Rollup merge of #103382 - compiler-errors:anon-apit-lt-region-ice, r=cjgillot
Don't ICE when reporting borrowck errors involving regions from `anonymous_lifetime_in_impl_trait`
The issue here is that when we have:
```
trait Trait<'a> { .. }
fn foo(arg: impl Trait) { .. }
```
The anonymous lifetime `'_` that we generate for `arg: impl Trait` doesn't end up in the argument type (which is a param) but in a where-clause of the function, in a predicate whose self type is that param ty.
Fixes #101660
r? ``@cjgillot``
This commit is contained in:
commit
6383540130
3 changed files with 120 additions and 8 deletions
12
src/test/ui/borrowck/anonymous-region-in-apit.rs
Normal file
12
src/test/ui/borrowck/anonymous-region-in-apit.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#![feature(anonymous_lifetime_in_impl_trait)]
|
||||
|
||||
trait Foo<T> {
|
||||
fn bar(self, baz: T);
|
||||
}
|
||||
|
||||
fn qux(foo: impl Foo<&str>) {
|
||||
|baz: &str| foo.bar(baz);
|
||||
//~^ ERROR borrowed data escapes outside of closure
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
16
src/test/ui/borrowck/anonymous-region-in-apit.stderr
Normal file
16
src/test/ui/borrowck/anonymous-region-in-apit.stderr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
error[E0521]: borrowed data escapes outside of closure
|
||||
--> $DIR/anonymous-region-in-apit.rs:8:17
|
||||
|
|
||||
LL | fn qux(foo: impl Foo<&str>) {
|
||||
| --- lifetime `'2` appears in the type of `foo`
|
||||
LL | |baz: &str| foo.bar(baz);
|
||||
| --- - ^^^^^^^^^^^^
|
||||
| | | |
|
||||
| | | `baz` escapes the closure body here
|
||||
| | | argument requires that `'1` must outlive `'2`
|
||||
| | let's call the lifetime of this reference `'1`
|
||||
| `baz` is a reference that is only valid in the closure body
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0521`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue