Skip to content

Commit ca9d725

Browse files
committed
update tests
1 parent 5f65331 commit ca9d725

File tree

4 files changed

+237
-15
lines changed

4 files changed

+237
-15
lines changed

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr

+8-7
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ LL | | }
7272
error[E0597]: `a` does not live long enough
7373
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26
7474
|
75-
LL | let cell = Cell::new(&a);
76-
| ----------^^-
77-
| | |
78-
| | borrowed value does not live long enough
79-
| argument requires that `a` is borrowed for `'static`
75+
LL | let cell = Cell::new(&a);
76+
| ^^ borrowed value does not live long enough
8077
...
81-
LL | }
82-
| - `a` dropped here while still borrowed
78+
LL | / foo(cell, |cell_a, cell_x| {
79+
LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
80+
LL | | })
81+
| |______- argument requires that `a` is borrowed for `'static`
82+
LL | }
83+
| - `a` dropped here while still borrowed
8384

8485
error: aborting due to 2 previous errors
8586

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#![allow(dead_code)]
2+
#![feature(nll)]
3+
4+
mod foo {
5+
trait OtherTrait<'a> {}
6+
impl<'a> OtherTrait<'a> for &'a () {}
7+
8+
trait ObjectTrait<T> {}
9+
trait MyTrait<T> {
10+
fn use_self<K>(&self) -> &();
11+
}
12+
trait Irrelevant {}
13+
14+
impl<T> MyTrait<T> for dyn ObjectTrait<T> {
15+
fn use_self<K>(&self) -> &() { panic!() }
16+
}
17+
impl<T> Irrelevant for dyn ObjectTrait<T> {}
18+
19+
fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
20+
val.use_self::<T>()
21+
//~^ ERROR borrowed data escapes outside
22+
}
23+
}
24+
25+
mod bar {
26+
trait ObjectTrait {}
27+
trait MyTrait {
28+
fn use_self(&self) -> &();
29+
}
30+
trait Irrelevant {}
31+
32+
impl MyTrait for dyn ObjectTrait {
33+
fn use_self(&self) -> &() { panic!() }
34+
}
35+
impl Irrelevant for dyn ObjectTrait {}
36+
37+
fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
38+
val.use_self()
39+
}
40+
}
41+
42+
mod baz {
43+
trait ObjectTrait {}
44+
trait MyTrait {
45+
fn use_self(&self) -> &();
46+
}
47+
trait Irrelevant {}
48+
49+
impl MyTrait for Box<dyn ObjectTrait> {
50+
fn use_self(&self) -> &() { panic!() }
51+
}
52+
impl Irrelevant for Box<dyn ObjectTrait> {}
53+
54+
fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
55+
val.use_self()
56+
}
57+
}
58+
59+
mod bat {
60+
trait OtherTrait<'a> {}
61+
impl<'a> OtherTrait<'a> for &'a () {}
62+
63+
trait ObjectTrait {}
64+
65+
impl dyn ObjectTrait {
66+
fn use_self(&self) -> &() { panic!() }
67+
}
68+
69+
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
70+
val.use_self()
71+
//~^ ERROR borrowed data escapes outside
72+
}
73+
}
74+
75+
mod ban {
76+
trait OtherTrait<'a> {}
77+
impl<'a> OtherTrait<'a> for &'a () {}
78+
79+
trait ObjectTrait {}
80+
trait MyTrait {
81+
fn use_self(&self) -> &() { panic!() }
82+
}
83+
trait Irrelevant {
84+
fn use_self(&self) -> &() { panic!() }
85+
}
86+
87+
impl MyTrait for dyn ObjectTrait {}
88+
89+
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
90+
val.use_self()
91+
//~^ ERROR borrowed data escapes outside
92+
}
93+
}
94+
95+
mod bal {
96+
trait OtherTrait<'a> {}
97+
impl<'a> OtherTrait<'a> for &'a () {}
98+
99+
trait ObjectTrait {}
100+
trait MyTrait {
101+
fn use_self(&self) -> &() { panic!() }
102+
}
103+
trait Irrelevant {
104+
fn use_self(&self) -> &() { panic!() }
105+
}
106+
107+
impl MyTrait for dyn ObjectTrait {}
108+
impl Irrelevant for dyn ObjectTrait {}
109+
110+
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
111+
MyTrait::use_self(val)
112+
//~^ ERROR borrowed data escapes outside
113+
}
114+
}
115+
116+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
error[E0521]: borrowed data escapes outside of function
2+
--> $DIR/impl-dyn-trait-static-bound.rs:20:9
3+
|
4+
LL | fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
5+
| -- --- `val` is a reference that is only valid in the function body
6+
| |
7+
| lifetime `'a` defined here
8+
LL | val.use_self::<T>()
9+
| ^^^^^^^^^^^^^^^^^^^
10+
| |
11+
| `val` escapes the function body here
12+
| argument requires that `'a` must outlive `'static`
13+
|
14+
note: the used `impl` has a `'static` requirement
15+
--> $DIR/impl-dyn-trait-static-bound.rs:14:32
16+
|
17+
LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> {
18+
| ^^^^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
19+
LL | fn use_self<K>(&self) -> &() { panic!() }
20+
| -------- calling this method introduces the `impl`'s 'static` requirement
21+
help: consider relaxing the implicit `'static` requirement
22+
|
23+
LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> + '_ {
24+
| ++++
25+
26+
error[E0521]: borrowed data escapes outside of function
27+
--> $DIR/impl-dyn-trait-static-bound.rs:70:9
28+
|
29+
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
30+
| -- --- `val` is a reference that is only valid in the function body
31+
| |
32+
| lifetime `'a` defined here
33+
LL | val.use_self()
34+
| ^^^^^^^^^^^^^^
35+
| |
36+
| `val` escapes the function body here
37+
| argument requires that `'a` must outlive `'static`
38+
|
39+
note: the used `impl` has a `'static` requirement
40+
--> $DIR/impl-dyn-trait-static-bound.rs:65:14
41+
|
42+
LL | impl dyn ObjectTrait {
43+
| ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
44+
LL | fn use_self(&self) -> &() { panic!() }
45+
| -------- calling this method introduces the `impl`'s 'static` requirement
46+
help: consider relaxing the implicit `'static` requirement
47+
|
48+
LL | impl dyn ObjectTrait + '_ {
49+
| ++++
50+
51+
error[E0521]: borrowed data escapes outside of function
52+
--> $DIR/impl-dyn-trait-static-bound.rs:90:9
53+
|
54+
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
55+
| -- --- `val` is a reference that is only valid in the function body
56+
| |
57+
| lifetime `'a` defined here
58+
LL | val.use_self()
59+
| ^^^^^^^^^^^^^^
60+
| |
61+
| `val` escapes the function body here
62+
| argument requires that `'a` must outlive `'static`
63+
|
64+
note: the used `impl` has a `'static` requirement
65+
--> $DIR/impl-dyn-trait-static-bound.rs:87:26
66+
|
67+
LL | fn use_self(&self) -> &() { panic!() }
68+
| -------- calling this method introduces the `impl`'s 'static` requirement
69+
...
70+
LL | impl MyTrait for dyn ObjectTrait {}
71+
| ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
72+
help: consider relaxing the implicit `'static` requirement
73+
|
74+
LL | impl MyTrait for dyn ObjectTrait + '_ {}
75+
| ++++
76+
77+
error[E0521]: borrowed data escapes outside of function
78+
--> $DIR/impl-dyn-trait-static-bound.rs:111:9
79+
|
80+
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
81+
| -- --- `val` is a reference that is only valid in the function body
82+
| |
83+
| lifetime `'a` defined here
84+
LL | MyTrait::use_self(val)
85+
| ^^^^^^^^^^^^^^^^^^^^^^
86+
| |
87+
| `val` escapes the function body here
88+
| argument requires that `'a` must outlive `'static`
89+
|
90+
note: the used `impl` has a `'static` requirement
91+
--> $DIR/impl-dyn-trait-static-bound.rs:107:26
92+
|
93+
LL | fn use_self(&self) -> &() { panic!() }
94+
| -------- calling this method introduces the `impl`'s 'static` requirement
95+
...
96+
LL | impl MyTrait for dyn ObjectTrait {}
97+
| ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
98+
help: consider relaxing the implicit `'static` requirement
99+
|
100+
LL | impl MyTrait for dyn ObjectTrait + '_ {}
101+
| ++++
102+
103+
error: aborting due to 4 previous errors
104+
105+
For more information about this error, try `rustc --explain E0521`.

src/test/ui/nll/user-annotations/adt-nullary-enums.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0597]: `c` does not live long enough
22
--> $DIR/adt-nullary-enums.rs:33:41
33
|
4-
LL | SomeEnum::SomeVariant(Cell::new(&c)),
5-
| ----------^^-
6-
| | |
7-
| | borrowed value does not live long enough
8-
| argument requires that `c` is borrowed for `'static`
9-
...
10-
LL | }
11-
| - `c` dropped here while still borrowed
4+
LL | / combine(
5+
LL | | SomeEnum::SomeVariant(Cell::new(&c)),
6+
| | ^^ borrowed value does not live long enough
7+
LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>,
8+
LL | | );
9+
| |_____- argument requires that `c` is borrowed for `'static`
10+
LL | }
11+
| - `c` dropped here while still borrowed
1212

1313
error[E0597]: `c` does not live long enough
1414
--> $DIR/adt-nullary-enums.rs:41:41

0 commit comments

Comments
 (0)