-
Notifications
You must be signed in to change notification settings - Fork 13.5k
start properly testing attributes in positions #140948
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: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
r? jieyouxu |
Oh, this is great! I was just recently working on this, but happy to have someone actually make it happen. I look forward to this being accepted. Let me know if you want any help. I think there are a few tests that could eventually get deleted once everything gets covered. For example:
Some suggestions:
|
cc @jdonszelmann (as you may want to co-review) |
Yes, I'd like that. might take a little because of rust week @rustbot claim |
I think we also ought to test combinations of attributes. Such as #[ATTRIBUTE]
#[naked]
extern "C" fn naked(){} Are there more like that?
Just added another commit with these. I originally had them..not sure where they went... |
Just these couple of edits have already been quite annoying and error prone. Doing this for dozens of attributes is going to be untenable in the long run. This needs to be automatically generated, and I have some ideas about how to do that. |
Thoughts on testing attributes in positionsPreliminary: attributescf. the Reference on attributes. We have several kinds of attributes in terms of name resolution behavior (roughly):
Syntactically, attributes can also be categorized into:
Covering built-in attributes: caveats and challengesNow, I imagine the test coverage proposed in #140948 (this PR) is primarily about built-in attributes, like One of the places where "this (built-in) attribute can be applied to this position" is checked is the
where
|
though combinations of attributes are an important thing to test, it seems infeasible to do so. That starts to feel like fuzzing. I also feel like making such a file for every single attribute is a lot of work. Is there some way we could automate part of it? Now that we have a literal list of attribute parsers it might be feasible to effectively find them all and test for each of them that they're valid in all these positions automatically. Related to that, the way parsers are designed now, when two attributes care about each other's presence, they're supposed to list all the ones they care about in their accept function. It's entirely legal for multiple parsers to care about the same attribute symbols simply to reject the combination. That'd mean we also have a reasonable heuristic for which attributes to check together. Take a look at the stability parser which accepts both stable, unstable, and rustc_stable_through_unstable_modules in one parser. rust/compiler/rustc_attr_parsing/src/attributes/stability.rs Lines 46 to 65 in 573a015
I'll make a draft for a |
See the readme for the motivation. Just doing three attributes for now to get feedback on the overall implementation and direction.
Please let me know if there are additional positions that need testing!