Skip to content

Commit ba76f10

Browse files
committed
add test
1 parent 795401e commit ba76f10

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Foo<Vec<X>> shouldn't imply X: 'static.
2+
// We don't use region constraints from trait impls in implied bounds.
3+
4+
trait Trait {
5+
type Assoc;
6+
}
7+
8+
impl<X: 'static> Trait for Vec<X> {
9+
type Assoc = ();
10+
}
11+
12+
struct Foo<T: Trait>(T)
13+
where
14+
T::Assoc: 'static, // any predicate naming T::Assoc
15+
;
16+
17+
fn foo<X>(_: Foo<Vec<X>>) {}
18+
//~^ ERROR `X` may not live long enough
19+
//~| ERROR `X` may not live long enough
20+
21+
fn main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0310]: the parameter type `X` may not live long enough
2+
--> $DIR/from-trait-impl.rs:17:1
3+
|
4+
LL | fn foo<X>(_: Foo<Vec<X>>) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `X` will meet its required lifetime bounds
6+
|
7+
help: consider adding an explicit lifetime bound...
8+
|
9+
LL | fn foo<X: 'static>(_: Foo<Vec<X>>) {}
10+
| +++++++++
11+
12+
error[E0310]: the parameter type `X` may not live long enough
13+
--> $DIR/from-trait-impl.rs:17:14
14+
|
15+
LL | fn foo<X>(_: Foo<Vec<X>>) {}
16+
| ^^^^^^^^^^^ ...so that the type `X` will meet its required lifetime bounds
17+
|
18+
help: consider adding an explicit lifetime bound...
19+
|
20+
LL | fn foo<X: 'static>(_: Foo<Vec<X>>) {}
21+
| +++++++++
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)