-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Point at fn bound that introduced lifetime obligation #146011
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
Conversation
| - `c` dropped here while still borrowed | ||
| | ||
note: requirement that `c` is borrowed for `'a` introduced here | ||
note: requirement for `'a` introduced here |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"), | ||
); |
There was a problem hiding this comment.
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) = ...
:<
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after nit
``` 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) {} | ^^ ^^ ```
79982d7
to
c5313fe
Compare
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. |
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) {} | ||
| ^^ ^^ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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🤔
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) {} | ||
| ^^ ^^ |
There was a problem hiding this comment.
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🤔
@bors r+ rollup |
… 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.
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
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.
The last note is new
When encountering a
ConstraintCategory::Predicate
in a funtion call, point at theSpan
for thatPredicate
to explain where the lifetime obligation originates from.CC #55307.