rust-lang / rust-lang/rust

`dropping_references` lint triggers even for mutable references

Open
#125,972 11 comments 1 reaction 1 assignee View on GitHub

@tbu- is already working on this.

Since Jun 11, 2024.

A-lints C-discussion
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

When I call std::mem::drop on a mutable reference, this is supposed to consume the reference and make it unavailable to following code. And indeed it does, because any following uses trigger a "use of moved value" error.

But when I do this, I get a warning from the compiler:

warning: calls to std::mem::drop with a reference instead of an owned value does nothing
--> foo.rs:1602:13
|
1602 | mem::drop(mutref);
| ^^^^^^^^^^-------------^
| |
| argument has type &mut Foo
|
= note: use let _ = ... to ignore the expression or result
= note: #[warn(dropping_references)] on by default

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (7c52d2db6 2024-06-03)
binary: rustc
commit-hash: 7c52d2db6348b038276198e88a835125849f322e
commit-date: 2024-06-03
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.