Skip to content

Commit 3831a25

Browse files
committed
Auto merge of #2817 - saethlin:rustup, r=saethlin
rustup Doing a sync just before I do a rustc-push
2 parents b024de1 + ba1c094 commit 3831a25

File tree

318 files changed

+3713
-2039
lines changed

Some content is hidden

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

318 files changed

+3713
-2039
lines changed

Cargo.lock

+13-3
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ dependencies = [
353353

354354
[[package]]
355355
name = "cargo"
356-
version = "0.70.0"
356+
version = "0.71.0"
357357
dependencies = [
358358
"anyhow",
359359
"base64",
@@ -1001,7 +1001,7 @@ dependencies = [
10011001

10021002
[[package]]
10031003
name = "crates-io"
1004-
version = "0.35.1"
1004+
version = "0.36.0"
10051005
dependencies = [
10061006
"anyhow",
10071007
"curl",
@@ -5139,6 +5139,7 @@ dependencies = [
51395139
"rustc_session",
51405140
"rustc_span",
51415141
"rustc_target",
5142+
"rustc_trait_selection",
51425143
"tracing",
51435144
]
51445145

@@ -5457,13 +5458,13 @@ dependencies = [
54575458
"itertools",
54585459
"minifier",
54595460
"once_cell",
5460-
"rayon",
54615461
"regex",
54625462
"rustdoc-json-types",
54635463
"serde",
54645464
"serde_json",
54655465
"smallvec",
54665466
"tempfile",
5467+
"threadpool",
54675468
"tracing",
54685469
"tracing-subscriber",
54695470
"tracing-tree",
@@ -6208,6 +6209,15 @@ dependencies = [
62086209
"once_cell",
62096210
]
62106211

6212+
[[package]]
6213+
name = "threadpool"
6214+
version = "1.8.1"
6215+
source = "registry+https://github.com/rust-lang/crates.io-index"
6216+
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
6217+
dependencies = [
6218+
"num_cpus",
6219+
]
6220+
62116221
[[package]]
62126222
name = "tidy"
62136223
version = "0.1.0"

RELEASES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ Compiler
125125
- [Optimize field ordering by grouping m\*2^n-sized fields with equivalently aligned ones.](https://github.com/rust-lang/rust/pull/102750/)
126126
- [Stabilize native library modifier `verbatim`.](https://github.com/rust-lang/rust/pull/104360/)
127127

128-
Added and removed targets:
128+
Added, updated, and removed targets:
129129

130130
- [Add a tier 3 target for PowerPC on AIX](https://github.com/rust-lang/rust/pull/102293/), `powerpc64-ibm-aix`.
131131
- [Add a tier 3 target for the Sony PlayStation 1](https://github.com/rust-lang/rust/pull/102689/), `mipsel-sony-psx`.
132132
- [Add tier 3 `no_std` targets for the QNX Neutrino RTOS](https://github.com/rust-lang/rust/pull/102701/),
133133
`aarch64-unknown-nto-qnx710` and `x86_64-pc-nto-qnx710`.
134+
- [Promote UEFI targets to tier 2](https://github.com/rust-lang/rust/pull/103933/), `aarch64-unknown-uefi`, `i686-unknown-uefi`, and `x86_64-unknown-uefi`.
134135
- [Remove tier 3 `linuxkernel` targets](https://github.com/rust-lang/rust/pull/104015/) (not used by the actual kernel).
135136

136137
Refer to Rust's [platform support page][platform-support-doc]

compiler/rustc_ast/src/ast.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,15 @@ impl Expr {
11841184
expr
11851185
}
11861186

1187+
pub fn peel_parens_and_refs(&self) -> &Expr {
1188+
let mut expr = self;
1189+
while let ExprKind::Paren(inner) | ExprKind::AddrOf(BorrowKind::Ref, _, inner) = &expr.kind
1190+
{
1191+
expr = inner;
1192+
}
1193+
expr
1194+
}
1195+
11871196
/// Attempts to reparse as `Ty` (for diagnostic purposes).
11881197
pub fn to_ty(&self) -> Option<P<Ty>> {
11891198
let kind = match &self.kind {

compiler/rustc_ast/src/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl FormatArguments {
131131
&self.arguments[..]
132132
}
133133

134-
pub fn all_args_mut(&mut self) -> &mut [FormatArgument] {
135-
&mut self.arguments[..]
134+
pub fn all_args_mut(&mut self) -> &mut Vec<FormatArgument> {
135+
&mut self.arguments
136136
}
137137
}
138138

compiler/rustc_ast_lowering/src/format.rs

+216-22
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,172 @@ use rustc_hir as hir;
77
use rustc_span::{
88
sym,
99
symbol::{kw, Ident},
10-
Span,
10+
Span, Symbol,
1111
};
12+
use std::borrow::Cow;
1213

1314
impl<'hir> LoweringContext<'_, 'hir> {
1415
pub(crate) fn lower_format_args(&mut self, sp: Span, fmt: &FormatArgs) -> hir::ExprKind<'hir> {
15-
expand_format_args(self, sp, fmt)
16+
// Never call the const constructor of `fmt::Arguments` if the
17+
// format_args!() had any arguments _before_ flattening/inlining.
18+
let allow_const = fmt.arguments.all_args().is_empty();
19+
let mut fmt = Cow::Borrowed(fmt);
20+
if self.tcx.sess.opts.unstable_opts.flatten_format_args {
21+
fmt = flatten_format_args(fmt);
22+
fmt = inline_literals(fmt);
23+
}
24+
expand_format_args(self, sp, &fmt, allow_const)
25+
}
26+
}
27+
28+
/// Flattens nested `format_args!()` into one.
29+
///
30+
/// Turns
31+
///
32+
/// `format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3)`
33+
///
34+
/// into
35+
///
36+
/// `format_args!("a {} b{}! {}.", 1, 2, 3)`.
37+
fn flatten_format_args(mut fmt: Cow<'_, FormatArgs>) -> Cow<'_, FormatArgs> {
38+
let mut i = 0;
39+
while i < fmt.template.len() {
40+
if let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i]
41+
&& let FormatTrait::Display | FormatTrait::Debug = &placeholder.format_trait
42+
&& let Ok(arg_index) = placeholder.argument.index
43+
&& let arg = fmt.arguments.all_args()[arg_index].expr.peel_parens_and_refs()
44+
&& let ExprKind::FormatArgs(_) = &arg.kind
45+
// Check that this argument is not used by any other placeholders.
46+
&& fmt.template.iter().enumerate().all(|(j, p)|
47+
i == j ||
48+
!matches!(p, FormatArgsPiece::Placeholder(placeholder)
49+
if placeholder.argument.index == Ok(arg_index))
50+
)
51+
{
52+
// Now we need to mutate the outer FormatArgs.
53+
// If this is the first time, this clones the outer FormatArgs.
54+
let fmt = fmt.to_mut();
55+
56+
// Take the inner FormatArgs out of the outer arguments, and
57+
// replace it by the inner arguments. (We can't just put those at
58+
// the end, because we need to preserve the order of evaluation.)
59+
60+
let args = fmt.arguments.all_args_mut();
61+
let remaining_args = args.split_off(arg_index + 1);
62+
let old_arg_offset = args.len();
63+
let mut fmt2 = &mut args.pop().unwrap().expr; // The inner FormatArgs.
64+
let fmt2 = loop { // Unwrap the Expr to get to the FormatArgs.
65+
match &mut fmt2.kind {
66+
ExprKind::Paren(inner) | ExprKind::AddrOf(BorrowKind::Ref, _, inner) => fmt2 = inner,
67+
ExprKind::FormatArgs(fmt2) => break fmt2,
68+
_ => unreachable!(),
69+
}
70+
};
71+
72+
args.append(fmt2.arguments.all_args_mut());
73+
let new_arg_offset = args.len();
74+
args.extend(remaining_args);
75+
76+
// Correct the indexes that refer to the arguments after the newly inserted arguments.
77+
for_all_argument_indexes(&mut fmt.template, |index| {
78+
if *index >= old_arg_offset {
79+
*index -= old_arg_offset;
80+
*index += new_arg_offset;
81+
}
82+
});
83+
84+
// Now merge the placeholders:
85+
86+
let rest = fmt.template.split_off(i + 1);
87+
fmt.template.pop(); // remove the placeholder for the nested fmt args.
88+
// Insert the pieces from the nested format args, but correct any
89+
// placeholders to point to the correct argument index.
90+
for_all_argument_indexes(&mut fmt2.template, |index| *index += arg_index);
91+
fmt.template.append(&mut fmt2.template);
92+
fmt.template.extend(rest);
93+
94+
// Don't increment `i` here, so we recurse into the newly added pieces.
95+
} else {
96+
i += 1;
97+
}
1698
}
99+
fmt
100+
}
101+
102+
/// Inline literals into the format string.
103+
///
104+
/// Turns
105+
///
106+
/// `format_args!("Hello, {}! {} {}", "World", 123, x)`
107+
///
108+
/// into
109+
///
110+
/// `format_args!("Hello, World! 123 {}", x)`.
111+
fn inline_literals(mut fmt: Cow<'_, FormatArgs>) -> Cow<'_, FormatArgs> {
112+
let mut was_inlined = vec![false; fmt.arguments.all_args().len()];
113+
let mut inlined_anything = false;
114+
115+
for i in 0..fmt.template.len() {
116+
let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i] else { continue };
117+
let Ok(arg_index) = placeholder.argument.index else { continue };
118+
119+
let mut literal = None;
120+
121+
if let FormatTrait::Display = placeholder.format_trait
122+
&& placeholder.format_options == Default::default()
123+
&& let arg = fmt.arguments.all_args()[arg_index].expr.peel_parens_and_refs()
124+
&& let ExprKind::Lit(lit) = arg.kind
125+
{
126+
if let token::LitKind::Str | token::LitKind::StrRaw(_) = lit.kind
127+
&& let Ok(LitKind::Str(s, _)) = LitKind::from_token_lit(lit)
128+
{
129+
literal = Some(s);
130+
} else if let token::LitKind::Integer = lit.kind
131+
&& let Ok(LitKind::Int(n, _)) = LitKind::from_token_lit(lit)
132+
{
133+
literal = Some(Symbol::intern(&n.to_string()));
134+
}
135+
}
136+
137+
if let Some(literal) = literal {
138+
// Now we need to mutate the outer FormatArgs.
139+
// If this is the first time, this clones the outer FormatArgs.
140+
let fmt = fmt.to_mut();
141+
// Replace the placeholder with the literal.
142+
fmt.template[i] = FormatArgsPiece::Literal(literal);
143+
was_inlined[arg_index] = true;
144+
inlined_anything = true;
145+
}
146+
}
147+
148+
// Remove the arguments that were inlined.
149+
if inlined_anything {
150+
let fmt = fmt.to_mut();
151+
152+
let mut remove = was_inlined;
153+
154+
// Don't remove anything that's still used.
155+
for_all_argument_indexes(&mut fmt.template, |index| remove[*index] = false);
156+
157+
// Drop all the arguments that are marked for removal.
158+
let mut remove_it = remove.iter();
159+
fmt.arguments.all_args_mut().retain(|_| remove_it.next() != Some(&true));
160+
161+
// Calculate the mapping of old to new indexes for the remaining arguments.
162+
let index_map: Vec<usize> = remove
163+
.into_iter()
164+
.scan(0, |i, remove| {
165+
let mapped = *i;
166+
*i += !remove as usize;
167+
Some(mapped)
168+
})
169+
.collect();
170+
171+
// Correct the indexes that refer to arguments that have shifted position.
172+
for_all_argument_indexes(&mut fmt.template, |index| *index = index_map[*index]);
173+
}
174+
175+
fmt
17176
}
18177

19178
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
@@ -189,11 +348,26 @@ fn expand_format_args<'hir>(
189348
ctx: &mut LoweringContext<'_, 'hir>,
190349
macsp: Span,
191350
fmt: &FormatArgs,
351+
allow_const: bool,
192352
) -> hir::ExprKind<'hir> {
353+
let mut incomplete_lit = String::new();
193354
let lit_pieces =
194355
ctx.arena.alloc_from_iter(fmt.template.iter().enumerate().filter_map(|(i, piece)| {
195356
match piece {
196-
&FormatArgsPiece::Literal(s) => Some(ctx.expr_str(fmt.span, s)),
357+
&FormatArgsPiece::Literal(s) => {
358+
// Coalesce adjacent literal pieces.
359+
if let Some(FormatArgsPiece::Literal(_)) = fmt.template.get(i + 1) {
360+
incomplete_lit.push_str(s.as_str());
361+
None
362+
} else if !incomplete_lit.is_empty() {
363+
incomplete_lit.push_str(s.as_str());
364+
let s = Symbol::intern(&incomplete_lit);
365+
incomplete_lit.clear();
366+
Some(ctx.expr_str(fmt.span, s))
367+
} else {
368+
Some(ctx.expr_str(fmt.span, s))
369+
}
370+
}
197371
&FormatArgsPiece::Placeholder(_) => {
198372
// Inject empty string before placeholders when not already preceded by a literal piece.
199373
if i == 0 || matches!(fmt.template[i - 1], FormatArgsPiece::Placeholder(_)) {
@@ -244,6 +418,18 @@ fn expand_format_args<'hir>(
244418

245419
let arguments = fmt.arguments.all_args();
246420

421+
if allow_const && arguments.is_empty() && argmap.is_empty() {
422+
// Generate:
423+
// <core::fmt::Arguments>::new_const(lit_pieces)
424+
let new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
425+
macsp,
426+
hir::LangItem::FormatArguments,
427+
sym::new_const,
428+
));
429+
let new_args = ctx.arena.alloc_from_iter([lit_pieces]);
430+
return hir::ExprKind::Call(new, new_args);
431+
}
432+
247433
// If the args array contains exactly all the original arguments once,
248434
// in order, we can use a simple array instead of a `match` construction.
249435
// However, if there's a yield point in any argument except the first one,
@@ -290,25 +476,14 @@ fn expand_format_args<'hir>(
290476
let args_ident = Ident::new(sym::args, macsp);
291477
let (args_pat, args_hir_id) = ctx.pat_ident(macsp, args_ident);
292478
let args = ctx.arena.alloc_from_iter(argmap.iter().map(|&(arg_index, ty)| {
293-
if let Some(arg) = arguments.get(arg_index) {
294-
let sp = arg.expr.span.with_ctxt(macsp.ctxt());
295-
let args_ident_expr = ctx.expr_ident(macsp, args_ident, args_hir_id);
296-
let arg = ctx.arena.alloc(ctx.expr(
297-
sp,
298-
hir::ExprKind::Field(
299-
args_ident_expr,
300-
Ident::new(sym::integer(arg_index), macsp),
301-
),
302-
));
303-
make_argument(ctx, sp, arg, ty)
304-
} else {
305-
ctx.expr(
306-
macsp,
307-
hir::ExprKind::Err(
308-
ctx.tcx.sess.delay_span_bug(macsp, format!("no arg at {arg_index}")),
309-
),
310-
)
311-
}
479+
let arg = &arguments[arg_index];
480+
let sp = arg.expr.span.with_ctxt(macsp.ctxt());
481+
let args_ident_expr = ctx.expr_ident(macsp, args_ident, args_hir_id);
482+
let arg = ctx.arena.alloc(ctx.expr(
483+
sp,
484+
hir::ExprKind::Field(args_ident_expr, Ident::new(sym::integer(arg_index), macsp)),
485+
));
486+
make_argument(ctx, sp, arg, ty)
312487
}));
313488
let elements: Vec<_> = arguments
314489
.iter()
@@ -409,3 +584,22 @@ fn may_contain_yield_point(e: &ast::Expr) -> bool {
409584
visitor.visit_expr(e);
410585
visitor.0
411586
}
587+
588+
fn for_all_argument_indexes(template: &mut [FormatArgsPiece], mut f: impl FnMut(&mut usize)) {
589+
for piece in template {
590+
let FormatArgsPiece::Placeholder(placeholder) = piece else { continue };
591+
if let Ok(index) = &mut placeholder.argument.index {
592+
f(index);
593+
}
594+
if let Some(FormatCount::Argument(FormatArgPosition { index: Ok(index), .. })) =
595+
&mut placeholder.format_options.width
596+
{
597+
f(index);
598+
}
599+
if let Some(FormatCount::Argument(FormatArgPosition { index: Ok(index), .. })) =
600+
&mut placeholder.format_options.precision
601+
{
602+
f(index);
603+
}
604+
}
605+
}

compiler/rustc_borrowck/src/dataflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
306306
}
307307

308308
// By passing `PlaceConflictBias::NoOverlap`, we conservatively assume that any given
309-
// pair of array indices are unequal, so that when `places_conflict` returns true, we
309+
// pair of array indices are not equal, so that when `places_conflict` returns true, we
310310
// will be assured that two places being compared definitely denotes the same sets of
311311
// locations.
312312
let definitely_conflicting_borrows = other_borrows_of_local.filter(|&i| {

0 commit comments

Comments
 (0)