-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
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
The following code:
unsafe fn slice_ptr_len_because_of_msrv<T>(slice: *const [T]) -> usize {
unsafe { (*slice)[..].len() }
}
gives the two following warnings
warning: implicit autoref creates a reference to the dereference of a raw pointer
--> src/main.rs:2:14
|
2 | 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
|
2 | unsafe { (&(*slice)[..]).len() }
| ++ +
warning: implicit autoref creates a reference to the dereference of a raw pointer
--> src/main.rs:2:14
|
2 | unsafe { (*slice)[..].len() }
| ^^^^^^^^^^^^
|
= note: creating a reference requires the pointer target to be valid and imposes aliasing requirements
help: try using a raw pointer method instead; or if this reference is intentional, make it explicit
|
2 | unsafe { (&(*slice))[..].len() }
| ++ +
I the first warning is quite a duplicate of the second one, and its suggestion is also wrong, as (&(*slice)[..]).len()
would still trigger the warning.
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.