diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2022-10-25 08:01:28 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-25 08:01:28 +0900 |
| commit | 63835401304adc4bf3bb0d45fda0fe28bceddb4e (patch) | |
| tree | 8d3077f0ae9c7dd985e822a4c27ec126c1bc13df /src/test | |
| parent | e47d222a94d0d89128b16b09adbb96fccab2f7c8 (diff) | |
| parent | e025306fa050ac593bff366eb1c9bff7bfd00b1d (diff) | |
| download | rust-63835401304adc4bf3bb0d45fda0fe28bceddb4e.tar.gz rust-63835401304adc4bf3bb0d45fda0fe28bceddb4e.zip | |
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``
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/borrowck/anonymous-region-in-apit.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/borrowck/anonymous-region-in-apit.stderr | 16 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/anonymous-region-in-apit.rs b/src/test/ui/borrowck/anonymous-region-in-apit.rs new file mode 100644 index 00000000000..7799a7cb151 --- /dev/null +++ b/src/test/ui/borrowck/anonymous-region-in-apit.rs @@ -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() {} diff --git a/src/test/ui/borrowck/anonymous-region-in-apit.stderr b/src/test/ui/borrowck/anonymous-region-in-apit.stderr new file mode 100644 index 00000000000..9e100f8ac3c --- /dev/null +++ b/src/test/ui/borrowck/anonymous-region-in-apit.stderr @@ -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`. |
