Skip to content

Commit

Permalink
[lint] Don't lint needless mut reference on _ignored variables (#15762)
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethk authored Jan 16, 2025
1 parent 4b69e48 commit d52887a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl MutableReferenceUsageTracker {
for instr in target.get_bytecode() {
tracker.update(target, instr);
}
tracker.get_mutably_unused_locations()
tracker.get_mutably_unused_locations(target)
}

/// Get an initial tracker from function parameters.
Expand All @@ -67,11 +67,15 @@ impl MutableReferenceUsageTracker {
}

/// Get locations where origins are not used mutably.
fn get_mutably_unused_locations(self) -> Vec<Loc> {
fn get_mutably_unused_locations(self, target: &FunctionTarget) -> Vec<Loc> {
self.origins
.into_iter()
.filter_map(|(t, loc)| {
if !self.mutably_used.contains(&t) {
let ignore_local = target
.symbol_pool()
.string(target.get_local_name(t))
.starts_with('_');
if !ignore_local && !self.mutably_used.contains(&t) {
Some(loc)
} else {
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,10 @@ module 0xc0ffee::more_struct_tests {
consume_immut(u);
}
}

module 0xc0ffee::p {
fun no_warn_01(_x: &mut u64) {
let x = 1;
let _y = &mut x;
}
}

0 comments on commit d52887a

Please sign in to comment.