Open
Description
Summary
.
Lint Name
explicit_deref_methods
Reproducer
I tried this code:
#![warn(clippy::explicit_deref_methods)]
use std::pin::Pin;
use std::sync::Mutex;
use std::ops::Deref;
pub struct Stderr(Mutex<()>);
pub fn poll_write(x: Pin<&mut Stderr>) {
let _ = &mut *Deref::deref(&x).0.lock().unwrap();
}
pub fn main() {}
I saw this happen:
warning: explicit `deref` method call
--> src/main.rs:9:19
|
9 | let _ = &mut *Deref::deref(&x).0.lock().unwrap();
| ^^^^^^^^^^^^^^^^ help: try: `&**&x`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_deref_methods
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::explicit_deref_methods)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the suggested code.
#![warn(clippy::explicit_deref_methods)]
use std::pin::Pin;
use std::sync::Mutex;
use std::ops::Deref;
pub struct Stderr(Mutex<()>);
pub fn poll_write(x: Pin<&mut Stderr>) {
let _ = &mut *&**&x.0.lock().unwrap();
}
pub fn main() {}
does not compile:
error[E0596]: cannot borrow data in a `&` reference as mutable
--> src/main.rs:9:13
|
9 | let _ = &mut *&**&x.0.lock().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
For more information about this error, try `rustc --explain E0596`.
Version
Additional Labels
No response