-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Improve -Zunpretty=hir for parsed attrs
#138063
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,7 @@ macro_rules! print_tup { | |
| let ($t, $($ts),*) = self; | ||
| let parens = print_tup!(num_should_render $t $($ts)*) > 1; | ||
| if parens { | ||
| p.word("("); | ||
| p.popen(); | ||
| } | ||
|
|
||
| let mut printed_anything = $t.should_render(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is printed_anything doing anything here? I may have misremembered my own code but can't find a usage atm |
||
|
|
@@ -134,14 +134,16 @@ macro_rules! print_tup { | |
|
|
||
| $( | ||
| if $ts.should_render() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the check isn't here anymore, which could be correct
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yes, that is necessary, but we need to push the |
||
| p.word_space(","); | ||
| if printed_anything { | ||
| p.word_space(","); | ||
| } | ||
| printed_anything = true; | ||
| } | ||
| $ts.print_attribute(p); | ||
| )* | ||
|
|
||
| if parens { | ||
| p.word(")"); | ||
| p.pclose(); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -152,8 +154,8 @@ macro_rules! print_tup { | |
|
|
||
| print_tup!(A B C D E F G H); | ||
| print_skip!(Span, ()); | ||
| print_disp!(Symbol, u16, bool, NonZero<u32>); | ||
| print_debug!(UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency); | ||
| print_disp!(u16, bool, NonZero<u32>); | ||
| print_debug!(Symbol, UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency); | ||
|
|
||
| /// Finds attributes in sequences of attributes by pattern matching. | ||
| /// | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,9 +117,9 @@ impl<'a> State<'a> { | |
| self.hardbreak() | ||
| } | ||
| hir::Attribute::Parsed(pa) => { | ||
| self.word("#[attr=\""); | ||
| self.word("#[attr = "); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't grammatical (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do prefer it though, so nice change :) |
||
| pa.print_attribute(self); | ||
| self.word("\")]"); | ||
| self.word("]"); | ||
| self.hardbreak() | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,14 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok | |
| let name = field.ident.as_ref().unwrap(); | ||
| let string_name = name.to_string(); | ||
| disps.push(quote! { | ||
| if __printed_anything && #name.should_render() { | ||
| __p.word_space(","); | ||
| if #name.should_render() { | ||
| if __printed_anything { | ||
| __p.word_space(","); | ||
| } | ||
| __p.word(#string_name); | ||
| __p.word_space(":"); | ||
| __printed_anything = true; | ||
| } | ||
| __p.word(#string_name); | ||
| __p.word_space(":"); | ||
| #name.print_attribute(__p); | ||
| }); | ||
| field_names.push(name); | ||
|
|
@@ -35,6 +37,7 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok | |
| return; | ||
| } | ||
|
|
||
| __p.nbsp(); | ||
| __p.word("{"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we could add some spaces (when #disps.len() > 0) here at the braces to make things slightly less tight?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may lead to other spacing awkwardness, so let's keep it as is. |
||
| #(#disps)* | ||
| __p.word("}"); | ||
|
|
@@ -48,8 +51,10 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok | |
| for idx in 0..fields_unnamed.unnamed.len() { | ||
| let name = format_ident!("f{idx}"); | ||
| disps.push(quote! { | ||
| if __printed_anything && #name.should_render() { | ||
| __p.word_space(","); | ||
| if #name.should_render() { | ||
| if __printed_anything { | ||
| __p.word_space(","); | ||
| } | ||
| __printed_anything = true; | ||
| } | ||
| #name.print_attribute(__p); | ||
|
|
@@ -66,9 +71,9 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok | |
| return; | ||
| } | ||
|
|
||
| __p.word("("); | ||
| __p.popen(); | ||
| #(#disps)* | ||
| __p.word(")"); | ||
| __p.pclose(); | ||
| }, | ||
| quote! { true }, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,24 +5,21 @@ extern crate std; | |
| //@ compile-flags: -Zunpretty=hir | ||
| //@ check-pass | ||
|
|
||
| // FIXME(jdonszelmann): the pretty printing output for deprecated (and possibly more attrs) is | ||
| // slightly broken. | ||
| #[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote: | ||
| suggestion: }span: }")] | ||
| #[attr = Deprecation {deprecation: Deprecation {since: Unspecified}}] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some of the spacing is a bit tighter than i'd like, but the pp_hir machinery is annoying lol |
||
| struct PlainDeprecated; | ||
|
|
||
| #[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote: | ||
| here's why this is deprecatedsuggestion: }span: }")] | ||
| #[attr = Deprecation {deprecation: Deprecation {since: Unspecified, note: | ||
| "here's why this is deprecated"}}] | ||
| struct DirectNote; | ||
|
|
||
| #[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote: | ||
| here's why this is deprecatedsuggestion: }span: }")] | ||
| #[attr = Deprecation {deprecation: Deprecation {since: Unspecified, note: | ||
| "here's why this is deprecated"}}] | ||
| struct ExplicitNote; | ||
|
|
||
| #[attr="Deprecation{deprecation: Deprecation{since: NonStandard(1.2.3)note: | ||
| here's why this is deprecatedsuggestion: }span: }")] | ||
| #[attr = Deprecation {deprecation: Deprecation {since: NonStandard("1.2.3"), | ||
| note: "here's why this is deprecated"}}] | ||
| struct SinceAndNote; | ||
|
|
||
| #[attr="Deprecation{deprecation: Deprecation{since: NonStandard(1.2.3)note: | ||
| here's why this is deprecatedsuggestion: }span: }")] | ||
| #[attr = Deprecation {deprecation: Deprecation {since: NonStandard("1.2.3"), | ||
| note: "here's why this is deprecated"}}] | ||
| struct FlippedOrder; | ||
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.
oh didn't know these existed, neat :3