Skip to content

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Aug 29, 2025

The last note is new

error[E0597]: `c` does not live long enough
  --> $DIR/without-precise-captures-we-are-powerless.rs:19:20
   |
LL | fn simple<'a>(x: &'a i32) {
   |           -- lifetime `'a` defined here
...
LL |     let c = async move || { println!("{}", *x); };
   |         - binding `c` declared here
LL |     outlives::<'a>(c());
   |     ---------------^---
   |     |              |
   |     |              borrowed value does not live long enough
   |     argument requires that `c` is borrowed for `'a`
LL |     outlives::<'a>(call_once(c));
LL | }
   | - `c` dropped here while still borrowed
   |
note: requirement that `c` is borrowed for `'a` introduced here
  --> $DIR/without-precise-captures-we-are-powerless.rs:7:33
   |
LL | fn outlives<'a>(_: impl Sized + 'a) {}
   |                                 ^^

When encountering a ConstraintCategory::Predicate in a funtion call, point at the Span for that Predicate to explain where the lifetime obligation originates from.

CC #55307.

@rustbot
Copy link
Collaborator

rustbot commented Aug 29, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 29, 2025
| - `c` dropped here while still borrowed
|
note: requirement that `c` is borrowed for `'a` introduced here
note: requirement for `'a` introduced here
Copy link
Contributor

@lcnr lcnr Aug 31, 2025

Choose a reason for hiding this comment

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

what is a requirement for 'a, I feel like the requirement is for the APIT here, not 'a. Is it not possible to keep sth like "requirement that outlives " introduced here"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to "requirement that the value outlives 'a introduced here".

| argument requires that borrow lasts for `'a`
|
note: requirement that the value outlives `'a` introduced here
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
Copy link
Contributor

@lcnr lcnr Sep 17, 2025

Choose a reason for hiding this comment

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

how come this doesn't actually show the predicate which caused this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the span is in std, which don't get displayed when the sources aren't found (like when path remap is being used, which is done for all tests).

err.span_note(
pred,
format!("requirement that the value outlives `{region_name}` introduced here"),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

if we report this for all preds while always using region_name it'd be reported twice here, would it?

fn outlives_indir<'a: 'b, 'b, T: 'a>(x: T) {}

fn foo<'b>() {
    outlives_indir::<'_, 'b, _>(&mut 1u32);
}

in a sense it would be

  • requirement that the value outlives {other_region} introduced here
  • requirement that {other_region} outlives {region_name} introduced here

ahhh. you break. please make this a if let Some(pred_span) = ... :<

Copy link
Contributor

@lcnr lcnr Sep 25, 2025

Choose a reason for hiding this comment

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

actually, idk if that's much easier to read, pls either use an if let = iter.find(..) instead of a loop here or add a comment that we only print this note for the first occurrance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to be if let Some(span) = iter.filter_map(...).next().

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

@lcnr lcnr 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-review Status: Awaiting review from the assignee but also interested parties. labels Sep 17, 2025
```
error[E0597]: `c` does not live long enough
  --> $DIR/without-precise-captures-we-are-powerless.rs:19:20
   |
LL | fn simple<'a>(x: &'a i32) {
   |           -- lifetime `'a` defined here
...
LL |     let c = async move || { println!("{}", *x); };
   |         - binding `c` declared here
LL |     outlives::<'a>(c());
   |     ---------------^---
   |     |              |
   |     |              borrowed value does not live long enough
   |     argument requires that `c` is borrowed for `'a`
LL |     outlives::<'a>(call_once(c));
LL | }
   | - `c` dropped here while still borrowed
   |
note: requirement that `c` is borrowed for `'a` introduced here
  --> $DIR/without-precise-captures-we-are-powerless.rs:7:33
   |
LL | fn outlives<'a>(_: impl Sized + 'a) {}
   |                                 ^^
```

When encountering a `ConstraintCategory::Predicate` in a funtion call, point at the `Span` for that `Predicate` to explain where the lifetime obligation originates from.
```
error[E0716]: temporary value dropped while borrowed
  --> $DIR/multiple-sources-for-outlives-requirement.rs:5:38
   |
LL | fn foo<'b>() {
   |        -- lifetime `'b` defined here
LL |     outlives_indir::<'_, 'b, _>(&mut 1u32);
   |     ---------------------------------^^^^-- temporary value is freed at the end of this statement
   |     |                                |
   |     |                                creates a temporary value which is freed while still in use
   |     argument requires that borrow lasts for `'b`
   |
note: requirements that the value outlives `'b` introduced here
  --> $DIR/multiple-sources-for-outlives-requirement.rs:1:23
   |
LL | fn outlives_indir<'a: 'b, 'b, T: 'a>(_x: T) {}
   |                       ^^         ^^
```
@estebank estebank force-pushed the lifetime-obligation-span branch from 79982d7 to c5313fe Compare September 28, 2025 21:14
@rustbot
Copy link
Collaborator

rustbot commented Sep 28, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment on lines +12 to +16
note: requirements that the value outlives `'b` introduced here
--> $DIR/multiple-sources-for-outlives-requirement.rs:1:23
|
LL | fn outlives_indir<'a: 'b, 'b, T: 'a>(_x: T) {}
| ^^ ^^
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The last commit is independent and changes it to point at every requirement, as previously this error was pointing only at the second span, which even though is correct, it isn't very understandable to someone who doesn't have a good grasp of Rust yet. What do you think @lcnr? I can drop the last commit and make it point just at the 'a here.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I agree that this seems better than just pointing at one of them🤔

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 28, 2025
Comment on lines +12 to +16
note: requirements that the value outlives `'b` introduced here
--> $DIR/multiple-sources-for-outlives-requirement.rs:1:23
|
LL | fn outlives_indir<'a: 'b, 'b, T: 'a>(_x: T) {}
| ^^ ^^
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I agree that this seems better than just pointing at one of them🤔

@lcnr
Copy link
Contributor

lcnr commented Sep 30, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Sep 30, 2025

📌 Commit c5313fe has been approved by lcnr

It is now in the queue for this repository.

@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 Sep 30, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 30, 2025
… r=lcnr

Point at fn bound that introduced lifetime obligation

The last note is new
```
error[E0597]: `c` does not live long enough
  --> $DIR/without-precise-captures-we-are-powerless.rs:19:20
   |
LL | fn simple<'a>(x: &'a i32) {
   |           -- lifetime `'a` defined here
...
LL |     let c = async move || { println!("{}", *x); };
   |         - binding `c` declared here
LL |     outlives::<'a>(c());
   |     ---------------^---
   |     |              |
   |     |              borrowed value does not live long enough
   |     argument requires that `c` is borrowed for `'a`
LL |     outlives::<'a>(call_once(c));
LL | }
   | - `c` dropped here while still borrowed
   |
note: requirement that `c` is borrowed for `'a` introduced here
  --> $DIR/without-precise-captures-we-are-powerless.rs:7:33
   |
LL | fn outlives<'a>(_: impl Sized + 'a) {}
   |                                 ^^
```

When encountering a `ConstraintCategory::Predicate` in a funtion call, point at the `Span` for that `Predicate` to explain where the lifetime obligation originates from.

CC rust-lang#55307.
bors added a commit that referenced this pull request Sep 30, 2025
Rollup of 5 pull requests

Successful merges:

 - #140916 (Fix unuseful span in type error in some format_args!() invocations)
 - #146011 (Point at fn bound that introduced lifetime obligation)
 - #146649 (cmse: fix 'region variables should not be hashed')
 - #147109 (Rename various "concrete opaque type" things to say "hidden type")
 - #147167 (Don't condition RUSTDOC_LIBDIR on `--no-doc`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1aa426b into rust-lang:master Sep 30, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Sep 30, 2025
rust-timer added a commit that referenced this pull request Sep 30, 2025
Rollup merge of #146011 - estebank:lifetime-obligation-span, r=lcnr

Point at fn bound that introduced lifetime obligation

The last note is new
```
error[E0597]: `c` does not live long enough
  --> $DIR/without-precise-captures-we-are-powerless.rs:19:20
   |
LL | fn simple<'a>(x: &'a i32) {
   |           -- lifetime `'a` defined here
...
LL |     let c = async move || { println!("{}", *x); };
   |         - binding `c` declared here
LL |     outlives::<'a>(c());
   |     ---------------^---
   |     |              |
   |     |              borrowed value does not live long enough
   |     argument requires that `c` is borrowed for `'a`
LL |     outlives::<'a>(call_once(c));
LL | }
   | - `c` dropped here while still borrowed
   |
note: requirement that `c` is borrowed for `'a` introduced here
  --> $DIR/without-precise-captures-we-are-powerless.rs:7:33
   |
LL | fn outlives<'a>(_: impl Sized + 'a) {}
   |                                 ^^
```

When encountering a `ConstraintCategory::Predicate` in a funtion call, point at the `Span` for that `Predicate` to explain where the lifetime obligation originates from.

CC #55307.
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants