]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Rollup merge of #67595 - ohadravid:impl-trait-does-not-live-long-enough, r=estebank
authorYuki Okushi <huyuumi.dev@gmail.com>
Fri, 3 Jan 2020 08:56:21 +0000 (17:56 +0900)
committerGitHub <noreply@github.com>
Fri, 3 Jan 2020 08:56:21 +0000 (17:56 +0900)
commit76c1454d27440dd6783bcc81b8558510a18130bf
tree7c7d8a2b52fed8b45e1d42200629a2f96ff141a9
parent7c404ce2332e72bc8e2bed8f14ab0e0e6002d2af
parent1a4f6b85a745e9855bbad4c5fdf0806200133f1d
Rollup merge of #67595 - ohadravid:impl-trait-does-not-live-long-enough, r=estebank

Suggest adding a lifetime constraint for opaque type

Fixes #67577, where code like this:

```
struct List {
  data: Vec<String>,
}
impl List {
  fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> {
    self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref())
  }
}
```

will show this error:
```
   Compiling playground v0.0.1 (/playground)
error[E0597]: `prefix` does not live long enough
 --> src/lib.rs:6:47
  |
5 |   fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> {
  |                   -- lifetime `'a` defined here     --------------------------- opaque type requires that `prefix` is borrowed for `'a`
...
```

but without suggesting the lovely `help: you can add a constraint..`.

r? @estebank
src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs
src/librustc_mir/borrow_check/diagnostics/region_errors.rs