-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
When moving out of a for loop head, suggest borrowing it #59195
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@@ -746,6 +747,19 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |||
}, | |||
moved_lp.ty)); | |||
} | |||
if let (Some(CompilerDesugaringKind::ForLoop), Ok(snippet)) = ( |
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 might want to use a separate CompilerDesugaringKind
variant to differentiate in errors, something along the lines of ForLoopHead
, or something, or modify ForLoop
to carry information on wether the source is completely synthetic or just moving around code that the user has written.
@@ -746,6 +747,19 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |||
}, | |||
moved_lp.ty)); | |||
} | |||
if let (Some(CompilerDesugaringKind::ForLoop), Ok(snippet)) = ( | |||
move_span.compiler_desugaring_kind(), | |||
self.tcx.sess.source_map().span_to_snippet(move_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.
Nit: not sure whether span_to_snippet
is expensive or not, but if it is, them it may make sense to nest if let
s to avoid pessimizing.
@bors r+ |
📌 Commit d189e6d has been approved by |
When moving out of a for loop head, suggest borrowing it When encountering code like the following, suggest borrowing the for loop head to avoid moving it into the for loop pattern: ``` fn main() { let a = vec![1, 2, 3]; for i in &a { for j in a { println!("{} * {} = {}", i, j, i * j); } } } ``` Fix rust-lang#25534.
This comment has been minimized.
This comment has been minimized.
@bors r=petrochenkov |
📌 Commit 6efdfbd9aa3947cf33132994d0a4930c6fba8db5 has been approved by |
⌛ Testing commit 6efdfbd9aa3947cf33132994d0a4930c6fba8db5 with merge e65450e978c5fa0833e3724c53c59615d47f6270... |
💔 Test failed - checks-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 |
When encountering code like the following, suggest borrowing the for loop head to avoid moving it into the for loop pattern: ``` fn main() { let a = vec![1, 2, 3]; for i in &a { for j in a { println!("{} * {} = {}", i, j, i * j); } } } ```
@bors r=petrochenkov I'll deal with replicating this output in nll mode later. |
📌 Commit 66202c1 has been approved by |
When moving out of a for loop head, suggest borrowing it When encountering code like the following, suggest borrowing the for loop head to avoid moving it into the for loop pattern: ``` fn main() { let a = vec![1, 2, 3]; for i in &a { for j in a { println!("{} * {} = {}", i, j, i * j); } } } ``` Fix #25534.
☀️ Test successful - checks-travis, status-appveyor |
…chenkov When moving out of a for loop head, suggest borrowing it in nll mode Follow up to rust-lang#59195 for NLL.
…chenkov When moving out of a for loop head, suggest borrowing it in nll mode Follow up to rust-lang#59195 for NLL.
…chenkov When moving out of a for loop head, suggest borrowing it in nll mode Follow up to rust-lang#59195 for NLL.
When encountering code like the following, suggest borrowing the for loop
head to avoid moving it into the for loop pattern:
Fix #25534.