Skip to content
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

Give types to some bool function arguments in pretty printer #92243

Closed
wants to merge 1 commit into from

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Dec 24, 2021

I found that the pervasive use of random anonymous bools in the pretty printer made code changes hard to review. Like in the following, it's easy for a reviewer to be inclined to just assume that false and true are correct without tracking down the signature to find out what they mean.

MacArgs::Delimited(_, delim, tokens) => self.print_mac_common(
Some(MacHeader::Path(&item.path)),
false,
None,
delim.to_token(),
tokens,
true,
span,
),

This PR replaces all the bool in function signatures in the pretty printer with appropriately named newtype wrappers around bool.

Illustrative example from the code that deals with printing &T / &mut T / &raw const T / &raw mut T:

Before

self.word("&");
match kind {
ast::BorrowKind::Ref => self.print_mutability(mutability, false),
ast::BorrowKind::Raw => {
self.word_nbsp("raw");
self.print_mutability(mutability, true);
}
}

After

https://github.com/rust-lang/rust/blob/fa65008f2fa822c100c10d73ba220f4e4e5352f3/compiler/rustc_ast_pretty/src/pprust/state.rs#L2005-L2012

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 24, 2021
@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2021
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 29, 2021

☔ The latest upstream changes (presumably #92397) made this pull request unmergeable. Please resolve the merge conflicts.

@dtolnay
Copy link
Member Author

dtolnay commented Dec 29, 2021

@bors
Copy link
Contributor

bors commented Jan 8, 2022

☔ The latest upstream changes (presumably #92664) made this pull request unmergeable. Please resolve the merge conflicts.

@dtolnay
Copy link
Member Author

dtolnay commented Jan 15, 2022

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.debug-assertions := True
configure: rust.overflow-checks := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
* highest error code: E0786
Found 502 error codes
Found 0 error codes with no tests
Done!
tidy error: /checkout/compiler/rustc_ast_pretty/src/pprust/state.rs: too many lines (3006) (add `// ignore-tidy-filelength` to the file to suppress this error)
some tidy checks failed



command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/rust-tidy" "/checkout" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build" "16"


Build completed unsuccessfully in 0:00:12

@dtolnay
Copy link
Member Author

dtolnay commented Jan 15, 2022

Blocked by compiler/rustc_ast_pretty/src/pprust/state.rs being over the 3000 lines tidy limit. I put up #92920 to break it up.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 15, 2022
Move expr- and item-related pretty printing functions to modules

Currently *compiler/rustc_ast_pretty/src/pprust/state.rs* is 2976 lines on master. The `tidy` limit is 3000, which is blocking rust-lang#92243.

This PR adds a `mod expr;` and `mod item;` to move logic related to those AST nodes out of the single huge file.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 19, 2022
Move expr- and item-related pretty printing functions to modules

Currently *compiler/rustc_ast_pretty/src/pprust/state.rs* is 2976 lines on master. The `tidy` limit is 3000, which is blocking rust-lang#92243.

This PR adds a `mod expr;` and `mod item;` to move logic related to those AST nodes out of the single huge file.
@bors
Copy link
Contributor

bors commented Jan 19, 2022

☔ The latest upstream changes (presumably #93069) made this pull request unmergeable. Please resolve the merge conflicts.

@dtolnay dtolnay closed this Jan 19, 2022
@dtolnay dtolnay deleted the booltype branch January 19, 2022 19:54
@dtolnay dtolnay added the A-pretty Area: Pretty printing (including `-Z unpretty`) label Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants