-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Unnecessary references lint #138230
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
Unnecessary references lint #138230
Conversation
r? @Noratrieb
rustbot has assigned @Noratrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r?
to explicitly pick a reviewer
These commits modify the Cargo.lock
file. Unintentional changes to Cargo.lock
can be introduced when switching branches and rebasing PRs.
If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint seems really specific to a single kind of expression, and there are plenty of other cases where unnecessary references are created when the user is trying to create a raw pointer. Unless this can be greatly generalized, it doesn't really seem worth adding this.
r? RalfJung
I agree, and my intention is to generalize this lint to cover all unnecessarily created references. Could you please list other cases that you think should be included? I can update this PR to cover them or create an issue to track these cases and mention that they should be added to the unnecessary_refs
lint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know little about lints' impls so r? compiler
Do we have some people who are our "linting experts"?
This lint seems really specific to a single kind of expression, and there are plenty of other cases where unnecessary references are created when the user is trying to create a raw pointer. Unless this can be greatly generalized, it doesn't really seem worth adding this.
Which examples did you have in mind?
A starting point might be to uplift https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr from cliippy to rustc, as you mention. It is not clear to me what the difference is between that lint and this one.
Do we have some people who are our "linting experts"?
cc @Urgau
Happy to take over the review. If @Nadrieril doesn't want to review it of course.
As for the lint it-self, I join @RalfJung that this is lint is currently clippy::borrow_as_ptr
, which will need to be dropped from clippy. Look at 1fee1a4 for the changes needed.
As a drive-by, rustc_hir_pretty
should not be necessary, a multi-part suggestion should be used instead, with some span manipulation to get the correct spans.
Much appreciated :) r? @Urgau
1e686f1
to
e113827
Compare
e113827
to
faf0620
Compare
This comment has been minimized.
This comment has been minimized.
faf0620
to
976c0a8
Compare
976c0a8
to
64132e5
Compare
This comment has been minimized.
This comment has been minimized.
I ran x test
on my machine, and everything passed. Why is it failing here, and how can I reproduce those errors locally?
64132e5
to
b0d836f
Compare
This comment has been minimized.
This comment has been minimized.
b0d836f
to
4acb822
Compare
4acb822
to
d6d72c8
Compare
The job x86_64-gnu-tools
failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] build_script_build test:false 0.334
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
88 | simd_ty!(u8x2[u8;2]: x0, x1);
| ---------------------------- in this macro invocation
|
= note: `-D unnecessary-refs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unnecessary_refs)]`
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
89 | simd_ty!(i8x2[i8;2]: x0, x1);
| ---------------------------- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
93 | simd_ty!(u8x4[u8;4]: x0, x1, x2, x3);
| ------------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
94 | simd_ty!(u16x2[u16;2]: x0, x1);
| ------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
96 | simd_ty!(i8x4[i8;4]: x0, x1, x2, x3);
| ------------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
97 | simd_ty!(i16x2[i16;2]: x0, x1);
| ------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
101 | / simd_ty!(
102 | | u8x8[u8;8]:
103 | | x0,
104 | | x1,
... |
110 | | x7
111 | | );
| |_- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
112 | simd_ty!(u16x4[u16;4]: x0, x1, x2, x3);
| -------------------------------------- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
113 | simd_ty!(u32x2[u32;2]: x0, x1);
| ------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
114 | simd_ty!(u64x1[u64;1]: x1);
| -------------------------- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
116 | / simd_ty!(
117 | | i8x8[i8;8]:
118 | | x0,
119 | | x1,
... |
125 | | x7
126 | | );
| |_- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
127 | simd_ty!(i16x4[i16;4]: x0, x1, x2, x3);
| -------------------------------------- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
128 | simd_ty!(i32x2[i32;2]: x0, x1);
| ------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
129 | simd_ty!(i64x1[i64;1]: x1);
| -------------------------- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
131 | simd_ty!(f32x2[f32;2]: x0, x1);
| ------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
132 | simd_ty!(f64x1[f64;1]: x1);
| -------------------------- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
136 | / simd_ty!(
137 | | u8x16[u8;16]:
138 | | x0,
139 | | x1,
... |
153 | | x15
154 | | );
| |_- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
155 | / simd_ty!(
156 | | u16x8[u16;8]:
157 | | x0,
158 | | x1,
... |
164 | | x7
165 | | );
| |_- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
166 | simd_ty!(u32x4[u32;4]: x0, x1, x2, x3);
| -------------------------------------- in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
...
167 | simd_ty!(u64x2[u64;2]: x0, x1);
| ------------------------------ in this macro invocation
|
help: consider using `&raw const` for a safer and more explicit raw pointer
|
44 - let self_ptr = &self as *const Self as *const $elem_type;
44 + let self_ptr = &raw const self as *const $elem_type;
|
error: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
--> library/core/src/../../stdarch/crates/core_arch/src/simd.rs:44:32
|
5 | / macro_rules! simd_ty {
6 | | ($id:ident [$elem_type:ty ; $len:literal]: $($param_name:ident),*) => {
7 | | #[repr(simd)]
8 | | #[derive(Copy, Clone, Debug, PartialEq)]
... |
44 | | let self_ptr = &self as *const Self as *const $elem_type;
| | ^^^^^^^^^^^^^^^^^^^^
... |
51 | | }
| |_- in this expansion of `simd_ty!`
☔ The latest upstream changes (presumably #139012) made this pull request unmergeable. Please resolve the merge conflicts.
My PR is currently blocked because the stdarch
bump is waiting on a bootstrap bump, see this.
Close #127724