Skip to content

False-positive explicit_deref_methods on method chains #14593

Open
@dima74

Description

@dima74

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions