From f918b89f61d9aac3df4e57b05892f4614ddfc678 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 28 Apr 2025 16:36:25 +0000 Subject: [PATCH 1/2] Wf is not coinductive --- .../src/traits/select/mod.rs | 5 ++++- tests/ui/associated-types/issue-64855.stderr | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index df02a67c2c9b5..de310f9d37162 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1242,7 +1242,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => { self.infcx.tcx.trait_is_coinductive(data.def_id()) } - ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => true, + ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => { + // TODO: GCE is going away + self.infcx.tcx.features().generic_const_exprs() + } _ => false, }) } diff --git a/tests/ui/associated-types/issue-64855.stderr b/tests/ui/associated-types/issue-64855.stderr index 7c09abdb3b6f3..1562a10b4534c 100644 --- a/tests/ui/associated-types/issue-64855.stderr +++ b/tests/ui/associated-types/issue-64855.stderr @@ -10,6 +10,19 @@ help: this trait has no implementations, consider adding one LL | pub trait Foo { | ^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error[E0275]: overflow evaluating the requirement `Bar well-formed` + --> $DIR/issue-64855.rs:5:46 + | +LL | pub struct Bar(::Type) where Self: ; + | ^^^^ + | +note: required by a bound in `Bar` + --> $DIR/issue-64855.rs:5:46 + | +LL | pub struct Bar(::Type) where Self: ; + | ^^^^ required by this bound in `Bar` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0275, E0277. +For more information about an error, try `rustc --explain E0275`. From 38c05a68ee94a01ac9ef91ab0b7d0d3fc6a33bda Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 29 Apr 2025 03:05:26 +0000 Subject: [PATCH 2/2] Adjust tests --- .../src/traits/select/mod.rs | 4 +++- tests/crashes/123456.rs | 16 ---------------- tests/ui/associated-types/issue-64855-2.rs | 5 ++++- tests/ui/associated-types/issue-64855-2.stderr | 15 +++++++++++++++ tests/ui/associated-types/issue-64855.rs | 5 +++++ tests/ui/associated-types/issue-64855.stderr | 8 ++++---- .../higher-ranked/trait-bounds/issue-95230.rs | 9 ++++----- .../trait-bounds/issue-95230.stderr | 18 ++++++++++++++++++ 8 files changed, 53 insertions(+), 27 deletions(-) delete mode 100644 tests/crashes/123456.rs create mode 100644 tests/ui/associated-types/issue-64855-2.stderr create mode 100644 tests/ui/higher-ranked/trait-bounds/issue-95230.stderr diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index de310f9d37162..1a5a1c214bd3e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1243,7 +1243,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.infcx.tcx.trait_is_coinductive(data.def_id()) } ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => { - // TODO: GCE is going away + // FIXME(generic_const_exprs): GCE needs well-formedness predicates to be + // coinductive, but GCE is on the way out anyways, so this should eventually + // be replaced with `false`. self.infcx.tcx.features().generic_const_exprs() } _ => false, diff --git a/tests/crashes/123456.rs b/tests/crashes/123456.rs deleted file mode 100644 index ed7cbada3f85c..0000000000000 --- a/tests/crashes/123456.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ known-bug: #123456 - -trait Project { - const SELF: Self; -} - -fn take1( - _: Project< - SELF = { - j2.join().unwrap(); - }, - >, -) { -} - -pub fn main() {} diff --git a/tests/ui/associated-types/issue-64855-2.rs b/tests/ui/associated-types/issue-64855-2.rs index 30cb37b5198e2..20b8ff17e9e5d 100644 --- a/tests/ui/associated-types/issue-64855-2.rs +++ b/tests/ui/associated-types/issue-64855-2.rs @@ -1,5 +1,8 @@ -//@ check-pass +// This was originally a test for a `ReEmpty` ICE, but became an unintentional test of +// the coinductiveness of WF predicates. That behavior was removed, and thus this is +// also inadvertently a test for the (non-)co-inductiveness of WF predicates. pub struct Bar<'a>(&'a Self) where Self: ; +//~^ ERROR overflow evaluating the requirement `Bar<'a> well-formed` fn main() {} diff --git a/tests/ui/associated-types/issue-64855-2.stderr b/tests/ui/associated-types/issue-64855-2.stderr new file mode 100644 index 0000000000000..22292a8721a16 --- /dev/null +++ b/tests/ui/associated-types/issue-64855-2.stderr @@ -0,0 +1,15 @@ +error[E0275]: overflow evaluating the requirement `Bar<'a> well-formed` + --> $DIR/issue-64855-2.rs:5:36 + | +LL | pub struct Bar<'a>(&'a Self) where Self: ; + | ^^^^ + | +note: required by a bound in `Bar` + --> $DIR/issue-64855-2.rs:5:36 + | +LL | pub struct Bar<'a>(&'a Self) where Self: ; + | ^^^^ required by this bound in `Bar` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/associated-types/issue-64855.rs b/tests/ui/associated-types/issue-64855.rs index 81cf3ae6e83b6..5d325b981a2c6 100644 --- a/tests/ui/associated-types/issue-64855.rs +++ b/tests/ui/associated-types/issue-64855.rs @@ -1,8 +1,13 @@ +// This was originally a test for a `ReEmpty` ICE, but became an unintentional test of +// the coinductiveness of WF predicates. That behavior was removed, and thus this is +// also inadvertently a test for the (non-)co-inductiveness of WF predicates. + pub trait Foo { type Type; } pub struct Bar(::Type) where Self: ; //~^ ERROR the trait bound `Bar: Foo` is not satisfied +//~| ERROR overflow evaluating the requirement `Bar well-formed` fn main() {} diff --git a/tests/ui/associated-types/issue-64855.stderr b/tests/ui/associated-types/issue-64855.stderr index 1562a10b4534c..d8ba1a9d07ee9 100644 --- a/tests/ui/associated-types/issue-64855.stderr +++ b/tests/ui/associated-types/issue-64855.stderr @@ -1,23 +1,23 @@ error[E0277]: the trait bound `Bar: Foo` is not satisfied - --> $DIR/issue-64855.rs:5:19 + --> $DIR/issue-64855.rs:9:19 | LL | pub struct Bar(::Type) where Self: ; | ^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar` | help: this trait has no implementations, consider adding one - --> $DIR/issue-64855.rs:1:1 + --> $DIR/issue-64855.rs:5:1 | LL | pub trait Foo { | ^^^^^^^^^^^^^ error[E0275]: overflow evaluating the requirement `Bar well-formed` - --> $DIR/issue-64855.rs:5:46 + --> $DIR/issue-64855.rs:9:46 | LL | pub struct Bar(::Type) where Self: ; | ^^^^ | note: required by a bound in `Bar` - --> $DIR/issue-64855.rs:5:46 + --> $DIR/issue-64855.rs:9:46 | LL | pub struct Bar(::Type) where Self: ; | ^^^^ required by this bound in `Bar` diff --git a/tests/ui/higher-ranked/trait-bounds/issue-95230.rs b/tests/ui/higher-ranked/trait-bounds/issue-95230.rs index d1ca6834551e1..821a04ff0655e 100644 --- a/tests/ui/higher-ranked/trait-bounds/issue-95230.rs +++ b/tests/ui/higher-ranked/trait-bounds/issue-95230.rs @@ -1,11 +1,10 @@ -//@ revisions: old next -//@[next] compile-flags: -Znext-solver -//@[old] check-pass -//@[next] known-bug: #109764 - +// This used to be a test for overflow handling + higher-ranked outlives +// in the new solver, but this test isn't expected to pass since WF preds +// are not coinductive anymore. pub struct Bar where for<'a> &'a mut Self:; +//~^ ERROR overflow evaluating the requirement `for<'a> &'a mut Bar well-formed` fn main() {} diff --git a/tests/ui/higher-ranked/trait-bounds/issue-95230.stderr b/tests/ui/higher-ranked/trait-bounds/issue-95230.stderr new file mode 100644 index 0000000000000..7070af75d290c --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/issue-95230.stderr @@ -0,0 +1,18 @@ +error[E0275]: overflow evaluating the requirement `for<'a> &'a mut Bar well-formed` + --> $DIR/issue-95230.rs:7:13 + | +LL | for<'a> &'a mut Self:; + | ^^^^^^^^^^^^ + | +note: required by a bound in `Bar` + --> $DIR/issue-95230.rs:7:13 + | +LL | pub struct Bar + | --- required by a bound in this struct +LL | where +LL | for<'a> &'a mut Self:; + | ^^^^^^^^^^^^ required by this bound in `Bar` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`.