-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
prettier error for parsed attrs on Target::Param
#150903
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
base: main
Are you sure you want to change the base?
prettier error for parsed attrs on Target::Param
#150903
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
8597baf to
4d39647
Compare
|
@jdonszelmann think it would be good if you did a quick look at this as well when you have time, just so you are up to date with the updates to |
| attrs = self.lower_attrs_with_extra( | ||
| hir_id, | ||
| param.attrs(), | ||
| param.span, | ||
| Target::Param, | ||
| attrs, | ||
| ); |
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.
unsure if this should actually be appending the param attrs here or not
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 think this should just be a lower_attrs call, the extra attributes from attrs are the attributes of the foreign fn, and the params should not inherit those.
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.
indeed
4d39647 to
34a3158
Compare
| attrs = self.lower_attrs_with_extra( | ||
| hir_id, | ||
| param.attrs(), | ||
| param.span, | ||
| Target::Param, | ||
| attrs, | ||
| ); |
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 think this should just be a lower_attrs call, the extra attributes from attrs are the attributes of the foreign fn, and the params should not inherit those.
|
Reminder, once the PR becomes ready for a review, use |
| // All attributes were previously erroring on Target::Param except a few that are allow-listed. | ||
| // Therefore, to avoid accidentally regressing from emitting error to emitting warn when parsing new attrs | ||
| // we have this check that always emits an error if Target::Param unless it's explicitly been allowed | ||
| if target == Target::Param || list.contains(&Policy::Error(target)) { |
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 don't like how special Target::Param is here.
There are other targets, such as Target::WherePredicate, that similarly were previously checked separately, and now have to be added to all attributes with AllowListWarnRest. We should have some way to ensure that these weird targets are not forgotten, but this doesn't feel right.
If we do this, we should at least rename AllowListWarnRest so the name is something like AllowListWarnMost, but even then this feels iffy to me.
@jdonszelmann what is your opinion?
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.
hm, we could:
- force people to list exhaustively (infeasible)
- write a rustc lint (could be neat)
- have some special sets that allow most (like you suggest, seems reasonable)
I've never written a rustc lint before, but I've seen them around. Could be worth considering.
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.
@Bryntet
What Jana meant is defining a full-on lint pass in rustc_lint/src/internal.rs, that checks for misuse of these allowed target lists. This is a possible solution but I feel like it's too overkill for this relatively simple problem.
I don't like this approach to "linting" because it has runtime overhead.
I'd personally prefer to go for the "special sets" approach
this improvement is only relevant for parsed attrs that use `AllowedTargets::AllowListWarnRest`
34a3158 to
7cbb620
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. |
7cbb620 to
7d4a0f5
Compare
|
i tried the approach of linting inside of rustc instead unsure if this is the proper way of making a rustc lint though? |
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #151051) made this pull request unmergeable. Please resolve the merge conflicts. |
Couple things to note:
This change includes making all so-far parsed attrs emit an error if they are targeting Param (by adding
Error(Target::Param))^ The above is not a breaking change, because there was previously a step that emitted an error pre-attr parsing, for all attrs that were not in the list
[allow, cfg_trace, cfg_attr_trace, deny, expect, forbid, warn]The check mentioned above has been disabled for all parsed attrs, meaning we in practice have replaced the error lint above, with the nicer lint from the attribute parser
I also removed
Allow(Target::Param)from theALL_TARGETSconst, since all attrs with the exception ofallow, cfg_trace, cfg_attr_trace, deny, expect, forbid, warnhad this emitting error previously anywaysThe latter two commits I would want someone to verify closely that I have not made some mistake/broken something with! I think they're good, but I still feel like I don't know exactly enough about the compiler to say that they are 100% OK
This also fixes this part of #147417
r? @JonathanBrouwer