diff options
| author | bors <bors@rust-lang.org> | 2022-06-24 07:39:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-24 07:39:28 +0000 |
| commit | d017d59ed013a4bc2431d023077eb7209fe9c60d (patch) | |
| tree | f9cc2f1615a02166ffec7da6ae4016b1789c8d84 /src | |
| parent | fc96600bf6a52f92aeeee60a92a161a82b61c0ef (diff) | |
| parent | e7ed8fe481fe103383f55a015a19f641450b76a3 (diff) | |
| download | rust-d017d59ed013a4bc2431d023077eb7209fe9c60d.tar.gz rust-d017d59ed013a4bc2431d023077eb7209fe9c60d.zip | |
Auto merge of #98109 - nikomatsakis:issue-98095, r=jackh726
fix universes in the NLL type tests In the NLL code, we were not accommodating universes in the `type_test` logic. Fixes #98095. r? `@compiler-errors` This breaks some tests, however, so the purpose of this branch is more explanatory and perhaps to do a crater run.
Diffstat (limited to 'src')
20 files changed, 280 insertions, 146 deletions
diff --git a/src/test/ui/borrowck/issue-71546.rs b/src/test/ui/borrowck/issue-71546.rs index b20c39193de..42100edeaa7 100644 --- a/src/test/ui/borrowck/issue-71546.rs +++ b/src/test/ui/borrowck/issue-71546.rs @@ -1,4 +1,8 @@ // Regression test for #71546. +// +// Made to pass as part of fixing #98095. +// +// check-pass pub fn serialize_as_csv<V>(value: &V) -> Result<String, &str> where @@ -6,15 +10,7 @@ where for<'a> &'a V: IntoIterator, for<'a> <&'a V as IntoIterator>::Item: ToString + 'static, { - let csv_str: String = value - //~^ ERROR higher-ranked lifetime error - //~| ERROR higher-ranked lifetime error - //~| ERROR higher-ranked lifetime error - .into_iter() - .map(|elem| elem.to_string()) - //~^ ERROR higher-ranked lifetime error - .collect::<String>(); - //~^ ERROR higher-ranked lifetime error + let csv_str: String = value.into_iter().map(|elem| elem.to_string()).collect::<String>(); Ok(csv_str) } diff --git a/src/test/ui/borrowck/issue-71546.stderr b/src/test/ui/borrowck/issue-71546.stderr deleted file mode 100644 index b8d79f0939b..00000000000 --- a/src/test/ui/borrowck/issue-71546.stderr +++ /dev/null @@ -1,59 +0,0 @@ -error: higher-ranked lifetime error - --> $DIR/issue-71546.rs:9:27 - | -LL | let csv_str: String = value - | ___________________________^ -LL | | -LL | | -LL | | -LL | | .into_iter() -LL | | .map(|elem| elem.to_string()) - | |_____________________________________^ - | - = note: could not prove for<'r> [closure@$DIR/issue-71546.rs:14:14: 14:37] well-formed - -error: higher-ranked lifetime error - --> $DIR/issue-71546.rs:9:27 - | -LL | let csv_str: String = value - | ___________________________^ -LL | | -LL | | -LL | | -LL | | .into_iter() -LL | | .map(|elem| elem.to_string()) - | |_____________________________________^ - | - = note: could not prove for<'r, 's> Map<<&'r V as IntoIterator>::IntoIter, [closure@$DIR/issue-71546.rs:14:14: 14:37]> well-formed - -error: higher-ranked lifetime error - --> $DIR/issue-71546.rs:9:27 - | -LL | let csv_str: String = value - | ___________________________^ -LL | | -LL | | -LL | | -... | -LL | | -LL | | .collect::<String>(); - | |____________________________^ - | - = note: could not prove for<'r, 's> Map<<&'r V as IntoIterator>::IntoIter, [closure@$DIR/issue-71546.rs:14:14: 14:37]> well-formed - -error: higher-ranked lifetime error - --> $DIR/issue-71546.rs:14:14 - | -LL | .map(|elem| elem.to_string()) - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: could not prove for<'a> <&'a V as IntoIterator>::Item: 'static - -error: higher-ranked lifetime error - --> $DIR/issue-71546.rs:16:10 - | -LL | .collect::<String>(); - | ^^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/src/test/ui/generic-associated-types/collectivity-regression.rs b/src/test/ui/generic-associated-types/collectivity-regression.rs new file mode 100644 index 00000000000..fb736843907 --- /dev/null +++ b/src/test/ui/generic-associated-types/collectivity-regression.rs @@ -0,0 +1,24 @@ +// Regression test from https://github.com/rust-lang/rust/pull/98109 + +#![feature(generic_associated_types)] + +pub trait Get { + type Value<'a> + where + Self: 'a; +} + +fn multiply_at<T>(x: T) +where + for<'a> T: Get<Value<'a> = ()>, +{ + || { + //~^ `T` does not live long enough + // + // FIXME(#98437). This regressed at some point and + // probably should work. + let _x = x; + }; +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/collectivity-regression.stderr b/src/test/ui/generic-associated-types/collectivity-regression.stderr new file mode 100644 index 00000000000..a858dd7fddc --- /dev/null +++ b/src/test/ui/generic-associated-types/collectivity-regression.stderr @@ -0,0 +1,14 @@ +error: `T` does not live long enough + --> $DIR/collectivity-regression.rs:15:5 + | +LL | / || { +LL | | +LL | | // +LL | | // FIXME(#98437). This regressed at some point and +LL | | // probably should work. +LL | | let _x = x; +LL | | }; + | |_____^ + +error: aborting due to previous error + diff --git a/src/test/ui/generic-associated-types/issue-86483.rs b/src/test/ui/generic-associated-types/issue-86483.rs index a8b54c354e3..07dd0bffd46 100644 --- a/src/test/ui/generic-associated-types/issue-86483.rs +++ b/src/test/ui/generic-associated-types/issue-86483.rs @@ -1,14 +1,16 @@ // Regression test of #86483. +// +// Made to pass as part of fixing #98095. +// +// check-pass #![feature(generic_associated_types)] -pub trait IceIce<T> //~ ERROR: the parameter type `T` may not live long enough +pub trait IceIce<T> where for<'a> T: 'a, { type Ice<'v>: IntoIterator<Item = &'v T>; - //~^ ERROR: the parameter type `T` may not live long enough - //~| ERROR: the parameter type `T` may not live long enough } fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-86483.stderr b/src/test/ui/generic-associated-types/issue-86483.stderr deleted file mode 100644 index a13dc043dc5..00000000000 --- a/src/test/ui/generic-associated-types/issue-86483.stderr +++ /dev/null @@ -1,50 +0,0 @@ -error[E0311]: the parameter type `T` may not live long enough - --> $DIR/issue-86483.rs:5:1 - | -LL | / pub trait IceIce<T> -LL | | where -LL | | for<'a> T: 'a, -LL | | { -... | -LL | | -LL | | } - | |_^ - | - = note: ...so that the type `T` will meet its required lifetime bounds... -note: ...that is required by this bound - --> $DIR/issue-86483.rs:7:16 - | -LL | for<'a> T: 'a, - | ^^ -help: consider adding an explicit lifetime bound... - | -LL | for<'a> T: 'a + 'a, - | ++++ - -error[E0311]: the parameter type `T` may not live long enough - --> $DIR/issue-86483.rs:9:5 - | -LL | type Ice<'v>: IntoIterator<Item = &'v T>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds... - | -note: ...that is required by this bound - --> $DIR/issue-86483.rs:7:16 - | -LL | for<'a> T: 'a, - | ^^ -help: consider adding an explicit lifetime bound... - | -LL | for<'a> T: 'a + 'a, - | ++++ - -error[E0309]: the parameter type `T` may not live long enough - --> $DIR/issue-86483.rs:9:32 - | -LL | type Ice<'v>: IntoIterator<Item = &'v T>; - | ^^^^^^^^^^^^ - help: consider adding a where clause: `where T: 'v` - | | - | ...so that the reference type `&'v T` does not outlive the data it points at - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0309`. diff --git a/src/test/ui/generic-associated-types/issue-91139.rs b/src/test/ui/generic-associated-types/issue-91139.rs index 03dc8ef93fe..092fa939c30 100644 --- a/src/test/ui/generic-associated-types/issue-91139.rs +++ b/src/test/ui/generic-associated-types/issue-91139.rs @@ -1,5 +1,3 @@ -//check-pass - #![feature(generic_associated_types)] trait Foo<T> { @@ -16,6 +14,22 @@ impl<T> Foo<T> for () { fn foo<T>() { let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + //~^ ERROR `T` does not live long enough + //~| ERROR `T` does not live long enough + //~| ERROR `T` does not live long enough + //~| ERROR `T` does not live long enough + //~| ERROR `T` does not live long enough + //~| ERROR `T` does not live long enough + //~| ERROR `T` does not live long enough + //~| ERROR `T` does not live long enough + // + // FIXME: This error is bogus, but it arises because we try to validate + // that `<() as Foo<T>>::Type<'a>` is valid, which requires proving + // that `T: 'a`. Since `'a` is higher-ranked, this becomes + // `for<'a> T: 'a`, which is not true. Of course, the error is bogus + // because there *ought* to be an implied bound stating that `'a` is + // not any lifetime but specifically + // "some `'a` such that `<() as Foo<T>>::Type<'a>" is valid". } pub fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-91139.stderr b/src/test/ui/generic-associated-types/issue-91139.stderr new file mode 100644 index 00000000000..6c5092978c8 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-91139.stderr @@ -0,0 +1,50 @@ +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:12 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:12 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:12 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:12 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:58 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^ + +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:58 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^ + +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:58 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^ + +error: `T` does not live long enough + --> $DIR/issue-91139.rs:16:58 + | +LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); + | ^^^^^^^^^ + +error: aborting due to 8 previous errors + diff --git a/src/test/ui/generic-associated-types/issue-92096.rs b/src/test/ui/generic-associated-types/issue-92096.rs index bfe0fc15fd3..377b8164ad5 100644 --- a/src/test/ui/generic-associated-types/issue-92096.rs +++ b/src/test/ui/generic-associated-types/issue-92096.rs @@ -1,5 +1,4 @@ // edition:2018 -// check-pass #![feature(generic_associated_types)] @@ -18,6 +17,14 @@ where C: Client + Send + Sync, { async move { c.connect().await } + //~^ ERROR `C` does not live long enough + // + // FIXME(#71723). This is because we infer at some point a value of + // + // impl Future<Output = <C as Client>::Connection<'_>> + // + // and then we somehow fail the WF check because `where C: 'a` is not known, + // but I'm not entirely sure how that comes about. } fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-92096.stderr b/src/test/ui/generic-associated-types/issue-92096.stderr new file mode 100644 index 00000000000..ca61a0f435e --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-92096.stderr @@ -0,0 +1,8 @@ +error: `C` does not live long enough + --> $DIR/issue-92096.rs:19:5 + | +LL | async move { c.connect().await } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/higher-rank-trait-bounds/issue-88586-hr-self-outlives-in-trait-def.rs b/src/test/ui/higher-rank-trait-bounds/issue-88586-hr-self-outlives-in-trait-def.rs index b50f56b03d9..92b7c5deb81 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-88586-hr-self-outlives-in-trait-def.rs +++ b/src/test/ui/higher-rank-trait-bounds/issue-88586-hr-self-outlives-in-trait-def.rs @@ -1,10 +1,12 @@ // Regression test for #88586: a higher-ranked outlives bound on Self in a trait // definition caused an ICE when debug_assertions were enabled. // -// FIXME: The error output in the absence of the ICE is unhelpful; this should be improved. +// Made to pass as part of fixing #98095. +// +// check-pass -trait A where for<'a> Self: 'a -//~^ ERROR the parameter type `Self` may not live long enough +trait A where + for<'a> Self: 'a, { } diff --git a/src/test/ui/higher-rank-trait-bounds/issue-88586-hr-self-outlives-in-trait-def.stderr b/src/test/ui/higher-rank-trait-bounds/issue-88586-hr-self-outlives-in-trait-def.stderr deleted file mode 100644 index 18618ffcc86..00000000000 --- a/src/test/ui/higher-rank-trait-bounds/issue-88586-hr-self-outlives-in-trait-def.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0311]: the parameter type `Self` may not live long enough - --> $DIR/issue-88586-hr-self-outlives-in-trait-def.rs:6:1 - | -LL | / trait A where for<'a> Self: 'a -LL | | -LL | | { -LL | | } - | |_^ - | - = help: consider adding an explicit lifetime bound `Self: 'a`... - = note: ...so that the type `Self` will meet its required lifetime bounds... -note: ...that is required by this bound - --> $DIR/issue-88586-hr-self-outlives-in-trait-def.rs:6:29 - | -LL | trait A where for<'a> Self: 'a - | ^^ - -error: aborting due to previous error - diff --git a/src/test/ui/nll/snocat-regression.rs b/src/test/ui/nll/snocat-regression.rs new file mode 100644 index 00000000000..b2e5995aa5b --- /dev/null +++ b/src/test/ui/nll/snocat-regression.rs @@ -0,0 +1,16 @@ +// Regression test from https://github.com/rust-lang/rust/pull/98109 + +pub fn negotiate<S>(link: S) +where + for<'a> &'a S: 'a, +{ + || { + //~^ ERROR `S` does not live long enough + // + // FIXME(#98437). This regressed at some point and + // probably should work. + let _x = link; + }; +} + +fn main() {} diff --git a/src/test/ui/nll/snocat-regression.stderr b/src/test/ui/nll/snocat-regression.stderr new file mode 100644 index 00000000000..0868984734d --- /dev/null +++ b/src/test/ui/nll/snocat-regression.stderr @@ -0,0 +1,14 @@ +error: `S` does not live long enough + --> $DIR/snocat-regression.rs:7:5 + | +LL | / || { +LL | | +LL | | // +LL | | // FIXME(#98437). This regressed at some point and +LL | | // probably should work. +LL | | let _x = link; +LL | | }; + | |_____^ + +error: aborting due to previous error + diff --git a/src/test/ui/nll/type-test-universe.rs b/src/test/ui/nll/type-test-universe.rs new file mode 100644 index 00000000000..f9801c07d7b --- /dev/null +++ b/src/test/ui/nll/type-test-universe.rs @@ -0,0 +1,21 @@ +// Regression test for #98095: make sure that +// we detect that S needs to outlive 'static. + +fn outlives_forall<T>() +where + for<'u> T: 'u, +{ +} + +fn test1<S>() { + outlives_forall::<S>(); + //~^ ERROR `S` does not live long enough +} + +struct Value<'a>(&'a ()); +fn test2<'a>() { + outlives_forall::<Value<'a>>(); + //~^ ERROR lifetime may not live long enough +} + +fn main() {} diff --git a/src/test/ui/nll/type-test-universe.stderr b/src/test/ui/nll/type-test-universe.stderr new file mode 100644 index 00000000000..242486c360a --- /dev/null +++ b/src/test/ui/nll/type-test-universe.stderr @@ -0,0 +1,16 @@ +error: `S` does not live long enough + --> $DIR/type-test-universe.rs:11:5 + | +LL | outlives_forall::<S>(); + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: lifetime may not live long enough + --> $DIR/type-test-universe.rs:17:5 + | +LL | fn test2<'a>() { + | -- lifetime `'a` defined here +LL | outlives_forall::<Value<'a>>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/nll/vimwiki-core-regression.rs b/src/test/ui/nll/vimwiki-core-regression.rs new file mode 100644 index 00000000000..0a4ed7e0a40 --- /dev/null +++ b/src/test/ui/nll/vimwiki-core-regression.rs @@ -0,0 +1,37 @@ +// check-pass +// +// Regression test from crater run for +// <https://github.com/rust-lang/rust/pull/98109>. + + +pub trait ElementLike {} + +pub struct Located<T> where T: ElementLike { + inner: T, +} + +pub struct BlockElement<'a>(&'a str); + +impl ElementLike for BlockElement<'_> {} + + +pub struct Page<'a> { + /// Comprised of the elements within a page + pub elements: Vec<Located<BlockElement<'a>>>, +} + +impl<'a, __IdxT> std::ops::Index<__IdxT> for Page<'a> where + Vec<Located<BlockElement<'a>>>: std::ops::Index<__IdxT> +{ + type Output = + <Vec<Located<BlockElement<'a>>> as + std::ops::Index<__IdxT>>::Output; + + #[inline] + fn index(&self, idx: __IdxT) -> &Self::Output { + <Vec<Located<BlockElement<'a>>> as + std::ops::Index<__IdxT>>::index(&self.elements, idx) + } +} + +fn main() {} diff --git a/src/test/ui/regions/forall-wf-ref-reflexive.rs b/src/test/ui/regions/forall-wf-ref-reflexive.rs new file mode 100644 index 00000000000..9c37d72d56b --- /dev/null +++ b/src/test/ui/regions/forall-wf-ref-reflexive.rs @@ -0,0 +1,18 @@ +// Test that we consider `for<'a> &'a T: 'a` to be sufficient to prove +// that `for<'a> &'a T: 'a`. +// +// FIXME. Except we don't! + +#![allow(warnings)] + +fn self_wf2<T>() +where + for<'a> &'a T: 'a, +{ + self_wf2::<T>(); + //~^ ERROR `T` does not live long enough + // + // FIXME. This ought to be accepted, presumably. +} + +fn main() {} diff --git a/src/test/ui/regions/forall-wf-ref-reflexive.stderr b/src/test/ui/regions/forall-wf-ref-reflexive.stderr new file mode 100644 index 00000000000..3d059ccec72 --- /dev/null +++ b/src/test/ui/regions/forall-wf-ref-reflexive.stderr @@ -0,0 +1,8 @@ +error: `T` does not live long enough + --> $DIR/forall-wf-ref-reflexive.rs:12:5 + | +LL | self_wf2::<T>(); + | ^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/regions/forall-wf-reflexive.rs b/src/test/ui/regions/forall-wf-reflexive.rs new file mode 100644 index 00000000000..8e6b8224b31 --- /dev/null +++ b/src/test/ui/regions/forall-wf-reflexive.rs @@ -0,0 +1,15 @@ +// Test that we consider `for<'a> T: 'a` to be sufficient to prove +// that `for<'a> T: 'a`. +// +// check-pass + +#![allow(warnings)] + +fn self_wf1<T>() +where + for<'a> T: 'a, +{ + self_wf1::<T>(); +} + +fn main() {} |
