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
Collaborator
| | AttributeKind::MacroTransparency { .. } | ||
| | AttributeKind::Repr { .. } | ||
| | AttributeKind::Stability { .. }, | ||
| ) => AttrStyle::Outer, |
Contributor
There was a problem hiding this comment.
I expect to, within a few weeks or so, convert all attributes to be parsed. As such, I'm not sure the changes in this pr are very useful as this function will likely be deleted soon since it would effectively always return Outer. Only tool attributes might retain the ability to have an AttrStyle, though I think it'd be acceptable to always print those as outer too.
Member
Author
|
Closing in favor of #142776. |
jdonszelmann
added a commit
to jdonszelmann/rust
that referenced
this pull request
Jun 21, 2025
All HIR attributes are outer Fixes rust-lang#142649. Closes rust-lang#142759. All HIR attributes, including parsed and not yet parsed, will now be rendered as outer attributes by `rustc_hir_pretty`. The original style of the corresponding AST attribute(s) is not relevant for pretty printing, only for diagnostics. r? `@jdonszelmann`
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Jun 22, 2025
All HIR attributes are outer Fixes rust-lang#142649. Closes rust-lang#142759. All HIR attributes, including parsed and not yet parsed, will now be rendered as outer attributes by `rustc_hir_pretty`. The original style of the corresponding AST attribute(s) is not relevant for pretty printing, only for diagnostics. r? ``@jdonszelmann``
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Jun 22, 2025
All HIR attributes are outer Fixes rust-lang#142649. Closes rust-lang#142759. All HIR attributes, including parsed and not yet parsed, will now be rendered as outer attributes by `rustc_hir_pretty`. The original style of the corresponding AST attribute(s) is not relevant for pretty printing, only for diagnostics. r? ```@jdonszelmann```
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Jun 22, 2025
All HIR attributes are outer Fixes rust-lang#142649. Closes rust-lang#142759. All HIR attributes, including parsed and not yet parsed, will now be rendered as outer attributes by `rustc_hir_pretty`. The original style of the corresponding AST attribute(s) is not relevant for pretty printing, only for diagnostics. r? ````@jdonszelmann````
rust-timer
added a commit
that referenced
this pull request
Jun 22, 2025
Rollup merge of #142776 - dtolnay:hirattrstyle2, r=jdonszelmann All HIR attributes are outer Fixes #142649. Closes #142759. All HIR attributes, including parsed and not yet parsed, will now be rendered as outer attributes by `rustc_hir_pretty`. The original style of the corresponding AST attribute(s) is not relevant for pretty printing, only for diagnostics. r? ````@jdonszelmann````
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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