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

Don't print newlines in APITs #111929

Merged
merged 1 commit into from
May 26, 2023
Merged

Conversation

compiler-errors
Copy link
Member

This is kind of a hack, but it gets the job done because the only "special" formatting that (afaict) rustc_ast_pretty does is break with newlines sometimes.

Fixes rust-lang/measureme#207

@rustbot
Copy link
Collaborator

rustbot commented May 25, 2023

r? @wesleywiser

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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. labels May 25, 2023
compiler/rustc_ast_lowering/src/lib.rs Outdated Show resolved Hide resolved
// HACK: pprust breaks strigns with newlines when the type
// gets too long. We don't want these to show up in compiler
// output or built artifacts, so replace them here...
// Perhaps we should instead format APITs more robustly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this in pprust instead? I don't know why we'd want it to add the newline ... if it's just for -Zunpretty=expanded that doesn't seem worth adding hacks for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This newline is not impl Trait specifically. This is just the regular line breaking that pprust does for code that is too long:

fn print_break(&mut self, token: BreakToken, size: isize) {
let fits = match self.get_top() {
PrintFrame::Fits => true,
PrintFrame::Broken { breaks: Breaks::Consistent, .. } => false,
PrintFrame::Broken { breaks: Breaks::Inconsistent, .. } => size <= self.space,
};
if fits {
self.pending_indentation += token.blank_space;
self.space -= token.blank_space;
} else {
if let Some(pre_break) = token.pre_break {
self.out.push(pre_break);
}
self.out.push('\n');
let indent = self.indent as isize + token.offset;
self.pending_indentation = indent;
self.space = cmp::max(MARGIN - indent, MIN_SPACE);
}
}

I don't think we should remove pprust's ability to break lines, and I don't think it's worth it to introduce extra configurables (like breaking only with spaces). I'd rather have the hack be as localized as possible, or else rewrite this formatting code to no longer rely on pprust at all.

@wesleywiser
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 25, 2023

📌 Commit 4692375 has been approved by wesleywiser

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 25, 2023
…=wesleywiser

Don't print newlines in APITs

This is kind of a hack, but it gets the job done because the only "special" formatting that (afaict) `rustc_ast_pretty` does is break with newlines sometimes.

Fixes rust-lang/measureme#207
bors added a commit to rust-lang-ci/rust that referenced this pull request May 25, 2023
…mpiler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#107522 (Add Median of Medians fallback to introselect)
 - rust-lang#111152 (update `pulldown-cmark` to `0.9.3`)
 - rust-lang#111757 (Consider lint check attributes on match arms)
 - rust-lang#111831 (Always capture slice when pattern requires checking the length)
 - rust-lang#111929 (Don't print newlines in APITs)
 - rust-lang#111945 (Migrate GUI colors test to original CSS color format)
 - rust-lang#111950 (Remove ExpnKind::Inlined.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5227b68 into rust-lang:master May 26, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 26, 2023
@compiler-errors compiler-errors deleted the no-newline-apit branch August 11, 2023 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Could not parse event_id. Found ASCII control character in <text>
5 participants