-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Warn when a borrow expression is unused #76264
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
Comments
… r=lcnr Lint for unused borrows as part of `UNUSED_MUST_USE` Resolves rust-lang#76264. This means an `unused_must_use` warning for statements like `&expr;` and `&mut expr;`. `unused_must_use` was chosen because it already lints for logical operators (`&&` and `||`) whose result is unused. Unused borrows actually appear fairly often in `rustc`'s test suite, since we have tests that rely on side-effects of the index operator (panicking). These cannot be written as `expr[..];`, since the result is unsized, but they can be written as `let _ = &expr[..];`, which is what this PR does. See the linked issue for the motivating example. This lint also found a benign mistake in the derived impl of `HashStable`.
FWIW, the corresponding PR #76894 has been closed due to inactivity. However, it was basically ready, just needed tending to some conflicts and test failures, so if someone wants to pick it up that shouldn't be too hard. |
Hi @RalfJung ! I'd like to pick it up if its OK? |
@inashivb sure, go ahead. :) (I'm not necessarily the best reviewer for this PR, and I am pretty swamped currently, so I'd appreciate if someone else reading along could help with reviewing.) |
@rustbot claim |
…=Aaron1011 Lint for unused borrows as part of UNUSED_MUST_USE close rust-lang#76264 base on rust-lang#76894 r? `@RalfJung`
Lint for unused borrows as part of UNUSED_MUST_USE close rust-lang/rust#76264 base on rust-lang/rust#76894 r? `@RalfJung`
Borrowing an expression is side-effect free, so there should never be a reason to write the first instead of the second.
If you really wanted to do this you could assign the result to an unused variable:
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.The text was updated successfully, but these errors were encountered: