-
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
Only warn about unused mut
in user-written code
#54787
Changes from all commits
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 |
---|---|---|
|
@@ -4058,16 +4058,16 @@ impl<'a> LoweringContext<'a> { | |
// expand <head> | ||
let head = self.lower_expr(head); | ||
let head_sp = head.span; | ||
let desugared_span = self.allow_internal_unstable( | ||
CompilerDesugaringKind::ForLoop, | ||
head_sp, | ||
); | ||
|
||
let iter = self.str_to_ident("iter"); | ||
|
||
let next_ident = self.str_to_ident("__next"); | ||
let next_sp = self.allow_internal_unstable( | ||
CompilerDesugaringKind::ForLoop, | ||
head_sp, | ||
); | ||
let next_pat = self.pat_ident_binding_mode( | ||
next_sp, | ||
desugared_span, | ||
next_ident, | ||
hir::BindingAnnotation::Mutable, | ||
); | ||
|
@@ -4096,8 +4096,11 @@ impl<'a> LoweringContext<'a> { | |
}; | ||
|
||
// `mut iter` | ||
let iter_pat = | ||
self.pat_ident_binding_mode(head_sp, iter, hir::BindingAnnotation::Mutable); | ||
let iter_pat = self.pat_ident_binding_mode( | ||
desugared_span, | ||
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. Must be because this is now using 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. @nikomatsakis For my understanding could you clarify what does normalizing spans mean ? 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. @blitzerr: notice that the problem in this failing test is that an error about a trait bound has been duplicated. The issue here is probably that to check whether these sorts of errors should be emitted (when they might be generated multiple times), the compiler checks against the spans of previously-emitted errors. In this case, one of the errors has span 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. @varkor Thanks a lot for the explanation. Makes sense. |
||
iter, | ||
hir::BindingAnnotation::Mutable | ||
); | ||
|
||
// `match ::std::iter::Iterator::next(&mut iter) { ... }` | ||
let match_expr = { | ||
|
@@ -4126,8 +4129,12 @@ impl<'a> LoweringContext<'a> { | |
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id)); | ||
|
||
// `let mut __next` | ||
let next_let = | ||
self.stmt_let_pat(head_sp, None, next_pat, hir::LocalSource::ForLoopDesugar); | ||
let next_let = self.stmt_let_pat( | ||
desugared_span, | ||
None, | ||
next_pat, | ||
hir::LocalSource::ForLoopDesugar, | ||
); | ||
|
||
// `let <pat> = __next` | ||
let pat = self.lower_pat(pat); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// run-pass | ||
|
||
#![deny(unused_mut)] | ||
#![allow(unreachable_code)] | ||
|
||
fn main() { | ||
for _ in { return (); 0..3 } {} // ok | ||
} |
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.
Am I right that desugared_span is just the renaming of next_sp ?
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.
Yes, that's correct. I just moved it so that both the spans that were being referenced multiple times were in the same place.
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.
makes sense