-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add new lint: ref_as_ptr
#12087
Add new lint: ref_as_ptr
#12087
Conversation
r? @xFrednet (rustbot has picked a reviewer for you, use r? to override) |
In my opinion |
Could not assign reviewer from: |
?? I'll check |
Yeah IDK, was weird, does this work? r? @xFrednet |
😂 r? @blyxyas |
Could not assign reviewer from: |
Lol, maybe it hasn't reloaded the configuration yet? |
Philipp reverted my change unassigning me as on-vacation. (on a subtree sync, idk why or how) |
Hmmm... How is this different from |
The |
Hmmm 🤔 I'm not really seeing the benefits of |
They are useful in slightly different situations, specifically |
Okis, so the conclusions from our improvised meeting is that both lints can coexist. I'm still not to fond of this (e.g. what if someone used Meow meow, sorry for the long delay 🙏, I'll review it (at least start to do it) today |
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.
Very good first iteration! Following Philipp's suggestion, and because I think that this new lint is more useful than borrow_as_ptr
(but they lint in identical situations), could you move that lint into restriction
?
I don't remember if there's a formal process to move a lint's category (⁎˃ᆺ˂), but I've asked about it. If there isn't a necessary process we didn't do, I'll merge this.
I've changed the category of |
Hmmm... you're right. We'll try with the second solution. This way, both lints can be suspicious, and we don't have to prioritize one over the other. |
I've moved the |
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.
Just a little bit of polish. After this little change, could you squash the commits?
clippy_lints/src/casts/ref_as_ptr.rs
Outdated
cx, | ||
REF_AS_PTR, | ||
expr.span, | ||
"ref as raw pointer", |
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.
"ref as raw pointer", | |
"reference as raw pointer", |
e418020
to
73f3fce
Compare
@bors r+ |
Add new lint: `ref_as_ptr` Fixes #10130 Added new lint `ref_as_ptr` that checks for conversions from references to pointers and suggests using `std::ptr::from_{ref, mut}` instead. The name is different than suggested in the issue (`as_ptr_cast`) since there were some other lints with similar names (`ptr_as_ptr`, `borrow_as_ptr`) and I wanted to follow the convention. Note that this lint conflicts with the `borrow_as_ptr` lint in the sense that it recommends changing `&foo as *const _` to `std::ptr::from_ref(&foo)` instead of `std::ptr::addr_of!(foo)`. Personally, I think the former is more readable and, in contrast to `addr_of` macro, can be also applied to temporaries (cf. #9884). --- changelog: New lint: [`ref_as_ptr`] [#12087](#12087)
💔 Test failed - checks-action_test |
Author: Marcin Serwin <[email protected]>
73f3fce
to
a3baebc
Compare
@bors r+ |
Add new lint: `ref_as_ptr` Fixes #10130 Added new lint `ref_as_ptr` that checks for conversions from references to pointers and suggests using `std::ptr::from_{ref, mut}` instead. The name is different than suggested in the issue (`as_ptr_cast`) since there were some other lints with similar names (`ptr_as_ptr`, `borrow_as_ptr`) and I wanted to follow the convention. Note that this lint conflicts with the `borrow_as_ptr` lint in the sense that it recommends changing `&foo as *const _` to `std::ptr::from_ref(&foo)` instead of `std::ptr::addr_of!(foo)`. Personally, I think the former is more readable and, in contrast to `addr_of` macro, can be also applied to temporaries (cf. #9884). --- changelog: New lint: [`ref_as_ptr`] [#12087](#12087)
💔 Test failed - checks-action_test |
@bors retry |
Add new lint: `ref_as_ptr` Fixes #10130 Added new lint `ref_as_ptr` that checks for conversions from references to pointers and suggests using `std::ptr::from_{ref, mut}` instead. The name is different than suggested in the issue (`as_ptr_cast`) since there were some other lints with similar names (`ptr_as_ptr`, `borrow_as_ptr`) and I wanted to follow the convention. Note that this lint conflicts with the `borrow_as_ptr` lint in the sense that it recommends changing `&foo as *const _` to `std::ptr::from_ref(&foo)` instead of `std::ptr::addr_of!(foo)`. Personally, I think the former is more readable and, in contrast to `addr_of` macro, can be also applied to temporaries (cf. #9884). --- changelog: New lint: [`ref_as_ptr`] [#12087](#12087)
💔 Test failed - checks-action_test |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #10130
Added new lint
ref_as_ptr
that checks for conversions from references to pointers and suggests usingstd::ptr::from_{ref, mut}
instead.The name is different than suggested in the issue (
as_ptr_cast
) since there were some other lints with similar names (ptr_as_ptr
,borrow_as_ptr
) and I wanted to follow the convention.Note that this lint conflicts with the
borrow_as_ptr
lint in the sense that it recommends changing&foo as *const _
tostd::ptr::from_ref(&foo)
instead ofstd::ptr::addr_of!(foo)
. Personally, I think the former is more readable and, in contrast toaddr_of
macro, can be also applied to temporaries (cf. #9884).changelog: New lint: [
ref_as_ptr
]#12087