-
Notifications
You must be signed in to change notification settings - Fork 1.7k
unsafe_derive_deserialize
: do not consider pin!()
as unsafe
#15137
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
Conversation
This will be replaced by a diagnostic item check once rust-lang/rust#143015 is merged and synced. |
Hmm, isn't this also a general issue with any macro containing unsafe being expanded there, not just |
clippy_lints/src/derive.rs
Outdated
.source_callee() | ||
.and_then(|expr| expr.macro_def_id) | ||
.is_none_or(|did| { | ||
(self.cx.tcx.crate_name(did.krate), self.cx.tcx.item_name(did)) != (sym::core, sym::pin) | ||
}) |
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 seems oddly specific to pin!
; what about something more general such as:
.source_callee() | |
.and_then(|expr| expr.macro_def_id) | |
.is_none_or(|did| { | |
(self.cx.tcx.crate_name(did.krate), self.cx.tcx.item_name(did)) != (sym::core, sym::pin) | |
}) | |
.from_expansion() | |
.not() |
- or, if using a
LatePass
, https://doc.rust-lang.org/1.87.0/nightly-rustc/rustc_span/struct.Span.html#method.in_external_macro seems idoneous.
As I understand it, the reasoning behind this lint is that as soon as you have unsafe code in your methods, you may be counting on having total control over the content of your structure, which may no longer be true if it is built through deserialization. However, the fact that I am not a user of this lint, so I have a hard time judging whether someone would want to be warned if an external macro they use start doing unsafe things behind the scene. |
Yeah, it is a fair stance; probably what the original authors had in mind, back in the day when the notion around who is responsible for an It should rather be about "precondition-assuming
Now enter macros. We don't have But the convention is the following:
With all that in context / having been said, I do believe it makes sense to ignore any
|
I agree to all that, but this is a larger change which affects the semantics of the lint. We might choose to do that, and that will fix the Btw, even in the standard library, |
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.
Yeah, fair. I'm fine with merging this as is, seeing how it's maybe not entirely uncontroversial to ignore all macros. We can always make this more general later separately, but this should at least fix the "regression" in this particular case with pin. So, r=me
c2c59a9
to
2e02468
Compare
In Rust 1.88, the `pin!()` macro uses `unsafe` and triggers `unsafe_derive_deserialize`.
2e02468
to
b49e360
Compare
In Rust 1.88, the
pin!()
macro usesunsafe
and triggersunsafe_derive_deserialize
.Fixes #15120
changelog: [
unsafe_derive_deserialize
]: do not trigger because of the standard library'spin!()
macro