-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.
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!
}
jyn514, workingjubilee, estebank, Sh3Rm4n, dobrakmato and 1 morekornelski, pickfire, strohel, scottmcm and inashivb
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.