Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest adding a lifetime constraint for opaque type #67595

Merged

Conversation

ohadravid
Copy link
Contributor

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2019
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after dealing with the nitpicks

@ohadravid ohadravid force-pushed the impl-trait-does-not-live-long-enough branch from ce292d3 to 3f53c1a Compare December 24, 2019 21:53
@ohadravid ohadravid force-pushed the impl-trait-does-not-live-long-enough branch from 3f53c1a to 94089ad Compare December 25, 2019 07:54
@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 25, 2019

📌 Commit 3e9d1cc has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 25, 2019
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Dec 26, 2019
…long-enough, r=estebank

Suggest adding a lifetime constraint for opaque type

Fixes rust-lang#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
@Mark-Simulacrum
Copy link
Member

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 26, 2019
@ohadravid ohadravid force-pushed the impl-trait-does-not-live-long-enough branch from 3e9d1cc to e9a9e07 Compare December 27, 2019 12:18
region_name,
),
format!("{} + {}", snippet, suggestable_name),
Applicability::Unspecified,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this fix can be applied automatically, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same Applicability as the other suggestions for impl Trait lifetimes.
I don't think we can be sure this snippet will work (@estebank just fixed an issue with ; for example)

@ohadravid ohadravid force-pushed the impl-trait-does-not-live-long-enough branch from e9a9e07 to cd73034 Compare December 30, 2019 18:23
@ohadravid
Copy link
Contributor Author

@Mark-Simulacrum rebased and the CI is green 😄

@Mark-Simulacrum
Copy link
Member

@bors r=estebank

Thanks!

@bors
Copy link
Contributor

bors commented Dec 30, 2019

📌 Commit cd73034 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 30, 2019
@bors
Copy link
Contributor

bors commented Dec 31, 2019

⌛ Testing commit cd73034 with merge 8e49171...

bors added a commit that referenced this pull request Dec 31, 2019
…, 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
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-nopt of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-12-31T08:36:01.2387712Z 
2019-12-31T08:36:01.2387979Z 6    |              |
2019-12-31T08:36:01.2388707Z 7    |              let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2389061Z 8    |
2019-12-31T08:36:01.2395759Z - help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint
2019-12-31T08:36:01.2396353Z + help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2396470Z 10    |
2019-12-31T08:36:01.2396733Z 11 LL | fn elided(x: &i32) -> impl Copy + '_ { x }
2019-12-31T08:36:01.2396876Z 
2019-12-31T08:36:01.2397137Z 20    |             lifetime `'a` defined here
2019-12-31T08:36:01.2397210Z 21    |
2019-12-31T08:36:01.2397475Z 22    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2397475Z 22    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2397797Z - help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint
2019-12-31T08:36:01.2401779Z + help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2019-12-31T08:36:01.2401892Z 24    |
2019-12-31T08:36:01.2402199Z 25 LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
2019-12-31T08:36:01.2402354Z 
2019-12-31T08:36:01.2402389Z 
2019-12-31T08:36:01.2402473Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2402473Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2402886Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/must_outlive_least_region_or_bound.nll/must_outlive_least_region_or_bound.nll.stderr
2019-12-31T08:36:01.2403223Z To update references, rerun the tests and pass the `--bless` flag
2019-12-31T08:36:01.2406275Z To only update this specific test, also pass `--test-args impl-trait/must_outlive_least_region_or_bound.rs`
2019-12-31T08:36:01.2406437Z error: 1 errors occurred comparing output.
2019-12-31T08:36:01.2406541Z status: exit code: 1
2019-12-31T08:36:01.2406541Z status: exit code: 1
2019-12-31T08:36:01.2407805Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/must_outlive_least_region_or_bound.nll" "-Zborrowck=mir" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/must_outlive_least_region_or_bound.nll/auxiliary" "-A" "unused"
2019-12-31T08:36:01.2408418Z ------------------------------------------
2019-12-31T08:36:01.2408488Z 
2019-12-31T08:36:01.2408755Z ------------------------------------------
2019-12-31T08:36:01.2409132Z stderr:
2019-12-31T08:36:01.2409132Z stderr:
2019-12-31T08:36:01.2409467Z ------------------------------------------
2019-12-31T08:36:01.2409563Z error: lifetime may not live long enough
2019-12-31T08:36:01.2409886Z   --> /checkout/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs:3:23
2019-12-31T08:36:01.2409993Z    |
2019-12-31T08:36:01.2410258Z LL | fn elided(x: &i32) -> impl Copy { x }
2019-12-31T08:36:01.2410596Z    |              -        ^^^^^^^^^ opaque type requires that `'1` must outlive `'static`
2019-12-31T08:36:01.2418370Z    |              let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2418477Z    |
2019-12-31T08:36:01.2418477Z    |
2019-12-31T08:36:01.2418796Z help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2418902Z    |
2019-12-31T08:36:01.2419155Z LL | fn elided(x: &i32) -> impl Copy + '_ { x }
2019-12-31T08:36:01.2419313Z 
2019-12-31T08:36:01.2419551Z error: lifetime may not live long enough
2019-12-31T08:36:01.2419903Z   --> /checkout/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs:6:32
2019-12-31T08:36:01.2420004Z    |
2019-12-31T08:36:01.2420004Z    |
2019-12-31T08:36:01.2420254Z LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
2019-12-31T08:36:01.2420582Z    |             --                 ^^^^^^^^^ opaque type requires that `'a` must outlive `'static`
2019-12-31T08:36:01.2420931Z    |             lifetime `'a` defined here
2019-12-31T08:36:01.2421002Z    |
2019-12-31T08:36:01.2421261Z    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2421261Z    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2421586Z help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2019-12-31T08:36:01.2421672Z    |
2019-12-31T08:36:01.2421942Z LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
2019-12-31T08:36:01.2422567Z 
2019-12-31T08:36:01.2422682Z error: lifetime may not live long enough
2019-12-31T08:36:01.2423312Z   --> /checkout/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs:12:69
2019-12-31T08:36:01.2423415Z    |
2019-12-31T08:36:01.2423415Z    |
2019-12-31T08:36:01.2424112Z LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
2019-12-31T08:36:01.2424548Z    |               -- lifetime `'a` defined here                         ^ returning this value requires that `'a` must outlive `'static`
2019-12-31T08:36:01.2425026Z    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2425368Z    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2425428Z 
2019-12-31T08:36:01.2425519Z error: lifetime may not live long enough
2019-12-31T08:36:01.2425519Z error: lifetime may not live long enough
2019-12-31T08:36:01.2425879Z   --> /checkout/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs:17:61
2019-12-31T08:36:01.2425996Z    |
2019-12-31T08:36:01.2426340Z LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
2019-12-31T08:36:01.2426823Z    |                          --  -- lifetime `'b` defined here  ^^^^^^^^^^^^^^^^ opaque type requires that `'b` must outlive `'a`
2019-12-31T08:36:01.2427283Z    |                          lifetime `'a` defined here
2019-12-31T08:36:01.2427388Z    |
2019-12-31T08:36:01.2427691Z    = help: consider adding the following bound: `'b: 'a`
2019-12-31T08:36:01.2427770Z 
2019-12-31T08:36:01.2427770Z 
2019-12-31T08:36:01.2427852Z error[E0310]: the parameter type `T` may not live long enough
2019-12-31T08:36:01.2428228Z   --> /checkout/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs:22:51
2019-12-31T08:36:01.2428327Z    |
2019-12-31T08:36:01.2428674Z LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
2019-12-31T08:36:01.2428899Z    |
2019-12-31T08:36:01.2429233Z    = help: consider adding an explicit lifetime bound `T: 'static`...
2019-12-31T08:36:01.2429326Z 
2019-12-31T08:36:01.2429400Z error: aborting due to 5 previous errors
---
2019-12-31T08:36:01.2430756Z 
2019-12-31T08:36:01.2430822Z 6    |                         |
2019-12-31T08:36:01.2431184Z 7    |                         let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2431296Z 8    |
2019-12-31T08:36:01.2431665Z - help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint
2019-12-31T08:36:01.2432074Z + help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2432329Z 10    |
2019-12-31T08:36:01.2432724Z 11 LL |     fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
2019-12-31T08:36:01.2432913Z 
2019-12-31T08:36:01.2433221Z 20    |                    lifetime `'a` defined here
2019-12-31T08:36:01.2433324Z 21    |
2019-12-31T08:36:01.2433623Z 22    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2433623Z 22    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2434022Z - help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint
2019-12-31T08:36:01.2434409Z + help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2019-12-31T08:36:01.2434530Z 24    |
2019-12-31T08:36:01.2434873Z 25 LL |     fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
2019-12-31T08:36:01.2435166Z 
2019-12-31T08:36:01.2435237Z 
2019-12-31T08:36:01.2435316Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2435316Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2435828Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/static-return-lifetime-infered.nll/static-return-lifetime-infered.nll.stderr
2019-12-31T08:36:01.2436197Z To update references, rerun the tests and pass the `--bless` flag
2019-12-31T08:36:01.2436596Z To only update this specific test, also pass `--test-args impl-trait/static-return-lifetime-infered.rs`
2019-12-31T08:36:01.2436763Z error: 1 errors occurred comparing output.
2019-12-31T08:36:01.2436845Z status: exit code: 1
2019-12-31T08:36:01.2436845Z status: exit code: 1
2019-12-31T08:36:01.2438129Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/impl-trait/static-return-lifetime-infered.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/static-return-lifetime-infered.nll" "-Zborrowck=mir" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/static-return-lifetime-infered.nll/auxiliary" "-A" "unused"
2019-12-31T08:36:01.2438798Z ------------------------------------------
2019-12-31T08:36:01.2438857Z 
2019-12-31T08:36:01.2439165Z ------------------------------------------
2019-12-31T08:36:01.2439249Z stderr:
2019-12-31T08:36:01.2439249Z stderr:
2019-12-31T08:36:01.2439545Z ------------------------------------------
2019-12-31T08:36:01.2439632Z error: lifetime may not live long enough
2019-12-31T08:36:01.2439993Z   --> /checkout/src/test/ui/impl-trait/static-return-lifetime-infered.rs:6:35
2019-12-31T08:36:01.2440090Z    |
2019-12-31T08:36:01.2440439Z LL |     fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
2019-12-31T08:36:01.2440848Z    |                         -         ^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'1` must outlive `'static`
2019-12-31T08:36:01.2441341Z    |                         let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2441438Z    |
2019-12-31T08:36:01.2441438Z    |
2019-12-31T08:36:01.2441811Z help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2441913Z    |
2019-12-31T08:36:01.2442254Z LL |     fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
2019-12-31T08:36:01.2442440Z 
2019-12-31T08:36:01.2442512Z error: lifetime may not live long enough
2019-12-31T08:36:01.2442870Z   --> /checkout/src/test/ui/impl-trait/static-return-lifetime-infered.rs:10:37
2019-12-31T08:36:01.2442976Z    |
2019-12-31T08:36:01.2442976Z    |
2019-12-31T08:36:01.2443411Z LL |     fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
2019-12-31T08:36:01.2443850Z    |                    --               ^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'a` must outlive `'static`
2019-12-31T08:36:01.2444301Z    |                    lifetime `'a` defined here
2019-12-31T08:36:01.2444386Z    |
2019-12-31T08:36:01.2444699Z    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2444699Z    = help: consider replacing `'a` with `'static`
2019-12-31T08:36:01.2445072Z help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2019-12-31T08:36:01.2445191Z    |
2019-12-31T08:36:01.2445514Z LL |     fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
2019-12-31T08:36:01.2445700Z 
2019-12-31T08:36:01.2445787Z error: aborting due to 2 previous errors
2019-12-31T08:36:01.2445839Z 
2019-12-31T08:36:01.2445879Z 
---
2019-12-31T08:36:01.2446940Z 
2019-12-31T08:36:01.2447010Z 6    |                          |
2019-12-31T08:36:01.2447370Z 7    |                          let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2447465Z 8    |
2019-12-31T08:36:01.2447855Z - help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint
2019-12-31T08:36:01.2448264Z + help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2448368Z 10    |
2019-12-31T08:36:01.2448706Z 11 LL |     async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
2019-12-31T08:36:01.2448897Z 
2019-12-31T08:36:01.2448938Z 
2019-12-31T08:36:01.2449026Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2449026Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2449566Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr
2019-12-31T08:36:01.2449968Z To update references, rerun the tests and pass the `--bless` flag
2019-12-31T08:36:01.2450381Z To only update this specific test, also pass `--test-args self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs`
2019-12-31T08:36:01.2450559Z error: 1 errors occurred comparing output.
2019-12-31T08:36:01.2450657Z status: exit code: 1
2019-12-31T08:36:01.2450657Z status: exit code: 1
2019-12-31T08:36:01.2452011Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll" "-Zborrowck=mir" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll/auxiliary" "-A" "unused"
2019-12-31T08:36:01.2452708Z ------------------------------------------
2019-12-31T08:36:01.2452767Z 
2019-12-31T08:36:01.2453071Z ------------------------------------------
2019-12-31T08:36:01.2453154Z stderr:
2019-12-31T08:36:01.2453154Z stderr:
2019-12-31T08:36:01.2453450Z ------------------------------------------
2019-12-31T08:36:01.2453553Z error: lifetime may not live long enough
2019-12-31T08:36:01.2453922Z   --> /checkout/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:48
2019-12-31T08:36:01.2454054Z    |
2019-12-31T08:36:01.2454466Z LL |     async fn f(self: Pin<&Self>) -> impl Clone { self }
2019-12-31T08:36:01.2454940Z    |                          -                     ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
2019-12-31T08:36:01.2455427Z    |                          let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2455538Z    |
2019-12-31T08:36:01.2455538Z    |
2019-12-31T08:36:01.2455895Z help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2456013Z    |
2019-12-31T08:36:01.2456322Z LL |     async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
2019-12-31T08:36:01.2456500Z 
2019-12-31T08:36:01.2456585Z error: aborting due to previous error
2019-12-31T08:36:01.2456637Z 
2019-12-31T08:36:01.2456676Z 
---
2019-12-31T08:36:01.2457725Z 
2019-12-31T08:36:01.2457793Z 6    |                    |
2019-12-31T08:36:01.2458145Z 7    |                    let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2458238Z 8    |
2019-12-31T08:36:01.2458619Z - help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint
2019-12-31T08:36:01.2459007Z + help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2459125Z 10    |
2019-12-31T08:36:01.2459453Z 11 LL |     fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
2019-12-31T08:36:01.2459612Z 
2019-12-31T08:36:01.2459680Z 
2019-12-31T08:36:01.2459758Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2459758Z The actual stderr differed from the expected stderr.
2019-12-31T08:36:01.2460293Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr
2019-12-31T08:36:01.2460695Z To update references, rerun the tests and pass the `--bless` flag
2019-12-31T08:36:01.2461097Z To only update this specific test, also pass `--test-args self/arbitrary_self_types_pin_lifetime_impl_trait.rs`
2019-12-31T08:36:01.2461274Z error: 1 errors occurred comparing output.
2019-12-31T08:36:01.2461373Z status: exit code: 1
2019-12-31T08:36:01.2461373Z status: exit code: 1
2019-12-31T08:36:01.2462671Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll" "-Zborrowck=mir" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll/auxiliary" "-A" "unused"
2019-12-31T08:36:01.2463355Z ------------------------------------------
2019-12-31T08:36:01.2463413Z 
2019-12-31T08:36:01.2463714Z ------------------------------------------
2019-12-31T08:36:01.2463796Z stderr:
2019-12-31T08:36:01.2463796Z stderr:
2019-12-31T08:36:01.2464093Z ------------------------------------------
2019-12-31T08:36:01.2464178Z error: lifetime may not live long enough
2019-12-31T08:36:01.2464549Z   --> /checkout/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.rs:8:31
2019-12-31T08:36:01.2464666Z    |
2019-12-31T08:36:01.2465031Z LL |     fn f(self: Pin<&Self>) -> impl Clone { self } //~ ERROR cannot infer an appropriate lifetime
2019-12-31T08:36:01.2465543Z    |                    -          ^^^^^^^^^^ opaque type requires that `'1` must outlive `'static`
2019-12-31T08:36:01.2466030Z    |                    let's call the lifetime of this reference `'1`
2019-12-31T08:36:01.2466122Z    |
2019-12-31T08:36:01.2466122Z    |
2019-12-31T08:36:01.2466497Z help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
2019-12-31T08:36:01.2466613Z    |
2019-12-31T08:36:01.2466982Z LL |     fn f(self: Pin<&Self>) -> impl Clone + '_ { self } //~ ERROR cannot infer an appropriate lifetime
2019-12-31T08:36:01.2467171Z 
2019-12-31T08:36:01.2467240Z error: aborting due to previous error
2019-12-31T08:36:01.2467311Z 
2019-12-31T08:36:01.2467351Z 
---
2019-12-31T08:36:01.2470098Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:385:22
2019-12-31T08:36:01.2470232Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-12-31T08:36:01.2470300Z 
2019-12-31T08:36:01.2470341Z 
2019-12-31T08:36:01.2472963Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--host-rustcflags" "-Crpath -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--llvm-version" "9.0.0-rust-1.42.0-nightly\n" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always" "--compare-mode" "nll"
2019-12-31T08:36:01.2475264Z 
2019-12-31T08:36:01.2475333Z 
2019-12-31T08:36:01.2491369Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-12-31T08:36:01.2491500Z Build completed unsuccessfully in 1:45:47
2019-12-31T08:36:01.2491500Z Build completed unsuccessfully in 1:45:47
2019-12-31T08:36:01.2543780Z == clock drift check ==
2019-12-31T08:36:01.2556451Z   local time: Tue Dec 31 08:36:01 UTC 2019
2019-12-31T08:36:01.5241612Z   network time: Tue, 31 Dec 2019 08:36:01 GMT
2019-12-31T08:36:01.5245665Z == end clock drift check ==
2019-12-31T08:36:02.6271752Z 
2019-12-31T08:36:02.6392981Z ##[error]Bash exited with code '1'.
2019-12-31T08:36:02.6439814Z ##[section]Starting: Checkout
2019-12-31T08:36:02.6442035Z ==============================================================================
2019-12-31T08:36:02.6458188Z Task         : Get sources
2019-12-31T08:36:02.6458300Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Dec 31, 2019

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 31, 2019
@ohadravid ohadravid force-pushed the impl-trait-does-not-live-long-enough branch from cd73034 to 1a4f6b8 Compare December 31, 2019 11:13
@ohadravid
Copy link
Contributor Author

Ah it was --compare-mode=nll.. sorry about that! I blessed it again and now it should also pass the full CI 😄 @Mark-Simulacrum

@Dylan-DPC-zz
Copy link

@bors r=estebank

@bors
Copy link
Contributor

bors commented Jan 2, 2020

📌 Commit 1a4f6b8 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 2, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jan 3, 2020
…long-enough, r=estebank

Suggest adding a lifetime constraint for opaque type

Fixes rust-lang#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
bors added a commit that referenced this pull request Jan 3, 2020
Rollup of 10 pull requests

Successful merges:

 - #67450 (Allow for setting a ThinLTO import limit during bootstrap)
 - #67595 (Suggest adding a lifetime constraint for opaque type)
 - #67636 (allow rustfmt key in [build] section)
 - #67736 (Less-than is asymmetric, not antisymmetric)
 - #67762 (Add missing links for insecure_time)
 - #67783 (Warn for bindings named same as variants when matching against a borrow)
 - #67796 (Ensure that we process projections during MIR inlining)
 - #67807 (Use drop instead of the toilet closure `|_| ()`)
 - #67816 (Clean up err codes)
 - #67825 (Minor: change take() docs grammar to match other docs)

Failed merges:

r? @ghost
@bors bors merged commit 1a4f6b8 into rust-lang:master Jan 3, 2020
@ohadravid ohadravid deleted the impl-trait-does-not-live-long-enough branch January 3, 2020 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-sense diagnostic message from lifetime checker
8 participants