diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-08-07 15:59:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-07 15:59:38 +0200 |
| commit | 888d157417c8defa25b321faca64460231d7cd62 (patch) | |
| tree | 2e81374a422d04079cb3e2368adadc122bf05cdc /tests/ui | |
| parent | f739c00f4a9924dafa8fd9805766266394da04fd (diff) | |
| parent | c656ce7aebe23b8d895f485b131da5d296a78c8c (diff) | |
| download | rust-888d157417c8defa25b321faca64460231d7cd62.tar.gz rust-888d157417c8defa25b321faca64460231d7cd62.zip | |
Rollup merge of #128753 - compiler-errors:arbitrary-upper, r=spastorino
Don't arbitrarily choose one upper bound for hidden captured region error message You could argue that the error message is objectively worse, even though it's more accurate. I guess we could also add a note explaining like "cannot capture the intersection of two regions" or something, though I'm not sure if that is confusing due to being totally technical jargon. This addresses the fact that #128752 says "add `+ 'b`" even though it does nothing to fix the issue. It doesn't fix the issue's root cause, though. r? `@spastorino`
Diffstat (limited to 'tests/ui')
5 files changed, 48 insertions, 21 deletions
diff --git a/tests/ui/impl-trait/in-trait/cannot-capture-intersection.rs b/tests/ui/impl-trait/in-trait/cannot-capture-intersection.rs new file mode 100644 index 00000000000..d7b62436d2d --- /dev/null +++ b/tests/ui/impl-trait/in-trait/cannot-capture-intersection.rs @@ -0,0 +1,29 @@ +#![feature(precise_capturing)] + +use std::future::Future; +use std::pin::Pin; + +trait MyTrait { + fn foo<'a, 'b>(&'a self, x: &'b i32) -> impl Future<Output = i32>; +} + +trait ErasedMyTrait { + fn foo<'life0, 'life1, 'dynosaur>(&'life0 self, x: &'life1 i32) + -> Pin<Box<dyn Future<Output = i32> + 'dynosaur>> + where + 'life0: 'dynosaur, + 'life1: 'dynosaur; +} + +struct DynMyTrait<T: ErasedMyTrait> { + ptr: T, +} + +impl<T: ErasedMyTrait> MyTrait for DynMyTrait<T> { + fn foo<'a, 'b>(&'a self, x: &'b i32) -> impl Future<Output = i32> { + self.ptr.foo(x) + //~^ ERROR hidden type for `impl Future<Output = i32>` captures lifetime that does not appear in bounds + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/cannot-capture-intersection.stderr b/tests/ui/impl-trait/in-trait/cannot-capture-intersection.stderr new file mode 100644 index 00000000000..92ef66c5504 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/cannot-capture-intersection.stderr @@ -0,0 +1,13 @@ +error[E0700]: hidden type for `impl Future<Output = i32>` captures lifetime that does not appear in bounds + --> $DIR/cannot-capture-intersection.rs:24:9 + | +LL | fn foo<'a, 'b>(&'a self, x: &'b i32) -> impl Future<Output = i32> { + | ------------------------- opaque type defined here +LL | self.ptr.foo(x) + | ^^^^^^^^^^^^^^^ + | + = note: hidden type `Pin<Box<dyn Future<Output = i32>>>` captures lifetime `'_` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0700`. diff --git a/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr b/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr index 4d4ba58c974..b7cee7d0b1f 100644 --- a/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr +++ b/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr @@ -2,17 +2,12 @@ error[E0700]: hidden type for `impl Trait<'d, 'e>` captures lifetime that does n --> $DIR/ordinary-bounds-unrelated.rs:28:33 | LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> - | -- ------------------ opaque type defined here - | | - | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here + | ------------------ opaque type defined here ... LL | if condition() { a } else { b } | ^ | -help: to declare that `impl Trait<'d, 'e>` captures `'b`, you can add an explicit `'b` lifetime bound - | -LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b - | ++++ + = note: hidden type `Ordinary<'_>` captures lifetime `'_` error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr b/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr index 060eaa7e64a..d1190da6c9f 100644 --- a/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr +++ b/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr @@ -2,17 +2,12 @@ error[E0700]: hidden type for `impl Trait<'a, 'b>` captures lifetime that does n --> $DIR/ordinary-bounds-unsuited.rs:31:33 | LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> - | -- ------------------ opaque type defined here - | | - | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here + | ------------------ opaque type defined here ... LL | if condition() { a } else { b } | ^ | -help: to declare that `impl Trait<'a, 'b>` captures `'b`, you can add an explicit `'b` lifetime bound - | -LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b - | ++++ + = note: hidden type `Ordinary<'_>` captures lifetime `'_` error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr index aeeec3aca34..3a1f685f16b 100644 --- a/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr +++ b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr @@ -2,18 +2,13 @@ error[E0700]: hidden type for `impl Iterator<Item = i32>` captures lifetime that --> $DIR/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs:7:5 | LL | fn bar(src: &crate::Foo) -> impl Iterator<Item = i32> { - | ---------- ------------------------- opaque type defined here - | | - | hidden type `FilterMap<std::slice::Iter<'static, i32>, {closure@$DIR/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs:9:21: 9:24}>` captures the anonymous lifetime defined here + | ------------------------- opaque type defined here LL | / [0].into_iter() LL | | LL | | .filter_map(|_| foo(src)) | |_________________________________^ | -help: to declare that `impl Iterator<Item = i32>` captures `'_`, you can introduce a named lifetime parameter `'a` - | -LL | fn bar<'a>(src: &'a crate::Foo<'a>) -> impl Iterator<Item = i32> + 'a { - | ++++ ++ ++++ ++++ + = note: hidden type `FilterMap<std::slice::Iter<'static, i32>, {closure@$DIR/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs:9:21: 9:24}>` captures lifetime `'_` error: aborting due to 1 previous error |
