-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Lint for unused borrows as part of UNUSED_MUST_USE
#76894
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Lint for unused borrows as part of UNUSED_MUST_USE
#76894
Conversation
r? @lcnr (rust_highfive has picked a reviewer for you, use r? to override) |
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.
LGTM
does this need lang or compiler signoff considering that this is a userfacing change?
How similar is this to clippys needless_borrow lint? |
I think it needs @rust-lang/lang approval, but I'm not 100% sure. @matthiaskrgr Sounds similar. I don't use clippy. |
Ah, so the transformation from 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!
} There are various alternatives with no false positives: Only triggering on |
Afaict the exprs which do so are the following: &slice[..];
&y[0];
&*boxed; all of which seem like something we can (and should) warn on, even if the suggestion is incorrect. |
For my own clarity, postfix indexing ( Also, I'm starting to think this should be folded into |
1693ffb
to
2c56247
Compare
The author probably meant to call `hash_stable` on a reference to the field in question.
2c56247
to
3b5105c
Compare
UNUSED_MUST_USE
This is now part of |
This makes sense to me. Since we lint on I don't know whether this needs a full FCP (we can talk about it on Monday), but in case it does, |
Team member @scottmcm has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns: Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I definitely approved a similar PR (#74869) without lang team approval. lcnr asked about the process in #76894 (review), and it occurred to me that I didn't actually know. If the lang-team does want to weigh in on this, they should consider it in concert with #69466, which also involves side-effects and |
@rfcbot concern crater Enthusiastic about this intuitively, but I'd like a crater run to make sure that this isn't going to suddenly lint a large part of the ecosystem or anything. |
… 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`.
@ecstatic-morse any updates on this? |
322: v0.4: Fix unused_must_use warning on unused borrows r=taiki-e a=taiki-e This fixes `unused_must_use` warning on unused borrows, which will be added to rustc in the future. See rust-lang/rust#76894 fore more. (Note: pin-project 1.0 does not have this problem.) Co-authored-by: Taiki Endo <te316e89@gmail.com>
322: v0.4: Fix unused_must_use warning on unused borrows r=taiki-e a=taiki-e This fixes `unused_must_use` warning on unused borrows, which will be added to rustc in the future. See rust-lang/rust#76894 fore more. (Note: pin-project 1.0 does not have this problem.) Co-authored-by: Taiki Endo <te316e89@gmail.com>
I am not able to review any PRs in the near future. r? @RalfJung |
Given that @ecstatic-morse has been inactive here for months and in general does not seem to be doing much Rust work any more, I'm going to close this PR for now. |
…=Aaron1011 Lint for unused borrows as part of UNUSED_MUST_USE close rust-lang#76264 base on rust-lang#76894 r? `@RalfJung`
…aron1011 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`
Unused references have become a build warning in the rust compiler and as warning are errors in our build, this is blocking the rust toolchain from rolling. See rust-lang/rust#76894 Change-Id: Ifcbdcc93efa4ca53003c99515767b58dc3675194 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/545184 Commit-Queue: Adrian Danis <adanis@google.com> Fuchsia-Auto-Submit: Adrian Danis <adanis@google.com> Reviewed-by: Chris Suter <csuter@google.com>
Resolves #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 inrustc
's test suite, since we have tests that rely on side-effects of the index operator (panicking). These cannot be written asexpr[..];
, since the result is unsized, but they can be written aslet _ = &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
.