diff options
| author | bors <bors@rust-lang.org> | 2017-09-27 22:00:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-09-27 22:00:11 +0000 |
| commit | 44d5090a6dbfbcd698ec53ef38981d9747112e0a (patch) | |
| tree | 98ed0601b49109869a317e515d42629d3c5d1c9c /src/test | |
| parent | 0e6f4cf51cd3b799fb057956f8e733d16605d09b (diff) | |
| parent | ddee9fbc998e345e9a36f2066d51d389aa31a632 (diff) | |
| download | rust-44d5090a6dbfbcd698ec53ef38981d9747112e0a.tar.gz rust-44d5090a6dbfbcd698ec53ef38981d9747112e0a.zip | |
Auto merge of #44782 - estebank:issue-36700, r=GuillaumeGomez
Point at parameter type on E0301
On "the parameter type `T` may not live long enough" error, point to the
parameter type suggesting lifetime bindings:
```
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/lifetime-doesnt-live-long-enough.rs:28:5
|
27 | struct Foo<T> {
| - help: consider adding an explicit lifetime bound `T: 'static`...
28 | foo: &'static T
| ^^^^^^^^^^^^^^^
|
note: ...so that the reference type `&'static T` does not outlive the data it points at
--> $DIR/lifetime-doesnt-live-long-enough.rs:28:5
|
28 | foo: &'static T
| ^^^^^^^^^^^^^^^
```
Fix #36700.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.rs (renamed from src/test/compile-fail/issue-16747.rs) | 8 | ||||
| -rw-r--r-- | src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr | 30 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/test/compile-fail/issue-16747.rs b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.rs index dd7e8a869ec..465b4271035 100644 --- a/src/test/compile-fail/issue-16747.rs +++ b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.rs @@ -16,14 +16,16 @@ trait Collection { fn len(&self) -> usize; } struct List<'a, T: ListItem<'a>> { slice: &'a [T] -//~^ ERROR the parameter type `T` may not live long enough -//~| HELP consider adding an explicit lifetime bound -//~| NOTE ...so that the reference type `&'a [T]` does not outlive the data it points at } + impl<'a, T: ListItem<'a>> Collection for List<'a, T> { fn len(&self) -> usize { 0 } } +struct Foo<T> { + foo: &'static T +} + fn main() {} diff --git a/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr new file mode 100644 index 00000000000..e17a660c591 --- /dev/null +++ b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr @@ -0,0 +1,30 @@ +error[E0309]: the parameter type `T` may not live long enough + --> $DIR/lifetime-doesnt-live-long-enough.rs:18:5 + | +17 | struct List<'a, T: ListItem<'a>> { + | -- help: consider adding an explicit lifetime bound `T: 'a`... +18 | slice: &'a [T] + | ^^^^^^^^^^^^^^ + | +note: ...so that the reference type `&'a [T]` does not outlive the data it points at + --> $DIR/lifetime-doesnt-live-long-enough.rs:18:5 + | +18 | slice: &'a [T] + | ^^^^^^^^^^^^^^ + +error[E0310]: the parameter type `T` may not live long enough + --> $DIR/lifetime-doesnt-live-long-enough.rs:28:5 + | +27 | struct Foo<T> { + | - help: consider adding an explicit lifetime bound `T: 'static`... +28 | foo: &'static T + | ^^^^^^^^^^^^^^^ + | +note: ...so that the reference type `&'static T` does not outlive the data it points at + --> $DIR/lifetime-doesnt-live-long-enough.rs:28:5 + | +28 | foo: &'static T + | ^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + |
