-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Improve -Zunpretty=hir
for parsed attrs
#138063
base: master
Are you sure you want to change the base?
Improve -Zunpretty=hir
for parsed attrs
#138063
Conversation
750e283
to
914ad9e
Compare
Some changes occurred in compiler/rustc_attr_data_structures |
@bors delegate=jdonszelmann |
✌️ @jdonszelmann, you can now approve this pull request! If @compiler-errors told you to " |
@@ -5,17 +5,21 @@ extern crate std; | |||
//@ compile-flags: -Zunpretty=hir | |||
//@ check-pass | |||
|
|||
#[deprecated] | |||
#[attr = Deprecation {deprecation: Deprecation {since: Unspecified}}] |
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.
some of the spacing is a bit tighter than i'd like, but the pp_hir machinery is annoying lol
hir::Attribute::Parsed(pa) => { | ||
self.word("#[attr=\""); | ||
self.word("#[attr = "); |
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.
this isn't grammatical (#[attr = {}]
) but renders better than a string :)
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 do prefer it though, so nice change :)
if parens { | ||
p.word("("); | ||
} | ||
|
||
let mut printed_anything = $t.print_something(); | ||
let mut printed_anything = $t.should_render(); |
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.
is printed_anything doing anything here? I may have misremembered my own code but can't find a usage atm
|
||
$t.print_attribute(p); | ||
|
||
$( | ||
if printed_anything && $ts.print_something() { | ||
if $ts.should_render() { |
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.
the check isn't here anymore, which could be correct
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 yes, that is necessary, but we need to push the if printed_anything
into the block like the other fixes.
@@ -126,7 +126,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(); |
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
hir::Attribute::Parsed(pa) => { | ||
self.word("#[attr=\""); | ||
self.word("#[attr = "); |
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 do prefer it though, so nice change :)
@@ -35,6 +37,7 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok | |||
return; | |||
} | |||
|
|||
__p.nbsp(); | |||
__p.word("{"); |
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 guess we could add some spaces (when #disps.len() > 0) here at the braces to make things slightly less tight?
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.
It may lead to other spacing awkwardness, so let's keep it as is.
☔ The latest upstream changes (presumably #138155) made this pull request unmergeable. Please resolve the merge conflicts. |
914ad9e
to
9ae9453
Compare
I see ya did the spaces change anyway, nice! Looks like that addresses everything @bors r+ |
@bors rollup since this does not really affect stable code |
…tty, r=jdonszelmann Improve `-Zunpretty=hir` for parsed attrs 0. Rename `print_something` to `should_render` to make it distinct from `print_attribute` in that it doesn't print anything, it's just a way to probe if a type renders anything. 1. Fixes a few bugs in the `PrintAttribute` derive. Namely, the `__printed_anything` variable was entangled with the `should_render` call, leading us to always render field names but never render commas. 2. Remove the outermost `""` from the attr. 3. Debug print `Symbol`s. I know that this is redundant for some parsed attributes, but there's no good way to distinguish symbols that are ident-like and symbols which are cooked string literals. We could perhaps *conditionally* to fall back to a debug printing if the symbol doesn't match an ident? But seems like overkill. Based on rust-lang#138060, only review the commits not in that one.
…mpiler-errors Rollup of 10 pull requests Successful merges: - rust-lang#135651 (Support for `wasm32-wali-linux-musl` Tier-3 target) - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package) - rust-lang#137337 (Add verbatim linker to AIXLinker) - rust-lang#137549 (Clean up various LLVM FFI things in codegen_llvm) - rust-lang#137957 (Remove i586-pc-windows-msvc) - rust-lang#138063 (Improve `-Zunpretty=hir` for parsed attrs) - rust-lang#138137 (setTargetTriple now accepts Triple rather than string) - rust-lang#138141 (tests: fix some typos in comment) - rust-lang#138150 (Streamline HIR intravisit `visit_id` calls for items) - rust-lang#138173 (Delay bug for negative auto trait rather than ICEing) r? `@ghost` `@rustbot` modify labels: rollup
…tty, r=jdonszelmann Improve `-Zunpretty=hir` for parsed attrs 0. Rename `print_something` to `should_render` to make it distinct from `print_attribute` in that it doesn't print anything, it's just a way to probe if a type renders anything. 1. Fixes a few bugs in the `PrintAttribute` derive. Namely, the `__printed_anything` variable was entangled with the `should_render` call, leading us to always render field names but never render commas. 2. Remove the outermost `""` from the attr. 3. Debug print `Symbol`s. I know that this is redundant for some parsed attributes, but there's no good way to distinguish symbols that are ident-like and symbols which are cooked string literals. We could perhaps *conditionally* to fall back to a debug printing if the symbol doesn't match an ident? But seems like overkill. Based on rust-lang#138060, only review the commits not in that one.
…mpiler-errors Rollup of 8 pull requests Successful merges: - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package) - rust-lang#137337 (Add verbatim linker to AIXLinker) - rust-lang#137363 (compiler: factor Windows x86-32 ABI impl into its own file) - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux) - rust-lang#138000 (atomic: clarify that failing conditional RMW operations are not 'writes') - rust-lang#138063 (Improve `-Zunpretty=hir` for parsed attrs) - rust-lang#138137 (setTargetTriple now accepts Triple rather than string) - rust-lang#138173 (Delay bug for negative auto trait rather than ICEing) r? `@ghost` `@rustbot` modify labels: rollup
@bors r- |
fix hir pretty printing
what is a PR but a series of patches anyway. can't push, can comment 🤷 |
9ae9453
to
9c7821b
Compare
@bors r=jdonszelmann |
@bors r- |
9c7821b
to
382b76d
Compare
Some changes occurred in tests/rustdoc-json |
@bors r=jdonszelmann |
print_something
toshould_render
to make it distinct fromprint_attribute
in that it doesn't print anything, it's just a way to probe if a type renders anything.PrintAttribute
derive. Namely, the__printed_anything
variable was entangled with theshould_render
call, leading us to always render field names but never render commas.""
from the attr.Symbol
s. I know that this is redundant for some parsed attributes, but there's no good way to distinguish symbols that are ident-like and symbols which are cooked string literals. We could perhaps conditionally to fall back to a debug printing if the symbol doesn't match an ident? But seems like overkill.Based on #138060, only review the commits not in that one.