Skip to content

False-positive explicit_deref_methods on method chains #14593

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

Closed
dima74 opened this issue Apr 11, 2025 · 1 comment · Fixed by #14921
Closed

False-positive explicit_deref_methods on method chains #14593

dima74 opened this issue Apr 11, 2025 · 1 comment · Fixed by #14921
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dima74
Copy link
Contributor

dima74 commented Apr 11, 2025

Summary

Lint explicit_deref_methods should not warn in case of method chains.

Lint Name

explicit_deref_methods

Reproducer

Consider code:

use std::ops::Deref;
use std::sync::Mutex;

fn func(data: &Mutex<i32>) {
    let _ = data.lock().unwrap().deref();
}
[lints]
clippy.pedantic = "warn"

It gives warning:

warning: explicit `deref` method call
 --> src/main.rs:5:13
  |
5 |     let _ = data.lock().unwrap().deref();
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*data.lock().unwrap()`
  |

However according to lint description in case of method chains there should be no warning:

Dereferencing by &*x or &mut *x is clearer and more concise, when not part of a method chain.

This lint excludes all of:
let _ = d.unwrap().deref();

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

No response

@dima74 dima74 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 11, 2025
@a-yossy
Copy link
Contributor

a-yossy commented May 30, 2025

@rustbot claim

github-merge-queue bot pushed a commit that referenced this issue May 30, 2025
changelog: [`explicit_deref_methods`]: do not lint on method chains
fixes #14593
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants