rustc_marker_type built in attribute created to have certain marker types not trigger dead code warnings from clippy#154978
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
|
r? @davidtwco rustbot has assigned @davidtwco. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
218306c to
2206c25
Compare
260b712 to
55627ab
Compare
This comment has been minimized.
This comment has been minimized.
55627ab to
7b574a6
Compare
This comment has been minimized.
This comment has been minimized.
7b574a6 to
60f81d1
Compare
This comment has been minimized.
This comment has been minimized.
60f81d1 to
c29ad8c
Compare
| use std::marker::PhantomData; | ||
|
|
||
| pub mod inner { | ||
| use std::marker; |
There was a problem hiding this comment.
For some reason, it kept telling me that it couldn't find std::marker crate, so I couldn't shortcut the field types to marker::PhantomPinned/marker::PhantomData<T>.
I'm not sure how this test operated prior to this, or if I screwed up something to cause this issue.
| } | ||
|
|
||
| /// Checks whether a given result of a name resolution are marked as `#[rustc_marker_type]` | ||
| pub fn has_rustc_marker_type_attr(tcx: TyCtxt<'_>, res: &Res) -> bool { |
There was a problem hiding this comment.
After hours of exploring how attributes works in the compiler, I figured out that the DefId that I could get from a field type's basic result (if it doesn't Err) could inform me about whether that field type has a specific attribute associated with it. If there's a better way to do this than the way I'm doing it, I'm all ears; I'm not even sure if this is the idiomatic way of getting an attribute from a specific type.
| RustcMain, | ||
|
|
||
| /// Represents `#[rustc_marker_type]` | ||
| RustcMarkerType(Symbol, Span), |
There was a problem hiding this comment.
I'm not sure if this is correct. I took inspiration from other enum members written like this (like Lang or RustcAsPtr). I do know that it operates with attribute parsing from lint_helpers.rs and I assume that lets us know what symbol name represents this AttributeKind, whether duplicate of the attribute applied to a certain target produces a compiler error, what target is this attribute limited to. I'm unsure what create does specifically. My hunch tells me that it's related to whether the attribute macro takes an argument or not, but unsure; if that's the case, I might just not need any arguments as part of this enum member.
| } | ||
|
|
||
| pub(crate) struct RustcMarkerTypeParser; | ||
| impl<S: Stage> NoArgsAttributeParser<S> for RustcMarkerTypeParser { |
There was a problem hiding this comment.
Let me know if this is the correct place to place this sort of attribute. I assumed that because rustc_marker_type helped clippy with dead field warnings, it should be part of lint_helpers.rs
| ), | ||
| rustc_attr!(rustc_force_inline,"`#[rustc_force_inline]` forces a free function to be inlined"), | ||
| rustc_attr!(rustc_scalable_vector,"`#[rustc_scalable_vector]` defines a scalable vector type"), | ||
| rustc_attr!( rustc_marker_type, "the `#[rustc_marker_type]` attribute is used by the standard library to mark certain marker types \ |
There was a problem hiding this comment.
Also, let me know if this is the correct spot to put the rustc_attr! for rustc_marker_type. It's in miscellaneous right now.
This comment has been minimized.
This comment has been minimized.
c29ad8c to
36cbcae
Compare
|
Some changes occurred in compiler/rustc_attr_parsing |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ypes not trigger dead code warnings from clippy
36cbcae to
9f0d57d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This PR fixes the issue on
PhantomPinnedtriggering field is never read warning by clippy through a built in attribute calledrustc_marker_type.A few questions I have are:
Phantom*types?Note: This is my first time contributing to the compiler side of Rust repos, so I'm unsure if I'm doing anything wrong with making a built in attribute. I'm just going based off my intuition from go to references in my IDE on what everything is doing.
cc @clarfonthey