Closed
Description
Borrowing an expression is side-effect free, so there should never be a reason to write the first instead of the second.
&expr;
// vs
expr;
If you really wanted to do this you could assign the result to an unused variable:
let _ = &expr;
Therefore, we should add a lint for unused borrows to the compiler. Why is this important? A misplaced semi-colon before an &&
operator in a multi-line boolean expression causes subsequent clauses to be silently ignored.
let trex = TyrannosaurusRex::new();
let is_a_dog = has_a_tail(trex)
&& has_bad_breath(trex)
&& is_a_carnivore(trex); // Misplaced semi-colon (perhaps due to reordering of lines)
&& is_adorable(trex);
if is_a_dog {
give_hug(trex); // Ouch!
}
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Category: A feature request, i.e: not implemented / a PR.Diagnostics: An error or lint that needs small tweaks.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Help is requested to fix this issue.