Skip to content

dropping_references lint triggers even for mutable references #125972

Open
@Rua

Description

@Rua

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

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-discussionCategory: Discussion or questions that doesn't represent real issues.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions