-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.L-dangerous_implicit_autorefsLint: dangerous_implicit_autorefsLint: dangerous_implicit_autorefsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Let's take the following example:
unsafe fn slice_ptr_len_because_of_msrv<T>(slice: *[T]) -> usize {
unsafe { (*slice).len() }
}
on current nightly, it triggers:
warning: implicit autoref creates a reference to the dereference of a raw pointer
--> src/main.rs:2:14
|
3 | unsafe { (*slice).len() }
| ^^^^^^^^^^^^^^
|
= note: creating a reference requires the pointer target to be valid and imposes aliasing requirements
= note: `#[warn(dangerous_implicit_autorefs)]` on by default
help: try using a raw pointer method instead; or if this reference is intentional, make it explicit
|
3 | unsafe { (&(*slice)).len() }
| ++ +
If the suggestion is applied, then clippy complains:
warning: this expression borrows a value the compiler would automatically borrow
--> src/main.rs:2:14
|
2 | unsafe { (&(*slice)).len() }
| ^^^^^^^^^^^ help: change this to: `(*slice)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
= note: `#[warn(clippy::needless_borrow)]` on by default
Curiously enough, (*slice)[..].len()
also triggers dangerous_implicit_autorefs
, but the suggested (&(*slice))[..].len()
doesn't trigger clippy::needless_borrow
.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.L-dangerous_implicit_autorefsLint: dangerous_implicit_autorefsLint: dangerous_implicit_autorefsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.