From 596d6c4b3b5e86e024cd02f7221749ee6958bec6 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Fri, 24 Jul 2020 21:59:43 +0100 Subject: Avoid cycle with projections from object types Normalizing ` as Iterator>::Item` no longer requires selecting `dyn Iterator: Iterator`. This was previously worked around by using a special type-folder to normalize things. --- src/test/ui/regions/regions-enum-not-wf.rs | 23 +++++++++++---------- src/test/ui/regions/regions-enum-not-wf.stderr | 24 ++++++---------------- .../regions-normalize-in-where-clause-list.rs | 17 ++++++++------- .../regions-normalize-in-where-clause-list.stderr | 24 +++++++++++----------- .../rfc-2093-infer-outlives/regions-enum-not-wf.rs | 23 +++++++++++---------- .../regions-enum-not-wf.stderr | 24 ++++++---------------- src/test/ui/traits/cycle-cache-err-60010.rs | 3 ++- src/test/ui/traits/cycle-cache-err-60010.stderr | 18 +++++++++++----- 8 files changed, 73 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/test/ui/regions/regions-enum-not-wf.rs b/src/test/ui/regions/regions-enum-not-wf.rs index 781cdb7286a..6de08f66d75 100644 --- a/src/test/ui/regions/regions-enum-not-wf.rs +++ b/src/test/ui/regions/regions-enum-not-wf.rs @@ -5,17 +5,18 @@ #![allow(dead_code)] trait Dummy<'a> { - type Out; + type Out; } impl<'a, T> Dummy<'a> for T -where T: 'a +where + T: 'a, { - type Out = (); + type Out = (); } type RequireOutlives<'a, T> = >::Out; enum Ref1<'a, T> { - Ref1Variant1(RequireOutlives<'a, T>) //~ ERROR the parameter type `T` may not live long enough + Ref1Variant1(RequireOutlives<'a, T>), //~ ERROR the parameter type `T` may not live long enough } enum Ref2<'a, T> { @@ -23,18 +24,18 @@ enum Ref2<'a, T> { Ref2Variant2(isize, RequireOutlives<'a, T>), //~ ERROR the parameter type `T` may not live long enough } -enum RefOk<'a, T:'a> { - RefOkVariant1(&'a T) +enum RefOk<'a, T: 'a> { + RefOkVariant1(&'a T), } // This is now well formed. RFC 2093 enum RefIndirect<'a, T> { - RefIndirectVariant1(isize, RefOk<'a,T>) + RefIndirectVariant1(isize, RefOk<'a, T>), } -enum RefDouble<'a, 'b, T> { //~ ERROR the parameter type `T` may not live long enough [E0309] - RefDoubleVariant1(&'a RequireOutlives<'b, T>) - //~^ the parameter type `T` may not live long enough [E0309] +enum RefDouble<'a, 'b, T> { + RefDoubleVariant1(&'a RequireOutlives<'b, T>), + //~^ the parameter type `T` may not live long enough [E0309] } -fn main() { } +fn main() {} diff --git a/src/test/ui/regions/regions-enum-not-wf.stderr b/src/test/ui/regions/regions-enum-not-wf.stderr index e32a36f72cd..36686eaf92f 100644 --- a/src/test/ui/regions/regions-enum-not-wf.stderr +++ b/src/test/ui/regions/regions-enum-not-wf.stderr @@ -1,13 +1,13 @@ error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:18:18 + --> $DIR/regions-enum-not-wf.rs:19:18 | LL | enum Ref1<'a, T> { | - help: consider adding an explicit lifetime bound...: `T: 'a` -LL | Ref1Variant1(RequireOutlives<'a, T>) +LL | Ref1Variant1(RequireOutlives<'a, T>), | ^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:23:25 + --> $DIR/regions-enum-not-wf.rs:24:25 | LL | enum Ref2<'a, T> { | - help: consider adding an explicit lifetime bound...: `T: 'a` @@ -16,25 +16,13 @@ LL | Ref2Variant2(isize, RequireOutlives<'a, T>), | ^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:35:1 - | -LL | enum RefDouble<'a, 'b, T> { - | ^ - help: consider adding an explicit lifetime bound...: `T: 'b` - | _| - | | -LL | | RefDoubleVariant1(&'a RequireOutlives<'b, T>) -LL | | -LL | | } - | |_^ ...so that the type `T` will meet its required lifetime bounds - -error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:36:23 + --> $DIR/regions-enum-not-wf.rs:37:23 | LL | enum RefDouble<'a, 'b, T> { | - help: consider adding an explicit lifetime bound...: `T: 'b` -LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>) +LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0309`. diff --git a/src/test/ui/regions/regions-normalize-in-where-clause-list.rs b/src/test/ui/regions/regions-normalize-in-where-clause-list.rs index e912805d855..9912e88c2ec 100644 --- a/src/test/ui/regions/regions-normalize-in-where-clause-list.rs +++ b/src/test/ui/regions/regions-normalize-in-where-clause-list.rs @@ -6,7 +6,8 @@ trait Project<'a, 'b> { } impl<'a, 'b> Project<'a, 'b> for () - where 'a: 'b +where + 'a: 'b, { type Item = (); } @@ -14,16 +15,18 @@ impl<'a, 'b> Project<'a, 'b> for () // No error here, we have 'a: 'b. We used to report an error here // though, see https://github.com/rust-lang/rust/issues/45937. fn foo<'a: 'b, 'b>() - where <() as Project<'a, 'b>>::Item : Eq +where + <() as Project<'a, 'b>>::Item: Eq, { } // Here we get an error: we need `'a: 'b`. -fn bar<'a, 'b>() //~ ERROR cannot infer - //~| ERROR cannot infer - //~| ERROR cannot infer - where <() as Project<'a, 'b>>::Item : Eq +fn bar<'a, 'b>() +//~^ ERROR cannot infer +//~| ERROR cannot infer +where + <() as Project<'a, 'b>>::Item: Eq, { } -fn main() { } +fn main() {} diff --git a/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr b/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr index 10ecb8d5262..24bf64261e9 100644 --- a/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr +++ b/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr @@ -1,5 +1,5 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - --> $DIR/regions-normalize-in-where-clause-list.rs:22:1 + --> $DIR/regions-normalize-in-where-clause-list.rs:24:1 | LL | / fn bar<'a, 'b>() LL | | @@ -7,18 +7,18 @@ LL | | LL | | where <() as Project<'a, 'b>>::Item : Eq | |____________________________________________^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 22:8... - --> $DIR/regions-normalize-in-where-clause-list.rs:22:8 +note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 24:8... + --> $DIR/regions-normalize-in-where-clause-list.rs:24:8 | LL | fn bar<'a, 'b>() | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the function body at 22:12... - --> $DIR/regions-normalize-in-where-clause-list.rs:22:12 +note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the function body at 24:12... + --> $DIR/regions-normalize-in-where-clause-list.rs:24:12 | LL | fn bar<'a, 'b>() | ^^ note: ...so that the types are compatible - --> $DIR/regions-normalize-in-where-clause-list.rs:22:1 + --> $DIR/regions-normalize-in-where-clause-list.rs:24:1 | LL | / fn bar<'a, 'b>() LL | | @@ -64,24 +64,24 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | fn bar<'a, 'b>() | ^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 22:8... - --> $DIR/regions-normalize-in-where-clause-list.rs:22:8 +note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 24:8... + --> $DIR/regions-normalize-in-where-clause-list.rs:24:8 | LL | fn bar<'a, 'b>() | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the function body at 22:12... - --> $DIR/regions-normalize-in-where-clause-list.rs:22:12 +note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the function body at 24:12... + --> $DIR/regions-normalize-in-where-clause-list.rs:24:12 | LL | fn bar<'a, 'b>() | ^^ note: ...so that the types are compatible - --> $DIR/regions-normalize-in-where-clause-list.rs:22:4 + --> $DIR/regions-normalize-in-where-clause-list.rs:24:4 | LL | fn bar<'a, 'b>() | ^^^ = note: expected `Project<'a, 'b>` found `Project<'_, '_>` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0495`. diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.rs b/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.rs index 781cdb7286a..6de08f66d75 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.rs +++ b/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.rs @@ -5,17 +5,18 @@ #![allow(dead_code)] trait Dummy<'a> { - type Out; + type Out; } impl<'a, T> Dummy<'a> for T -where T: 'a +where + T: 'a, { - type Out = (); + type Out = (); } type RequireOutlives<'a, T> = >::Out; enum Ref1<'a, T> { - Ref1Variant1(RequireOutlives<'a, T>) //~ ERROR the parameter type `T` may not live long enough + Ref1Variant1(RequireOutlives<'a, T>), //~ ERROR the parameter type `T` may not live long enough } enum Ref2<'a, T> { @@ -23,18 +24,18 @@ enum Ref2<'a, T> { Ref2Variant2(isize, RequireOutlives<'a, T>), //~ ERROR the parameter type `T` may not live long enough } -enum RefOk<'a, T:'a> { - RefOkVariant1(&'a T) +enum RefOk<'a, T: 'a> { + RefOkVariant1(&'a T), } // This is now well formed. RFC 2093 enum RefIndirect<'a, T> { - RefIndirectVariant1(isize, RefOk<'a,T>) + RefIndirectVariant1(isize, RefOk<'a, T>), } -enum RefDouble<'a, 'b, T> { //~ ERROR the parameter type `T` may not live long enough [E0309] - RefDoubleVariant1(&'a RequireOutlives<'b, T>) - //~^ the parameter type `T` may not live long enough [E0309] +enum RefDouble<'a, 'b, T> { + RefDoubleVariant1(&'a RequireOutlives<'b, T>), + //~^ the parameter type `T` may not live long enough [E0309] } -fn main() { } +fn main() {} diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr index e32a36f72cd..36686eaf92f 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr @@ -1,13 +1,13 @@ error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:18:18 + --> $DIR/regions-enum-not-wf.rs:19:18 | LL | enum Ref1<'a, T> { | - help: consider adding an explicit lifetime bound...: `T: 'a` -LL | Ref1Variant1(RequireOutlives<'a, T>) +LL | Ref1Variant1(RequireOutlives<'a, T>), | ^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:23:25 + --> $DIR/regions-enum-not-wf.rs:24:25 | LL | enum Ref2<'a, T> { | - help: consider adding an explicit lifetime bound...: `T: 'a` @@ -16,25 +16,13 @@ LL | Ref2Variant2(isize, RequireOutlives<'a, T>), | ^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:35:1 - | -LL | enum RefDouble<'a, 'b, T> { - | ^ - help: consider adding an explicit lifetime bound...: `T: 'b` - | _| - | | -LL | | RefDoubleVariant1(&'a RequireOutlives<'b, T>) -LL | | -LL | | } - | |_^ ...so that the type `T` will meet its required lifetime bounds - -error[E0309]: the parameter type `T` may not live long enough - --> $DIR/regions-enum-not-wf.rs:36:23 + --> $DIR/regions-enum-not-wf.rs:37:23 | LL | enum RefDouble<'a, 'b, T> { | - help: consider adding an explicit lifetime bound...: `T: 'b` -LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>) +LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0309`. diff --git a/src/test/ui/traits/cycle-cache-err-60010.rs b/src/test/ui/traits/cycle-cache-err-60010.rs index 62d558fde88..98bfcb8d67b 100644 --- a/src/test/ui/traits/cycle-cache-err-60010.rs +++ b/src/test/ui/traits/cycle-cache-err-60010.rs @@ -24,7 +24,7 @@ struct Runtime { _storage: Box, } struct SalsaStorage { - _parse: >::Data, //~ ERROR overflow + _parse: >::Data, } impl Database for RootDatabase { @@ -67,6 +67,7 @@ pub(crate) fn goto_implementation(db: &RootDatabase) -> u32 { // we used to fail to report an error here because we got the // caching wrong. SourceDatabase::parse(db); + //~^ ERROR overflow 22 } diff --git a/src/test/ui/traits/cycle-cache-err-60010.stderr b/src/test/ui/traits/cycle-cache-err-60010.stderr index 25b1f427f3a..738b052a11e 100644 --- a/src/test/ui/traits/cycle-cache-err-60010.stderr +++ b/src/test/ui/traits/cycle-cache-err-60010.stderr @@ -1,10 +1,18 @@ -error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase` - --> $DIR/cycle-cache-err-60010.rs:27:13 +error[E0275]: overflow evaluating the requirement `SalsaStorage: std::panic::RefUnwindSafe` + --> $DIR/cycle-cache-err-60010.rs:69:5 | -LL | _parse: >::Data, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn parse(&self) { + | --------------- required by `SourceDatabase::parse` +... +LL | SourceDatabase::parse(db); + | ^^^^^^^^^^^^^^^^^^^^^ | - = note: required because of the requirements on the impl of `Query` for `ParseQuery` + = note: required because it appears within the type `*const SalsaStorage` + = note: required because it appears within the type `std::ptr::Unique` + = note: required because it appears within the type `std::boxed::Box` + = note: required because it appears within the type `Runtime` + = note: required because it appears within the type `RootDatabase` + = note: required because of the requirements on the impl of `SourceDatabase` for `RootDatabase` error[E0275]: overflow evaluating the requirement `Runtime: RefUnwindSafe` --> $DIR/cycle-cache-err-60010.rs:31:20 -- cgit 1.4.1-3-g733a5