diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-09-30 23:41:08 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-30 23:41:08 -0700 |
| commit | 8c5114b4e84a5a707c071982e3357fcbb3fb0a75 (patch) | |
| tree | 421b457d0454d60efb399ea5df29b6676a692bd4 /src | |
| parent | 27269554b85d9202f5cdbfa09c6350498adf9d31 (diff) | |
| parent | 87a4a79554b03e2002691b8734d23fb7a556fab1 (diff) | |
| download | rust-8c5114b4e84a5a707c071982e3357fcbb3fb0a75.tar.gz rust-8c5114b4e84a5a707c071982e3357fcbb3fb0a75.zip | |
Rollup merge of #89327 - oli-obk:nll_diag_infer_vars, r=wesleywiser
Pick one possible lifetime in case there are multiple choices
In case a lifetime variable is created, but doesn't have an obvious lifetime in the list of named lifetimes that it should be inferred to, just pick the first one for the diagnostic.
This happens e.g. in
```rust
fn foo<'a, 'b>(a: Struct<'a>, b: Struct<'b>) -> impl Trait<'a, 'b> {
if bar() { a } else { b }
}
```
where we get a lifetime variable that combines the lifetimes of `a` and `b` creating a lifetime that is the intersection of both. Right now the type system cannot express this and thus we get an error, but that error also can't express this.
I can also create an entirely new diagnostic that mentions all involved lifetimes, so it would actually mention `'a` and `'b` instead of just `'b`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr index 8cf89f164b1..0fe9b06355f 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr @@ -4,7 +4,11 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> | ^^^^^^^^^^^^^^^^^^ | - = note: hidden type `Ordinary<'_>` captures lifetime '_#9r +note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined on the function body at 16:21 + --> $DIR/ordinary-bounds-unrelated.rs:16:21 + | +LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + | ^^ error: aborting due to previous error diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr index 1bcb28120ed..6de77523db5 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr @@ -4,7 +4,11 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> | ^^^^^^^^^^^^^^^^^^ | - = note: hidden type `Ordinary<'_>` captures lifetime '_#6r +note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined on the function body at 18:21 + --> $DIR/ordinary-bounds-unsuited.rs:18:21 + | +LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + | ^^ error: aborting due to previous error |
