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.
This commit is contained in:
bors 2017-09-27 22:00:11 +00:00
commit 44d5090a6d
8 changed files with 102 additions and 20 deletions

View file

@ -0,0 +1,31 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait ListItem<'a> {
fn list_name() -> &'a str;
}
trait Collection { fn len(&self) -> usize; }
struct List<'a, T: ListItem<'a>> {
slice: &'a [T]
}
impl<'a, T: ListItem<'a>> Collection for List<'a, T> {
fn len(&self) -> usize {
0
}
}
struct Foo<T> {
foo: &'static T
}
fn main() {}

View file

@ -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