-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[NLL] Use span of the closure args in free region errors #53088
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
error: unsatisfied lifetime constraints | ||
--> $DIR/issue-40510-1.rs:18:9 | ||
| | ||
LL | || { | ||
| _____- | ||
| |_____| | ||
| || | ||
LL | || &mut x | ||
| || ^^^^^^ return requires that `'1` must outlive `'2` | ||
LL | || }; | ||
| || - | ||
| ||_____| | ||
| |______lifetime `'1` represents the closure body | ||
| lifetime `'2` appears in return type | ||
LL | || { | ||
| -- | ||
| | | ||
| lifetime `'1` represents this closure's body | ||
| lifetime `'2` appears in return type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to say "in return type of this closure" -- this confused me for quite a bit |
||
LL | &mut x | ||
| ^^^^^^ return requires that `'1` must outlive `'2` | ||
| | ||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also so nice — I do wonder if we can "re-orient" the message around this note though. Something like this:
maybe we should shelve this for a later improvement, though -- in particular, I would really like to do a bit more analysis and connect the message to the variable
|
||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
error: unsatisfied lifetime constraints | ||
--> $DIR/issue-40510-3.rs:18:9 | ||
| | ||
LL | || { | ||
| _____- | ||
| |_____| | ||
| || | ||
LL | || || { | ||
| ||_________^ | ||
LL | ||| x.push(()) | ||
LL | ||| } | ||
| |||_________^ requires that `'1` must outlive `'2` | ||
LL | || }; | ||
| || - | ||
| ||_____| | ||
| |______lifetime `'1` represents the closure body | ||
| lifetime `'2` appears in return type | ||
LL | || { | ||
| -- | ||
| | | ||
| lifetime `'1` represents this closure's body | ||
| lifetime `'2` appears in return type | ||
LL | / || { | ||
LL | | x.push(()) | ||
LL | | } | ||
| |_________^ requires that `'1` must outlive `'2` | ||
| | ||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
error: unsatisfied lifetime constraints | ||
--> $DIR/issue-49824.rs:22:9 | ||
| | ||
LL | || { | ||
| _____- | ||
| |_____| | ||
| || | ||
LL | || || { | ||
| ||_________^ | ||
LL | ||| let _y = &mut x; | ||
LL | ||| } | ||
| |||_________^ requires that `'1` must outlive `'2` | ||
LL | || }; | ||
| || - | ||
| ||_____| | ||
| |______lifetime `'1` represents the closure body | ||
| lifetime `'2` appears in return type | ||
LL | || { | ||
| -- | ||
| | | ||
| lifetime `'1` represents this closure's body | ||
| lifetime `'2` appears in return type | ||
LL | / || { | ||
LL | | let _y = &mut x; | ||
LL | | } | ||
| |_________^ requires that `'1` must outlive `'2` | ||
| | ||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure | ||
|
||
error: aborting due to previous error | ||
|
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.
We can do better here, too.
mir.span
is pretty horrific in all cases. Maybe we leave that for another issue though. We would want to extract (from the HIR) the span of the return type, I suppose. Really, we should do the same "return type is&'1 u32
" sort of thing we do for arguments, right?I wonder if, for closures, we can highlight just the final
|
?So it would look like:
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.
This is the code to extract the type name:
rust/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs
Lines 278 to 280 in 4b8089d
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.
To get the final character you can use the
end_point
method