Move #[naked] attribute check to attribute parsing stage - #162530
RichardTjokroutomo wants to merge 5 commits into
Conversation
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
|
Thanks for the pull request, and welcome! The Rust Project has assigned @nnethercote (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
57ae8f4 to
c65aa6f
Compare
This comment has been minimized.
This comment has been minimized.
c65aa6f to
4c2e629
Compare
This comment has been minimized.
This comment has been minimized.
4c2e629 to
ee7a87a
Compare
ee7a87a to
9d144c2
Compare
This comment has been minimized.
This comment has been minimized.
| }; | ||
|
|
||
| let ItemKind::Fn(fn_item) = &item.kind else { | ||
| return; |
There was a problem hiding this comment.
This should never fail right? So please make this panic
There was a problem hiding this comment.
After implementing panic, through the failing CI I just found out that methods defined under traits & impls are represented as associated item instead of normal item.... lucky...
| MethodKind::Trait { body: true } | MethodKind::TraitImpl | MethodKind::Inherent, | ||
| ) => { | ||
| let Some(item) = cx.target_item else { | ||
| return; |
There was a problem hiding this comment.
same with this
| /// - support unwinding with `-Cpanic=unwind`, unlike `extern "C"` | ||
| /// - often diverge from the C ABI | ||
| /// - are subject to change between compiler versions | ||
| pub fn is_rustic_abi(self) -> bool { |
There was a problem hiding this comment.
Can we avoid duplicating this logic?
Perhaps by parsing the abi into a ExternAbi instead?
There was a problem hiding this comment.
I don't think we can. I originally tried to convert it to ExternAbi, but I couldn't compile as it creates circular dependency (haven't checked deeper as to why, though).
Then I saw similar check for CanonAbi, and I thought since the logic is already duplicated elsewhere, perhaps I can also add similar method to Extern.
There was a problem hiding this comment.
I'll doubly insist that this logic should not be duplicated.
There was a problem hiding this comment.
OK; I added a helper method to convert extern to externAbi
|
Reminder, once the PR becomes ready for a review, use |
9d144c2 to
7e93b9a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7e93b9a to
cdc980c
Compare
This comment has been minimized.
This comment has been minimized.
cdc980c to
4fbadae
Compare
|
Some changes occurred in compiler/rustc_attr_ir |
This comment has been minimized.
This comment has been minimized.
8698b20 to
8969f45
Compare
This comment has been minimized.
This comment has been minimized.
8969f45 to
1486a1f
Compare
This comment has been minimized.
This comment has been minimized.
1486a1f to
2891b61
Compare
|
@rustbot ready |
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
This comment has been minimized.
This comment has been minimized.
fd6559e to
d041737
Compare
This comment has been minimized.
This comment has been minimized.
d041737 to
7d02364
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
7d02364 to
05aa3f9
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 comment has been minimized.
This comment has been minimized.
…functions calling lower_attrs() Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
05aa3f9 to
2e27ca7
Compare
View all comments
Following #161482's idea to add
target_itemfield toFinalizeCheckContext, replacetarget_itemwithast_target, which is anenumthat contains all possible types of target Item (obtained by grepping all functions that calllower_attrs()).This change is needed as methods defined under
traits &impls are represented asast::AssocItem. Lastly, movecheck_nakedto the callback returned byNakedParser::deferred_finalize_check().Part of #153101. r?@JonathanBrouwer
LLM disclosure: I wrote the code by hand & took inspiration from #161482. However, I did use LLM to learn how attribute checking is done in Rustc.