update tests
This commit is contained in:
parent
5f65331b3e
commit
ca9d72540b
4 changed files with 237 additions and 15 deletions
|
@ -72,14 +72,15 @@ LL | | }
|
||||||
error[E0597]: `a` does not live long enough
|
error[E0597]: `a` does not live long enough
|
||||||
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26
|
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26
|
||||||
|
|
|
|
||||||
LL | let cell = Cell::new(&a);
|
LL | let cell = Cell::new(&a);
|
||||||
| ----------^^-
|
| ^^ borrowed value does not live long enough
|
||||||
| | |
|
|
||||||
| | borrowed value does not live long enough
|
|
||||||
| argument requires that `a` is borrowed for `'static`
|
|
||||||
...
|
...
|
||||||
LL | }
|
LL | / foo(cell, |cell_a, cell_x| {
|
||||||
| - `a` dropped here while still borrowed
|
LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
|
||||||
|
LL | | })
|
||||||
|
| |______- argument requires that `a` is borrowed for `'static`
|
||||||
|
LL | }
|
||||||
|
| - `a` dropped here while still borrowed
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
116
src/test/ui/nll/impl-dyn-trait-static-bound.rs
Normal file
116
src/test/ui/nll/impl-dyn-trait-static-bound.rs
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
#![feature(nll)]
|
||||||
|
|
||||||
|
mod foo {
|
||||||
|
trait OtherTrait<'a> {}
|
||||||
|
impl<'a> OtherTrait<'a> for &'a () {}
|
||||||
|
|
||||||
|
trait ObjectTrait<T> {}
|
||||||
|
trait MyTrait<T> {
|
||||||
|
fn use_self<K>(&self) -> &();
|
||||||
|
}
|
||||||
|
trait Irrelevant {}
|
||||||
|
|
||||||
|
impl<T> MyTrait<T> for dyn ObjectTrait<T> {
|
||||||
|
fn use_self<K>(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
impl<T> Irrelevant for dyn ObjectTrait<T> {}
|
||||||
|
|
||||||
|
fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
|
||||||
|
val.use_self::<T>()
|
||||||
|
//~^ ERROR borrowed data escapes outside
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod bar {
|
||||||
|
trait ObjectTrait {}
|
||||||
|
trait MyTrait {
|
||||||
|
fn use_self(&self) -> &();
|
||||||
|
}
|
||||||
|
trait Irrelevant {}
|
||||||
|
|
||||||
|
impl MyTrait for dyn ObjectTrait {
|
||||||
|
fn use_self(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
impl Irrelevant for dyn ObjectTrait {}
|
||||||
|
|
||||||
|
fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
|
||||||
|
val.use_self()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod baz {
|
||||||
|
trait ObjectTrait {}
|
||||||
|
trait MyTrait {
|
||||||
|
fn use_self(&self) -> &();
|
||||||
|
}
|
||||||
|
trait Irrelevant {}
|
||||||
|
|
||||||
|
impl MyTrait for Box<dyn ObjectTrait> {
|
||||||
|
fn use_self(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
impl Irrelevant for Box<dyn ObjectTrait> {}
|
||||||
|
|
||||||
|
fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
|
||||||
|
val.use_self()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod bat {
|
||||||
|
trait OtherTrait<'a> {}
|
||||||
|
impl<'a> OtherTrait<'a> for &'a () {}
|
||||||
|
|
||||||
|
trait ObjectTrait {}
|
||||||
|
|
||||||
|
impl dyn ObjectTrait {
|
||||||
|
fn use_self(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||||
|
val.use_self()
|
||||||
|
//~^ ERROR borrowed data escapes outside
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod ban {
|
||||||
|
trait OtherTrait<'a> {}
|
||||||
|
impl<'a> OtherTrait<'a> for &'a () {}
|
||||||
|
|
||||||
|
trait ObjectTrait {}
|
||||||
|
trait MyTrait {
|
||||||
|
fn use_self(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
trait Irrelevant {
|
||||||
|
fn use_self(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MyTrait for dyn ObjectTrait {}
|
||||||
|
|
||||||
|
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
|
||||||
|
val.use_self()
|
||||||
|
//~^ ERROR borrowed data escapes outside
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod bal {
|
||||||
|
trait OtherTrait<'a> {}
|
||||||
|
impl<'a> OtherTrait<'a> for &'a () {}
|
||||||
|
|
||||||
|
trait ObjectTrait {}
|
||||||
|
trait MyTrait {
|
||||||
|
fn use_self(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
trait Irrelevant {
|
||||||
|
fn use_self(&self) -> &() { panic!() }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MyTrait for dyn ObjectTrait {}
|
||||||
|
impl Irrelevant for dyn ObjectTrait {}
|
||||||
|
|
||||||
|
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||||
|
MyTrait::use_self(val)
|
||||||
|
//~^ ERROR borrowed data escapes outside
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
105
src/test/ui/nll/impl-dyn-trait-static-bound.stderr
Normal file
105
src/test/ui/nll/impl-dyn-trait-static-bound.stderr
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
error[E0521]: borrowed data escapes outside of function
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:20:9
|
||||||
|
|
|
||||||
|
LL | fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
|
||||||
|
| -- --- `val` is a reference that is only valid in the function body
|
||||||
|
| |
|
||||||
|
| lifetime `'a` defined here
|
||||||
|
LL | val.use_self::<T>()
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| `val` escapes the function body here
|
||||||
|
| argument requires that `'a` must outlive `'static`
|
||||||
|
|
|
||||||
|
note: the used `impl` has a `'static` requirement
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:14:32
|
||||||
|
|
|
||||||
|
LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> {
|
||||||
|
| ^^^^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
|
||||||
|
LL | fn use_self<K>(&self) -> &() { panic!() }
|
||||||
|
| -------- calling this method introduces the `impl`'s 'static` requirement
|
||||||
|
help: consider relaxing the implicit `'static` requirement
|
||||||
|
|
|
||||||
|
LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> + '_ {
|
||||||
|
| ++++
|
||||||
|
|
||||||
|
error[E0521]: borrowed data escapes outside of function
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:70:9
|
||||||
|
|
|
||||||
|
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||||
|
| -- --- `val` is a reference that is only valid in the function body
|
||||||
|
| |
|
||||||
|
| lifetime `'a` defined here
|
||||||
|
LL | val.use_self()
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| `val` escapes the function body here
|
||||||
|
| argument requires that `'a` must outlive `'static`
|
||||||
|
|
|
||||||
|
note: the used `impl` has a `'static` requirement
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:65:14
|
||||||
|
|
|
||||||
|
LL | impl dyn ObjectTrait {
|
||||||
|
| ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
|
||||||
|
LL | fn use_self(&self) -> &() { panic!() }
|
||||||
|
| -------- calling this method introduces the `impl`'s 'static` requirement
|
||||||
|
help: consider relaxing the implicit `'static` requirement
|
||||||
|
|
|
||||||
|
LL | impl dyn ObjectTrait + '_ {
|
||||||
|
| ++++
|
||||||
|
|
||||||
|
error[E0521]: borrowed data escapes outside of function
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:90:9
|
||||||
|
|
|
||||||
|
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
|
||||||
|
| -- --- `val` is a reference that is only valid in the function body
|
||||||
|
| |
|
||||||
|
| lifetime `'a` defined here
|
||||||
|
LL | val.use_self()
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| `val` escapes the function body here
|
||||||
|
| argument requires that `'a` must outlive `'static`
|
||||||
|
|
|
||||||
|
note: the used `impl` has a `'static` requirement
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:87:26
|
||||||
|
|
|
||||||
|
LL | fn use_self(&self) -> &() { panic!() }
|
||||||
|
| -------- calling this method introduces the `impl`'s 'static` requirement
|
||||||
|
...
|
||||||
|
LL | impl MyTrait for dyn ObjectTrait {}
|
||||||
|
| ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
|
||||||
|
help: consider relaxing the implicit `'static` requirement
|
||||||
|
|
|
||||||
|
LL | impl MyTrait for dyn ObjectTrait + '_ {}
|
||||||
|
| ++++
|
||||||
|
|
||||||
|
error[E0521]: borrowed data escapes outside of function
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:111:9
|
||||||
|
|
|
||||||
|
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||||
|
| -- --- `val` is a reference that is only valid in the function body
|
||||||
|
| |
|
||||||
|
| lifetime `'a` defined here
|
||||||
|
LL | MyTrait::use_self(val)
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| `val` escapes the function body here
|
||||||
|
| argument requires that `'a` must outlive `'static`
|
||||||
|
|
|
||||||
|
note: the used `impl` has a `'static` requirement
|
||||||
|
--> $DIR/impl-dyn-trait-static-bound.rs:107:26
|
||||||
|
|
|
||||||
|
LL | fn use_self(&self) -> &() { panic!() }
|
||||||
|
| -------- calling this method introduces the `impl`'s 'static` requirement
|
||||||
|
...
|
||||||
|
LL | impl MyTrait for dyn ObjectTrait {}
|
||||||
|
| ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
|
||||||
|
help: consider relaxing the implicit `'static` requirement
|
||||||
|
|
|
||||||
|
LL | impl MyTrait for dyn ObjectTrait + '_ {}
|
||||||
|
| ++++
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0521`.
|
|
@ -1,14 +1,14 @@
|
||||||
error[E0597]: `c` does not live long enough
|
error[E0597]: `c` does not live long enough
|
||||||
--> $DIR/adt-nullary-enums.rs:33:41
|
--> $DIR/adt-nullary-enums.rs:33:41
|
||||||
|
|
|
|
||||||
LL | SomeEnum::SomeVariant(Cell::new(&c)),
|
LL | / combine(
|
||||||
| ----------^^-
|
LL | | SomeEnum::SomeVariant(Cell::new(&c)),
|
||||||
| | |
|
| | ^^ borrowed value does not live long enough
|
||||||
| | borrowed value does not live long enough
|
LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>,
|
||||||
| argument requires that `c` is borrowed for `'static`
|
LL | | );
|
||||||
...
|
| |_____- argument requires that `c` is borrowed for `'static`
|
||||||
LL | }
|
LL | }
|
||||||
| - `c` dropped here while still borrowed
|
| - `c` dropped here while still borrowed
|
||||||
|
|
||||||
error[E0597]: `c` does not live long enough
|
error[E0597]: `c` does not live long enough
|
||||||
--> $DIR/adt-nullary-enums.rs:41:41
|
--> $DIR/adt-nullary-enums.rs:41:41
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue