Assign an AttrStyle to all HIR attributes#142759
Closed
dtolnay wants to merge 2 commits intorust-lang:masterfrom
Closed
Assign an AttrStyle to all HIR attributes#142759dtolnay wants to merge 2 commits intorust-lang:masterfrom
dtolnay wants to merge 2 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #142649.
Prior to #135726, all
hir::Attributeused to have a "style" (eitherAttrStyle::OuterorAttrStyle::Inner, for #[…] and #![…] respectively). After that refactor,hir::Attribute'sfn style(&self) -> AttrStylebegan to panic if called on certain builtin attributes like#[deprecated].I looked into changing this method to
fn style(&self) -> Option<AttrStyle>where builtin attributes would not have a style. But ultimately the HIR pretty-printer needs to print all these attributes, and needs to print them in either outer or inner position, so at least every attribute included in-Zunpretty=hirdefinitely needs a style, including builtin attributes.I looked into storing every attribute's original
AttrStylein eitherrustc_attr_data_structures::AttributeKindorhir::Attribute. This does not make sense because there is a many-to-one correspondence between AST attributes and HIR attributes. Two different AST attributes with different style can get parsed into the same single HIR attribute. I have added an example of this in a comment.Since the HIR pretty-printer chooses to print all of these builtin attributes as outer attributes, and we need to be able to know the style of every expression-level attribute in order to correctly handle expression precedence during pretty-printing and diagnostics, in this PR I have made
hir::Attribute::stylereturnAttrStyle::Outerinstead of panicking for builtin attributes.This solution fixes several
rustc_hir_prettybugs associated with not being able to know the style of HIR attributes. For example, some attributes used to get duplicated as both outer and inner when printed, as you can see in the tests.@jdonszelmann @fmease