-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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] Returns are interesting for free regions #53175
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
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.
I'm happy with this, apart from wanting a comment. The results seem great.
| | | requires that `'1` must outlive `'2` | ||
| | has type `&'1 i32` | ||
| lifetime `'2` appears in return type | ||
| -- ^ returning this value requires that `'1` must outlive `'2` |
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.
👍
src/test/ui/issue-15034.nll.stderr
Outdated
| | ||
LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> { | ||
| ----- consider changing the type of `lexer` to `&'a mut Lexer<'a>` | ||
LL | Parser { lexer: lexer } | ||
| ^^^^^ lifetime `'a` required | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required |
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.
These seem less good but still "tolerable" — I think with a bit more thought we should be able to narrow back down to the lexer
expression. The problem is that we still have trouble distinguishing "intermediate, passthrough" regions (like the one on Parser
) from the "source regions" (the ones on lexer
). That's ok for now though I think.
src/test/ui/issue-40510-1.nll.stderr
Outdated
| |return type of closure is &'2 mut std::boxed::Box<()> | ||
| lifetime `'1` represents this closure's body | ||
LL | &mut x | ||
| ^^^^^^ returning this value requires that `'1` must outlive `'2` |
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.
Clear win. Nice!
| consider changing type to `(&'a i32, &'a i32)` | ||
| ------ consider changing type to `(&'a i32, &'a i32)` | ||
LL | if x > y { x } else { y } //~ ERROR explicit lifetime | ||
| ^ lifetime `'a` required |
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.
💯
@@ -42,7 +42,7 @@ impl fmt::Display for ConstraintCategory { | |||
// Must end with a space. Allows for empty names to be provided. | |||
match self { | |||
ConstraintCategory::Assignment => write!(f, "assignment "), | |||
ConstraintCategory::Return => write!(f, "return "), | |||
ConstraintCategory::Return => write!(f, "returning this value "), |
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.
I like how this reads, though it's less "concise", which I think some people value. Still, seems ok to me.
@@ -254,7 +258,22 @@ impl<'tcx> RegionInferenceContext<'tcx> { | |||
debug!("classify_constraint: terminator.kind={:?}", terminator.kind); | |||
match terminator.kind { | |||
TerminatorKind::DropAndReplace { .. } => ConstraintCategory::Assignment, | |||
TerminatorKind::Call { .. } => ConstraintCategory::CallArgument, | |||
TerminatorKind::Call { destination: Some((ref place, _)), .. } => { | |||
if tcx.any_free_region_meets( |
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.
I'd like a comment here... something lke:
Classify calls differently depending on whether or not the sub
region appears in the return type. If the return type contains the sub-region, then this is either an assignment or a return, depending on whether we are writing to the RETURN_PLACE
or not. The idea here is that the region is being propagated from an input into the output place, so it's a kind of assignment. Otherwise, if the sub-region only appears in the argument types, then use the CallArgument
classification.
infcx.extract_type_name(&return_ty) | ||
}); | ||
|
||
let mir_node_id = tcx.hir.as_local_node_id(mir_def_id).expect("non-local mir"); |
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.
Nit: wild indentation
9586af6
to
0cecd38
Compare
Rebased, some tests were changed in the mean time. Added another commit where we had lifetimes in some messages the wrong way around. |
This comment has been minimized.
This comment has been minimized.
0cecd38
to
49cf4e1
Compare
@bors r+ |
📌 Commit 49cf4e1e49e8ef5527148fa663d47ace4a30f89c has been approved by |
49cf4e1
to
a19db49
Compare
Rebased and tests updated |
@bors r+ |
📌 Commit a19db49 has been approved by |
⌛ Testing commit a19db49 with merge 5cbed2c8cc23b11aee0543296770e77137070580... |
💔 Test failed - status-travis |
💔 Test failed - status-travis |
The job Click to expand the log.
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 |
⌛ Testing commit a19db49 with merge 3087520eac999cbb0b528b0985381a0b5b33e80c... |
💔 Test failed - status-travis |
The job Click to expand the log.
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 |
⌛ Testing commit a19db49 with merge 5c194343d069ce4839b85c1208b434e48afe4146... |
💔 Test failed - status-travis |
The job Click to expand the log.
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 |
@bors retry
|
[NLL] Returns are interesting for free regions Based on #53088 - creating now to get feedback. Closes #51175 * Make assigning to the return type interesting. * Use "returning this value" instead of "return" in error messages. * Prefer one of the explanations that we have a name for to a generic interesting cause in some cases. * Treat causes that involve the destination of a call like assignments.
☀️ Test successful - status-appveyor, status-travis |
Based on #53088 - creating now to get feedback.
Closes #51175