Skip to content

Commit c359117

Browse files
committed
Auto merge of #142442 - matthiaskrgr:rollup-6yodjfx, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #134847 (Implement asymmetrical precedence for closures and jumps) - #141491 (Delegate `<CStr as Debug>` to `ByteStr`) - #141770 (Merge `Cfg::render_long_html` and `Cfg::render_long_plain` methods common code) - #142069 (Introduce `-Zmacro-stats`) - #142158 (Tracking the old name of renamed unstable library features) - #142221 ([AIX] strip underlying xcoff object) - #142340 (miri: we can use apfloat's mul_add now) - #142379 (Add bootstrap option to compile a tool with features) - #142410 (intrinsics: rename min_align_of to align_of) - #142413 (rustc-dev-guide subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 015c777 + 9c826de commit c359117

File tree

97 files changed

+1094
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1094
-311
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,9 +3234,9 @@ dependencies = [
32343234

32353235
[[package]]
32363236
name = "rustc_apfloat"
3237-
version = "0.2.2+llvm-462a31f5a5ab"
3237+
version = "0.2.3+llvm-462a31f5a5ab"
32383238
source = "registry+https://github.com/rust-lang/crates.io-index"
3239-
checksum = "121e2195ff969977a4e2b5c9965ea867fce7e4cb5aee5b09dee698a7932d574f"
3239+
checksum = "486c2179b4796f65bfe2ee33679acf0927ac83ecf583ad6c91c3b4570911b9ad"
32403240
dependencies = [
32413241
"bitflags",
32423242
"smallvec",

bootstrap.example.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,15 @@
381381
# "miri", "cargo-miri" # for dev/nightly channels
382382
#]
383383

384+
# Specify build configuration specific for some tool, such as enabled features.
385+
# This option has no effect on which tools are enabled: refer to the `tools` option for that.
386+
#
387+
# For example, to build Miri with tracing support, use `tool.miri.features = ["tracing"]`
388+
#
389+
# The default value for the `features` array is `[]`. However, please note that other flags in
390+
# `bootstrap.toml` might influence the features enabled for some tools.
391+
#tool.TOOL_NAME.features = [FEATURE1, FEATURE2]
392+
384393
# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation
385394
#verbose = 0
386395

compiler/rustc_ast/src/ast.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ pub struct Path {
9797
pub tokens: Option<LazyAttrTokenStream>,
9898
}
9999

100+
// Succeeds if the path has a single segment that is arg-free and matches the given symbol.
100101
impl PartialEq<Symbol> for Path {
101102
#[inline]
102103
fn eq(&self, name: &Symbol) -> bool {
103104
if let [segment] = self.segments.as_ref()
104-
&& segment.args.is_none()
105-
&& segment.ident.name == *name
105+
&& segment == name
106106
{
107107
true
108108
} else {
@@ -111,6 +111,15 @@ impl PartialEq<Symbol> for Path {
111111
}
112112
}
113113

114+
// Succeeds if the path has segments that are arg-free and match the given symbols.
115+
impl PartialEq<&[Symbol]> for Path {
116+
#[inline]
117+
fn eq(&self, names: &&[Symbol]) -> bool {
118+
self.segments.len() == names.len()
119+
&& self.segments.iter().zip(names.iter()).all(|(s1, s2)| s1 == s2)
120+
}
121+
}
122+
114123
impl<CTX: rustc_span::HashStableContext> HashStable<CTX> for Path {
115124
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
116125
self.segments.len().hash_stable(hcx, hasher);
@@ -166,6 +175,14 @@ pub struct PathSegment {
166175
pub args: Option<P<GenericArgs>>,
167176
}
168177

178+
// Succeeds if the path segment is arg-free and matches the given symbol.
179+
impl PartialEq<Symbol> for PathSegment {
180+
#[inline]
181+
fn eq(&self, name: &Symbol) -> bool {
182+
self.args.is_none() && self.ident.name == *name
183+
}
184+
}
185+
169186
impl PathSegment {
170187
pub fn from_ident(ident: Ident) -> Self {
171188
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
@@ -1441,11 +1458,15 @@ impl Expr {
14411458
}
14421459
}
14431460

1444-
ExprKind::Break(..)
1445-
| ExprKind::Ret(..)
1446-
| ExprKind::Yield(..)
1447-
| ExprKind::Yeet(..)
1448-
| ExprKind::Become(..) => ExprPrecedence::Jump,
1461+
ExprKind::Break(_ /*label*/, value)
1462+
| ExprKind::Ret(value)
1463+
| ExprKind::Yield(YieldKind::Prefix(value))
1464+
| ExprKind::Yeet(value) => match value {
1465+
Some(_) => ExprPrecedence::Jump,
1466+
None => ExprPrecedence::Unambiguous,
1467+
},
1468+
1469+
ExprKind::Become(_) => ExprPrecedence::Jump,
14491470

14501471
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
14511472
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
@@ -1502,6 +1523,7 @@ impl Expr {
15021523
| ExprKind::Underscore
15031524
| ExprKind::UnsafeBinderCast(..)
15041525
| ExprKind::While(..)
1526+
| ExprKind::Yield(YieldKind::Postfix(..))
15051527
| ExprKind::Err(_)
15061528
| ExprKind::Dummy => ExprPrecedence::Unambiguous,
15071529
}

compiler/rustc_ast_pretty/src/pprust/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ pub fn item_to_string(i: &ast::Item) -> String {
5353
State::new().item_to_string(i)
5454
}
5555

56+
pub fn assoc_item_to_string(i: &ast::AssocItem) -> String {
57+
State::new().assoc_item_to_string(i)
58+
}
59+
60+
pub fn foreign_item_to_string(i: &ast::ForeignItem) -> String {
61+
State::new().foreign_item_to_string(i)
62+
}
63+
64+
pub fn stmt_to_string(s: &ast::Stmt) -> String {
65+
State::new().stmt_to_string(s)
66+
}
67+
5668
pub fn path_to_string(p: &ast::Path) -> String {
5769
State::new().path_to_string(p)
5870
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
10631063
Self::to_string(|s| s.print_item(i))
10641064
}
10651065

1066+
fn assoc_item_to_string(&self, i: &ast::AssocItem) -> String {
1067+
Self::to_string(|s| s.print_assoc_item(i))
1068+
}
1069+
1070+
fn foreign_item_to_string(&self, i: &ast::ForeignItem) -> String {
1071+
Self::to_string(|s| s.print_foreign_item(i))
1072+
}
1073+
10661074
fn path_to_string(&self, p: &ast::Path) -> String {
10671075
Self::to_string(|s| s.print_path(p, false, 0))
10681076
}

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_ast::util::classify;
77
use rustc_ast::util::literal::escape_byte_str_symbol;
88
use rustc_ast::util::parser::{self, ExprPrecedence, Fixity};
99
use rustc_ast::{
10-
self as ast, BlockCheckMode, FormatAlignment, FormatArgPosition, FormatArgsPiece, FormatCount,
11-
FormatDebugHex, FormatSign, FormatTrait, YieldKind, token,
10+
self as ast, BinOpKind, BlockCheckMode, FormatAlignment, FormatArgPosition, FormatArgsPiece,
11+
FormatCount, FormatDebugHex, FormatSign, FormatTrait, YieldKind, token,
1212
};
1313

1414
use crate::pp::Breaks::Inconsistent;
@@ -214,13 +214,6 @@ impl<'a> State<'a> {
214214
}
215215

216216
fn print_expr_call(&mut self, func: &ast::Expr, args: &[P<ast::Expr>], fixup: FixupContext) {
217-
let needs_paren = match func.kind {
218-
// In order to call a named field, needs parens: `(self.fun)()`
219-
// But not for an unnamed field: `self.0()`
220-
ast::ExprKind::Field(_, name) => !name.is_numeric(),
221-
_ => func.precedence() < ExprPrecedence::Unambiguous,
222-
};
223-
224217
// Independent of parenthesization related to precedence, we must
225218
// parenthesize `func` if this is a statement context in which without
226219
// parentheses, a statement boundary would occur inside `func` or
@@ -237,8 +230,16 @@ impl<'a> State<'a> {
237230
// because the latter is valid syntax but with the incorrect meaning.
238231
// It's a match-expression followed by tuple-expression, not a function
239232
// call.
240-
self.print_expr_cond_paren(func, needs_paren, fixup.leftmost_subexpression());
233+
let func_fixup = fixup.leftmost_subexpression_with_operator(true);
234+
235+
let needs_paren = match func.kind {
236+
// In order to call a named field, needs parens: `(self.fun)()`
237+
// But not for an unnamed field: `self.0()`
238+
ast::ExprKind::Field(_, name) => !name.is_numeric(),
239+
_ => func_fixup.precedence(func) < ExprPrecedence::Unambiguous,
240+
};
241241

242+
self.print_expr_cond_paren(func, needs_paren, func_fixup);
242243
self.print_call_post(args)
243244
}
244245

@@ -281,9 +282,24 @@ impl<'a> State<'a> {
281282
rhs: &ast::Expr,
282283
fixup: FixupContext,
283284
) {
285+
let operator_can_begin_expr = match op {
286+
| BinOpKind::Sub // -x
287+
| BinOpKind::Mul // *x
288+
| BinOpKind::And // &&x
289+
| BinOpKind::Or // || x
290+
| BinOpKind::BitAnd // &x
291+
| BinOpKind::BitOr // |x| x
292+
| BinOpKind::Shl // <<T as Trait>::Type as Trait>::CONST
293+
| BinOpKind::Lt // <T as Trait>::CONST
294+
=> true,
295+
_ => false,
296+
};
297+
298+
let left_fixup = fixup.leftmost_subexpression_with_operator(operator_can_begin_expr);
299+
284300
let binop_prec = op.precedence();
285-
let left_prec = lhs.precedence();
286-
let right_prec = rhs.precedence();
301+
let left_prec = left_fixup.precedence(lhs);
302+
let right_prec = fixup.precedence(rhs);
287303

288304
let (mut left_needs_paren, right_needs_paren) = match op.fixity() {
289305
Fixity::Left => (left_prec < binop_prec, right_prec <= binop_prec),
@@ -312,18 +328,18 @@ impl<'a> State<'a> {
312328
_ => {}
313329
}
314330

315-
self.print_expr_cond_paren(lhs, left_needs_paren, fixup.leftmost_subexpression());
331+
self.print_expr_cond_paren(lhs, left_needs_paren, left_fixup);
316332
self.space();
317333
self.word_space(op.as_str());
318-
self.print_expr_cond_paren(rhs, right_needs_paren, fixup.subsequent_subexpression());
334+
self.print_expr_cond_paren(rhs, right_needs_paren, fixup.rightmost_subexpression());
319335
}
320336

321337
fn print_expr_unary(&mut self, op: ast::UnOp, expr: &ast::Expr, fixup: FixupContext) {
322338
self.word(op.as_str());
323339
self.print_expr_cond_paren(
324340
expr,
325-
expr.precedence() < ExprPrecedence::Prefix,
326-
fixup.subsequent_subexpression(),
341+
fixup.precedence(expr) < ExprPrecedence::Prefix,
342+
fixup.rightmost_subexpression(),
327343
);
328344
}
329345

@@ -344,8 +360,8 @@ impl<'a> State<'a> {
344360
}
345361
self.print_expr_cond_paren(
346362
expr,
347-
expr.precedence() < ExprPrecedence::Prefix,
348-
fixup.subsequent_subexpression(),
363+
fixup.precedence(expr) < ExprPrecedence::Prefix,
364+
fixup.rightmost_subexpression(),
349365
);
350366
}
351367

@@ -590,8 +606,8 @@ impl<'a> State<'a> {
590606
self.word_space("=");
591607
self.print_expr_cond_paren(
592608
rhs,
593-
rhs.precedence() < ExprPrecedence::Assign,
594-
fixup.subsequent_subexpression(),
609+
fixup.precedence(rhs) < ExprPrecedence::Assign,
610+
fixup.rightmost_subexpression(),
595611
);
596612
}
597613
ast::ExprKind::AssignOp(op, lhs, rhs) => {
@@ -604,8 +620,8 @@ impl<'a> State<'a> {
604620
self.word_space(op.node.as_str());
605621
self.print_expr_cond_paren(
606622
rhs,
607-
rhs.precedence() < ExprPrecedence::Assign,
608-
fixup.subsequent_subexpression(),
623+
fixup.precedence(rhs) < ExprPrecedence::Assign,
624+
fixup.rightmost_subexpression(),
609625
);
610626
}
611627
ast::ExprKind::Field(expr, ident) => {
@@ -618,10 +634,11 @@ impl<'a> State<'a> {
618634
self.print_ident(*ident);
619635
}
620636
ast::ExprKind::Index(expr, index, _) => {
637+
let expr_fixup = fixup.leftmost_subexpression_with_operator(true);
621638
self.print_expr_cond_paren(
622639
expr,
623-
expr.precedence() < ExprPrecedence::Unambiguous,
624-
fixup.leftmost_subexpression(),
640+
expr_fixup.precedence(expr) < ExprPrecedence::Unambiguous,
641+
expr_fixup,
625642
);
626643
self.word("[");
627644
self.print_expr(index, FixupContext::default());
@@ -634,10 +651,11 @@ impl<'a> State<'a> {
634651
// a "normal" binop gets parenthesized. (`LOr` is the lowest-precedence binop.)
635652
let fake_prec = ExprPrecedence::LOr;
636653
if let Some(e) = start {
654+
let start_fixup = fixup.leftmost_subexpression_with_operator(true);
637655
self.print_expr_cond_paren(
638656
e,
639-
e.precedence() < fake_prec,
640-
fixup.leftmost_subexpression(),
657+
start_fixup.precedence(e) < fake_prec,
658+
start_fixup,
641659
);
642660
}
643661
match limits {
@@ -647,8 +665,8 @@ impl<'a> State<'a> {
647665
if let Some(e) = end {
648666
self.print_expr_cond_paren(
649667
e,
650-
e.precedence() < fake_prec,
651-
fixup.subsequent_subexpression(),
668+
fixup.precedence(e) < fake_prec,
669+
fixup.rightmost_subexpression(),
652670
);
653671
}
654672
}
@@ -665,11 +683,10 @@ impl<'a> State<'a> {
665683
self.space();
666684
self.print_expr_cond_paren(
667685
expr,
668-
// Parenthesize if required by precedence, or in the
669-
// case of `break 'inner: loop { break 'inner 1 } + 1`
670-
expr.precedence() < ExprPrecedence::Jump
671-
|| (opt_label.is_none() && classify::leading_labeled_expr(expr)),
672-
fixup.subsequent_subexpression(),
686+
// Parenthesize `break 'inner: loop { break 'inner 1 } + 1`
687+
// ^---------------------------------^
688+
opt_label.is_none() && classify::leading_labeled_expr(expr),
689+
fixup.rightmost_subexpression(),
673690
);
674691
}
675692
}
@@ -684,11 +701,7 @@ impl<'a> State<'a> {
684701
self.word("return");
685702
if let Some(expr) = result {
686703
self.word(" ");
687-
self.print_expr_cond_paren(
688-
expr,
689-
expr.precedence() < ExprPrecedence::Jump,
690-
fixup.subsequent_subexpression(),
691-
);
704+
self.print_expr(expr, fixup.rightmost_subexpression());
692705
}
693706
}
694707
ast::ExprKind::Yeet(result) => {
@@ -697,21 +710,13 @@ impl<'a> State<'a> {
697710
self.word("yeet");
698711
if let Some(expr) = result {
699712
self.word(" ");
700-
self.print_expr_cond_paren(
701-
expr,
702-
expr.precedence() < ExprPrecedence::Jump,
703-
fixup.subsequent_subexpression(),
704-
);
713+
self.print_expr(expr, fixup.rightmost_subexpression());
705714
}
706715
}
707716
ast::ExprKind::Become(result) => {
708717
self.word("become");
709718
self.word(" ");
710-
self.print_expr_cond_paren(
711-
result,
712-
result.precedence() < ExprPrecedence::Jump,
713-
fixup.subsequent_subexpression(),
714-
);
719+
self.print_expr(result, fixup.rightmost_subexpression());
715720
}
716721
ast::ExprKind::InlineAsm(a) => {
717722
// FIXME: Print `builtin # asm` once macro `asm` uses `builtin_syntax`.
@@ -761,11 +766,7 @@ impl<'a> State<'a> {
761766

762767
if let Some(expr) = e {
763768
self.space();
764-
self.print_expr_cond_paren(
765-
expr,
766-
expr.precedence() < ExprPrecedence::Jump,
767-
fixup.subsequent_subexpression(),
768-
);
769+
self.print_expr(expr, fixup.rightmost_subexpression());
769770
}
770771
}
771772
ast::ExprKind::Yield(YieldKind::Postfix(e)) => {

0 commit comments

Comments
 (0)