-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Assign an AttrStyle to all HIR attributes #142759
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
Conversation
| AttributeKind::MacroTransparency { .. } | ||
| AttributeKind::Repr { .. } | ||
| AttributeKind::Stability { .. }, | ||
) => AttrStyle::Outer, |
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 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.
Closing in favor of #142776. |
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`
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``
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```
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````
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````
Fixes #142649.
Prior to #135726, all
hir::Attribute
used to have a "style" (eitherAttrStyle::Outer
orAttrStyle::Inner
, for #[…] and #![…] respectively). After that refactor,hir::Attribute
'sfn style(&self) -> AttrStyle
began 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=hir
definitely needs a style, including builtin attributes.I looked into storing every attribute's original
AttrStyle
in eitherrustc_attr_data_structures::AttributeKind
orhir::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::style
returnAttrStyle::Outer
instead of panicking for builtin attributes.This solution fixes several
rustc_hir_pretty
bugs 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