Skip to content

Rollup of 7 pull requests #140388

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

Merged
merged 39 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
399cf1f
fix(docs): add newlines between prefix/suffix chapters
hwhsu1231 Apr 18, 2025
1b5f2aa
toolchain version does not need to be specified
tshepang Apr 19, 2025
e9896cc
update build and test instructions
ZuseZ4 Apr 22, 2025
deed996
Merge pull request #2350 from rust-lang/update-autodiff-build-instr
ZuseZ4 Apr 22, 2025
3536324
Fix detection of `main` function if there are expressions around it
GuillaumeGomez Apr 23, 2025
81438c0
Add regression ui test for #140162 and for #139651
GuillaumeGomez Apr 23, 2025
745500f
Preparing for merge from rustc
invalid-email-address Apr 24, 2025
1b315ad
Merge from rustc
invalid-email-address Apr 24, 2025
bdfeb8f
Remove `weak` alias terminology
BoxyUwU Apr 24, 2025
ba6dd90
typo
tshepang Apr 25, 2025
e6472b3
Merge pull request #2353 from rust-lang/tshepang-patch-1
tshepang Apr 25, 2025
3ededc1
Improve code
GuillaumeGomez Apr 25, 2025
3ef98a5
If there is a `;` alone, we consider that the doctest needs to be put…
GuillaumeGomez Apr 25, 2025
bffb760
Fix error message for static references or mutable references
yuk1ty Apr 20, 2025
7a70f33
Merge pull request #2345 from rust-lang/extraneous
tshepang Apr 26, 2025
3945ae9
Merge pull request #2343 from hwhsu1231-fork/fix-prefix-chapter
tshepang Apr 26, 2025
79faff2
use correct code block markers
tshepang Apr 26, 2025
26a60d4
Merge pull request #2354 from rust-lang/tshepang-fix-code-blocks
tshepang Apr 26, 2025
9eeadbf
copy-paste ease
tshepang Apr 26, 2025
e40391a
Merge pull request #2355 from rust-lang/tshepang-patch-1
tshepang Apr 26, 2025
9c4d568
replace command that does not work
tshepang Apr 26, 2025
89bb181
Merge pull request #2356 from rust-lang/tshepang-patch-2
tshepang Apr 26, 2025
aa69e3a
Fix bad handling of macros if there is already a `main` function
GuillaumeGomez Apr 26, 2025
474466d
ci: clean more disk space in codebuild
marcoieni Apr 27, 2025
d91ffb6
Merge pull request #2351 from rust-lang/rustc-pull
JohnTitor Apr 27, 2025
de491f9
Preparing for merge from rustc
invalid-email-address Apr 28, 2025
aa15830
Merge from rustc
invalid-email-address Apr 28, 2025
1b53c12
Merge pull request #2358 from rust-lang/rustc-pull
tshepang Apr 28, 2025
aff1be2
Introduce `BoxMarker` to pretty-printing.
nnethercote Apr 24, 2025
61a66b1
Use `PrintState::head` in `PrintState::block_to_string`.
nnethercote Apr 27, 2025
bb04e11
Inline and remove three pretty-printer methods.
nnethercote Apr 27, 2025
480d007
ci: use aws codebuild for the `dist-x86_64-linux` job
marcoieni Apr 28, 2025
1a766a8
Rollup merge of #140056 - yuk1ty:fix-static-mut-error-message, r=jiey…
GuillaumeGomez Apr 28, 2025
a782b54
Rollup merge of #140220 - GuillaumeGomez:doctest-main-wrapping, r=fmease
GuillaumeGomez Apr 28, 2025
7843686
Rollup merge of #140249 - BoxyUwU:remove_weak_alias_terminology, r=ol…
GuillaumeGomez Apr 28, 2025
cbc40c7
Rollup merge of #140316 - nnethercote:BoxMarker, r=dtolnay
GuillaumeGomez Apr 28, 2025
64b3643
Rollup merge of #140347 - marcoieni:free-disk-codebuild, r=jdno
GuillaumeGomez Apr 28, 2025
117202e
Rollup merge of #140349 - marcoieni:codebuild-linux-large-runners, r=…
GuillaumeGomez Apr 28, 2025
dd3ca71
Rollup merge of #140379 - tshepang:rdg-push, r=jieyouxu
GuillaumeGomez Apr 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_ast_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(internal_features)]
#![doc(rust_logo)]
#![feature(box_patterns)]
#![feature(negative_impls)]
#![feature(rustdoc_internals)]
// tidy-alphabetical-end

Expand Down
40 changes: 38 additions & 2 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,38 @@ struct BufEntry {
size: isize,
}

// Boxes opened with methods like `Printer::{cbox,ibox}` must be closed with
// `Printer::end`. Failure to do so can result in bad indenting, or in extreme
// cases, cause no output to be produced at all.
//
// Box opening and closing used to be entirely implicit, which was hard to
// understand and easy to get wrong. This marker type is now returned from the
// box opening methods and forgotten by `Printer::end`. Any marker that isn't
// forgotten will trigger a panic in `drop`. (Closing a box more than once
// isn't possible because `BoxMarker` doesn't implement `Copy` or `Clone`.)
//
// FIXME(nnethercote): the panic in `drop` is currently disabled because a few
// places fail to close their boxes. It can be enabled once they are fixed.
//
// Note: it would be better to make open/close mismatching impossible and avoid
// the need for this marker type altogether by having functions like
// `with_ibox` that open a box, call a closure, and then close the box. That
// would work for simple cases, but box lifetimes sometimes interact with
// complex control flow and across function boundaries in ways that are
// difficult to handle with such a technique.
#[must_use]
pub struct BoxMarker;

impl !Clone for BoxMarker {}
impl !Copy for BoxMarker {}

impl Drop for BoxMarker {
fn drop(&mut self) {
// FIXME(nnethercote): enable once the bad cases are fixed
//panic!("BoxMarker not ended with `Printer::end()`");
}
}

impl Printer {
pub fn new() -> Self {
Printer {
Expand Down Expand Up @@ -270,23 +302,27 @@ impl Printer {
}
}

fn scan_begin(&mut self, token: BeginToken) {
// This is is where `BoxMarker`s are produced.
fn scan_begin(&mut self, token: BeginToken) -> BoxMarker {
if self.scan_stack.is_empty() {
self.left_total = 1;
self.right_total = 1;
self.buf.clear();
}
let right = self.buf.push(BufEntry { token: Token::Begin(token), size: -self.right_total });
self.scan_stack.push_back(right);
BoxMarker
}

fn scan_end(&mut self) {
// This is is where `BoxMarker`s are consumed.
fn scan_end(&mut self, b: BoxMarker) {
if self.scan_stack.is_empty() {
self.print_end();
} else {
let right = self.buf.push(BufEntry { token: Token::End, size: -1 });
self.scan_stack.push_back(right);
}
std::mem::forget(b)
}

fn scan_break(&mut self, token: BreakToken) {
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_ast_pretty/src/pp/convenience.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
use std::borrow::Cow;

use crate::pp::{BeginToken, BreakToken, Breaks, IndentStyle, Printer, SIZE_INFINITY, Token};
use crate::pp::{
BeginToken, BoxMarker, BreakToken, Breaks, IndentStyle, Printer, SIZE_INFINITY, Token,
};

impl Printer {
/// "raw box"
pub fn rbox(&mut self, indent: isize, breaks: Breaks) {
pub fn rbox(&mut self, indent: isize, breaks: Breaks) -> BoxMarker {
self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
}

/// Inconsistent breaking box
pub fn ibox(&mut self, indent: isize) {
pub fn ibox(&mut self, indent: isize) -> BoxMarker {
self.rbox(indent, Breaks::Inconsistent)
}

/// Consistent breaking box
pub fn cbox(&mut self, indent: isize) {
pub fn cbox(&mut self, indent: isize) -> BoxMarker {
self.rbox(indent, Breaks::Consistent)
}

pub fn visual_align(&mut self) {
self.scan_begin(BeginToken { indent: IndentStyle::Visual, breaks: Breaks::Consistent });
pub fn visual_align(&mut self) -> BoxMarker {
self.scan_begin(BeginToken { indent: IndentStyle::Visual, breaks: Breaks::Consistent })
}

pub fn break_offset(&mut self, n: usize, off: isize) {
Expand All @@ -30,8 +32,8 @@ impl Printer {
});
}

pub fn end(&mut self) {
self.scan_end()
pub fn end(&mut self, b: BoxMarker) {
self.scan_end(b)
}

pub fn eof(mut self) -> String {
Expand Down
Loading
Loading