From: lcnr Date: Mon, 9 Jan 2023 16:13:14 +0000 (+0100) Subject: update test for inductive canonical cycles X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=31099ee3840f26c59b5f9057001fd656284deb81;p=rust.git update test for inductive canonical cycles --- diff --git a/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.rs b/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.rs index a3bb76d7e3b..5449f5f00d5 100644 --- a/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.rs +++ b/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.rs @@ -1,28 +1,69 @@ -// known-bug +// check-pass + +// This test checks that we're correctly dealing with inductive cycles +// with canonical inference variables. -// This should compile but fails with the current solver. -// -// This checks that the new solver uses `Ambiguous` when hitting the -// inductive cycle here when proving `exists<^0, ^1> (): Trait<^0, ^1>` -// which requires proving `Trait` but that has the same -// canonical representation. trait Trait {} -impl Trait for () +trait IsNotU32 {} +impl IsNotU32 for i32 {} +impl Trait for () // impl 1 where - (): Trait, - T: OtherTrait, + (): Trait {} -trait OtherTrait {} -impl OtherTrait for u32 {} +impl Trait for () {} // impl 2 + +// If we now check whether `(): Trait` holds this has to +// result in ambiguity as both `for (): Trait` and `(): Trait` +// applies. The remainder of this test asserts that. + +// If we were to error on inductive cycles with canonical inference variables +// this would be wrong: -fn require_trait() +// (): Trait +// - impl 1 +// - ?0: IsNotU32 // ambig +// - (): Trait // canonical cycle -> err +// - ERR +// - impl 2 +// - OK ?0 == u32 +// +// Result: OK ?0 == u32. + +// (): Trait +// - impl 1 +// - i32: IsNotU32 // ok +// - (): Trait +// - impl 1 +// - u32: IsNotU32 // err +// - ERR +// - impl 2 +// - OK +// - OK +// - impl 2 (trivial ERR) +// +// Result OK + +// This would mean that `(): Trait` is not complete, +// which is unsound if we're in coherence. + +fn implements_trait() -> (T, U) where - (): Trait -{} + (): Trait, +{ + todo!() +} + +// A hack to only constrain the infer vars after first checking +// the `(): Trait<_, _>`. +trait Constrain {} +impl Constrain for T {} +fn constrain, U>(_: U) {} fn main() { - require_trait::<_, _>(); - //~^ ERROR overflow evaluating + let (x, y) = implements_trait::<_, _>(); + + constrain::(x); + constrain::(y); } diff --git a/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.stderr b/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.stderr deleted file mode 100644 index e4b84e07822..00000000000 --- a/src/test/ui/traits/solver-cycles/inductive-canonical-cycle.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error[E0275]: overflow evaluating the requirement `_: Sized` - --> $DIR/inductive-canonical-cycle.rs:26:5 - | -LL | require_trait::<_, _>(); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`inductive_canonical_cycle`) -note: required for `()` to implement `Trait<_, _>` - --> $DIR/inductive-canonical-cycle.rs:11:12 - | -LL | impl Trait for () - | ^^^^^^^^^^^ ^^ - = note: 128 redundant requirements hidden - = note: required for `()` to implement `Trait<_, _>` -note: required by a bound in `require_trait` - --> $DIR/inductive-canonical-cycle.rs:22:9 - | -LL | fn require_trait() - | ------------- required by a bound in this -LL | where -LL | (): Trait - | ^^^^^^^^^^^ required by this bound in `require_trait` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0275`.