Skip to content

Commit ead9d17

Browse files
committed
Auto merge of rust-lang#127991 - tgross35:rollup-ccfammj, r=tgross35
Rollup of 8 pull requests Successful merges: - rust-lang#123196 (Add Process support for UEFI) - rust-lang#127523 (Migrate `dump-ice-to-disk` and `panic-abort-eh_frame` `run-make` tests to rmake) - rust-lang#127556 (Replace a long inline "autoref" comment with method docs) - rust-lang#127693 (Migrate `crate-hash-rustc-version` to `rmake`) - rust-lang#127866 (Conditionally build `wasm-component-ld` ) - rust-lang#127918 (Safely enforce thread name requirements) - rust-lang#127948 (fixes panic error `index out of bounds` in conflicting error) - rust-lang#127980 (Avoid ref when using format! in compiler) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9057c3f + d2d24cf commit ead9d17

File tree

46 files changed

+1317
-307
lines changed

Some content is hidden

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

46 files changed

+1317
-307
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
456456
if let Some(def_id) = def_id
457457
&& self.infcx.tcx.def_kind(def_id).is_fn_like()
458458
&& let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
459-
&& let ty::Param(_) =
460-
self.infcx.tcx.fn_sig(def_id).skip_binder().skip_binder().inputs()
461-
[pos + offset]
462-
.kind()
459+
&& let Some(arg) = self
460+
.infcx
461+
.tcx
462+
.fn_sig(def_id)
463+
.skip_binder()
464+
.skip_binder()
465+
.inputs()
466+
.get(pos + offset)
467+
&& let ty::Param(_) = arg.kind()
463468
{
464469
let place = &self.move_data.move_paths[mpi].place;
465470
let ty = place.ty(self.body, self.infcx.tcx).ty;

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
505505
let nop_inst = fx.bcx.ins().nop();
506506
fx.add_comment(
507507
nop_inst,
508-
format!("virtual call; self arg pass mode: {:?}", &fn_abi.args[0]),
508+
format!("virtual call; self arg pass mode: {:?}", fn_abi.args[0]),
509509
);
510510
}
511511

compiler/rustc_codegen_ssa/src/back/link.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn link_natively(
759759
sess.dcx().abort_if_errors();
760760

761761
// Invoke the system linker
762-
info!("{:?}", &cmd);
762+
info!("{cmd:?}");
763763
let retry_on_segfault = env::var("RUSTC_RETRY_LINKER_ON_SEGFAULT").is_ok();
764764
let unknown_arg_regex =
765765
Regex::new(r"(unknown|unrecognized) (command line )?(option|argument)").unwrap();
@@ -796,7 +796,7 @@ fn link_natively(
796796
cmd.arg(arg);
797797
}
798798
}
799-
info!("{:?}", &cmd);
799+
info!("{cmd:?}");
800800
continue;
801801
}
802802

@@ -817,7 +817,7 @@ fn link_natively(
817817
cmd.arg(arg);
818818
}
819819
}
820-
info!("{:?}", &cmd);
820+
info!("{cmd:?}");
821821
continue;
822822
}
823823

@@ -878,7 +878,7 @@ fn link_natively(
878878
cmd.arg(arg);
879879
}
880880
}
881-
info!("{:?}", &cmd);
881+
info!("{cmd:?}");
882882
continue;
883883
}
884884

@@ -996,7 +996,7 @@ fn link_natively(
996996
sess.dcx().emit_err(errors::UnableToExeLinker {
997997
linker_path,
998998
error: e,
999-
command_formatted: format!("{:?}", &cmd),
999+
command_formatted: format!("{cmd:?}"),
10001000
});
10011001
}
10021002

@@ -1567,7 +1567,7 @@ fn print_native_static_libs(
15671567
sess.dcx().emit_note(errors::StaticLibraryNativeArtifacts);
15681568
// Prefix for greppability
15691569
// Note: This must not be translated as tools are allowed to depend on this exact string.
1570-
sess.dcx().note(format!("native-static-libs: {}", &lib_args.join(" ")));
1570+
sess.dcx().note(format!("native-static-libs: {}", lib_args.join(" ")));
15711571
}
15721572
}
15731573
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
328328
sym::link_section => {
329329
if let Some(val) = attr.value_str() {
330330
if val.as_str().bytes().any(|b| b == 0) {
331-
let msg = format!("illegal null byte in link_section value: `{}`", &val);
331+
let msg = format!("illegal null byte in link_section value: `{val}`");
332332
tcx.dcx().span_err(attr.span, msg);
333333
} else {
334334
codegen_fn_attrs.link_section = Some(val);
@@ -726,7 +726,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
726726
if *ordinal <= u16::MAX as u128 {
727727
Some(ordinal.get() as u16)
728728
} else {
729-
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
729+
let msg = format!("ordinal value in `link_ordinal` is too large: `{ordinal}`");
730730
tcx.dcx()
731731
.struct_span_err(attr.span, msg)
732732
.with_note("the value may not exceed `u16::MAX`")

compiler/rustc_codegen_ssa/src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
130130

131131
let symbol_name = self.symbol_name(cx.tcx()).name;
132132

133-
debug!("symbol {}", &symbol_name);
133+
debug!("symbol {symbol_name}");
134134

135135
match *self {
136136
MonoItem::Static(def_id) => {

compiler/rustc_fluent_macro/src/fluent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
253253

254254
for Attribute { id: Identifier { name: attr_name }, .. } in attributes {
255255
let snake_name = Ident::new(
256-
&format!("{}{}", &crate_prefix, &attr_name.replace('-', "_")),
256+
&format!("{crate_prefix}{}", attr_name.replace('-', "_")),
257257
resource_str.span(),
258258
);
259259
if !previous_attrs.insert(snake_name.clone()) {

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
651651
self.path_segment.hir_id,
652652
num_params_to_take,
653653
);
654-
debug!("suggested_args: {:?}", &suggested_args);
654+
debug!("suggested_args: {suggested_args:?}");
655655

656656
match self.angle_brackets {
657657
AngleBrackets::Missing => {

compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn check_explicit_predicates<'tcx>(
249249
let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id);
250250

251251
for (outlives_predicate, &span) in explicit_predicates.as_ref().skip_binder() {
252-
debug!("outlives_predicate = {:?}", &outlives_predicate);
252+
debug!("outlives_predicate = {outlives_predicate:?}");
253253

254254
// Careful: If we are inferring the effects of a `dyn Trait<..>`
255255
// type, then when we look up the predicates for `Trait`,
@@ -289,12 +289,12 @@ fn check_explicit_predicates<'tcx>(
289289
&& let GenericArgKind::Type(ty) = outlives_predicate.0.unpack()
290290
&& ty.walk().any(|arg| arg == self_ty.into())
291291
{
292-
debug!("skipping self ty = {:?}", &ty);
292+
debug!("skipping self ty = {ty:?}");
293293
continue;
294294
}
295295

296296
let predicate = explicit_predicates.rebind(*outlives_predicate).instantiate(tcx, args);
297-
debug!("predicate = {:?}", &predicate);
297+
debug!("predicate = {predicate:?}");
298298
insert_outlives_predicate(tcx, predicate.0, predicate.1, span, required_predicates);
299299
}
300300
}

compiler/rustc_hir_typeck/src/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12651265
}
12661266
(
12671267
match parent_pred {
1268-
None => format!("`{}`", &p),
1268+
None => format!("`{p}`"),
12691269
Some(parent_pred) => match format_pred(*parent_pred) {
1270-
None => format!("`{}`", &p),
1270+
None => format!("`{p}`"),
12711271
Some((parent_p, _)) => {
12721272
if !suggested
12731273
&& !suggested_bounds.contains(pred)

compiler/rustc_middle/src/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn report_unstable(
112112
) {
113113
let msg = match reason {
114114
Some(r) => format!("use of unstable library feature '{feature}': {r}"),
115-
None => format!("use of unstable library feature '{}'", &feature),
115+
None => format!("use of unstable library feature '{feature}'"),
116116
};
117117

118118
if is_soft {

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
26272627
self.prepare_region_info(value);
26282628
}
26292629

2630-
debug!("self.used_region_names: {:?}", &self.used_region_names);
2630+
debug!("self.used_region_names: {:?}", self.used_region_names);
26312631

26322632
let mut empty = true;
26332633
let mut start_or_continue = |cx: &mut Self, start: &str, cont: &str| {

compiler/rustc_middle/src/util/find_self_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn find_self_call<'tcx>(
1414
local: Local,
1515
block: BasicBlock,
1616
) -> Option<(DefId, GenericArgsRef<'tcx>)> {
17-
debug!("find_self_call(local={:?}): terminator={:?}", local, &body[block].terminator);
17+
debug!("find_self_call(local={:?}): terminator={:?}", local, body[block].terminator);
1818
if let Some(Terminator { kind: TerminatorKind::Call { func, args, .. }, .. }) =
1919
&body[block].terminator
2020
{

compiler/rustc_mir_build/src/build/matches/mod.rs

+84-81
Original file line numberDiff line numberDiff line change
@@ -2162,92 +2162,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
21622162

21632163
self.ascribe_types(block, ascriptions);
21642164

2165-
// rust-lang/rust#27282: The `autoref` business deserves some
2166-
// explanation here.
2167-
//
2168-
// The intent of the `autoref` flag is that when it is true,
2169-
// then any pattern bindings of type T will map to a `&T`
2170-
// within the context of the guard expression, but will
2171-
// continue to map to a `T` in the context of the arm body. To
2172-
// avoid surfacing this distinction in the user source code
2173-
// (which would be a severe change to the language and require
2174-
// far more revision to the compiler), when `autoref` is true,
2175-
// then any occurrence of the identifier in the guard
2176-
// expression will automatically get a deref op applied to it.
2177-
//
2178-
// So an input like:
2179-
//
2180-
// ```
2181-
// let place = Foo::new();
2182-
// match place { foo if inspect(foo)
2183-
// => feed(foo), ... }
2184-
// ```
2185-
//
2186-
// will be treated as if it were really something like:
2187-
//
2188-
// ```
2189-
// let place = Foo::new();
2190-
// match place { Foo { .. } if { let tmp1 = &place; inspect(*tmp1) }
2191-
// => { let tmp2 = place; feed(tmp2) }, ... }
2192-
// ```
2193-
//
2194-
// And an input like:
2195-
//
2196-
// ```
2197-
// let place = Foo::new();
2198-
// match place { ref mut foo if inspect(foo)
2199-
// => feed(foo), ... }
2200-
// ```
2201-
//
2202-
// will be treated as if it were really something like:
2203-
//
2204-
// ```
2205-
// let place = Foo::new();
2206-
// match place { Foo { .. } if { let tmp1 = & &mut place; inspect(*tmp1) }
2207-
// => { let tmp2 = &mut place; feed(tmp2) }, ... }
2208-
// ```
2209-
//
2210-
// In short, any pattern binding will always look like *some*
2211-
// kind of `&T` within the guard at least in terms of how the
2212-
// MIR-borrowck views it, and this will ensure that guard
2213-
// expressions cannot mutate their the match inputs via such
2214-
// bindings. (It also ensures that guard expressions can at
2215-
// most *copy* values from such bindings; non-Copy things
2216-
// cannot be moved via pattern bindings in guard expressions.)
2217-
//
2218-
// ----
2219-
//
2220-
// Implementation notes (under assumption `autoref` is true).
2221-
//
2222-
// To encode the distinction above, we must inject the
2223-
// temporaries `tmp1` and `tmp2`.
2224-
//
2225-
// There are two cases of interest: binding by-value, and binding by-ref.
2226-
//
2227-
// 1. Binding by-value: Things are simple.
2228-
//
2229-
// * Establishing `tmp1` creates a reference into the
2230-
// matched place. This code is emitted by
2231-
// bind_matched_candidate_for_guard.
2232-
//
2233-
// * `tmp2` is only initialized "lazily", after we have
2234-
// checked the guard. Thus, the code that can trigger
2235-
// moves out of the candidate can only fire after the
2236-
// guard evaluated to true. This initialization code is
2237-
// emitted by bind_matched_candidate_for_arm.
2238-
//
2239-
// 2. Binding by-reference: Things are tricky.
2240-
//
2241-
// * Here, the guard expression wants a `&&` or `&&mut`
2242-
// into the original input. This means we need to borrow
2243-
// the reference that we create for the arm.
2244-
// * So we eagerly create the reference for the arm and then take a
2245-
// reference to that.
2165+
// Lower an instance of the arm guard (if present) for this candidate,
2166+
// and then perform bindings for the arm body.
22462167
if let Some((arm, match_scope)) = arm_match_scope
22472168
&& let Some(guard) = arm.guard
22482169
{
22492170
let tcx = self.tcx;
22502171

2172+
// Bindings for guards require some extra handling to automatically
2173+
// insert implicit references/dereferences.
22512174
self.bind_matched_candidate_for_guard(block, schedule_drops, bindings.clone());
22522175
let guard_frame = GuardFrame {
22532176
locals: bindings.clone().map(|b| GuardFrameLocal::new(b.var_id)).collect(),
@@ -2387,6 +2310,82 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
23872310
}
23882311
}
23892312

2313+
/// Binding for guards is a bit different from binding for the arm body,
2314+
/// because an extra layer of implicit reference/dereference is added.
2315+
///
2316+
/// The idea is that any pattern bindings of type T will map to a `&T` within
2317+
/// the context of the guard expression, but will continue to map to a `T`
2318+
/// in the context of the arm body. To avoid surfacing this distinction in
2319+
/// the user source code (which would be a severe change to the language and
2320+
/// require far more revision to the compiler), any occurrence of the
2321+
/// identifier in the guard expression will automatically get a deref op
2322+
/// applied to it. (See the caller of [`Self::is_bound_var_in_guard`].)
2323+
///
2324+
/// So an input like:
2325+
///
2326+
/// ```ignore (illustrative)
2327+
/// let place = Foo::new();
2328+
/// match place { foo if inspect(foo)
2329+
/// => feed(foo), ... }
2330+
/// ```
2331+
///
2332+
/// will be treated as if it were really something like:
2333+
///
2334+
/// ```ignore (illustrative)
2335+
/// let place = Foo::new();
2336+
/// match place { Foo { .. } if { let tmp1 = &place; inspect(*tmp1) }
2337+
/// => { let tmp2 = place; feed(tmp2) }, ... }
2338+
/// ```
2339+
///
2340+
/// And an input like:
2341+
///
2342+
/// ```ignore (illustrative)
2343+
/// let place = Foo::new();
2344+
/// match place { ref mut foo if inspect(foo)
2345+
/// => feed(foo), ... }
2346+
/// ```
2347+
///
2348+
/// will be treated as if it were really something like:
2349+
///
2350+
/// ```ignore (illustrative)
2351+
/// let place = Foo::new();
2352+
/// match place { Foo { .. } if { let tmp1 = & &mut place; inspect(*tmp1) }
2353+
/// => { let tmp2 = &mut place; feed(tmp2) }, ... }
2354+
/// ```
2355+
/// ---
2356+
///
2357+
/// ## Implementation notes
2358+
///
2359+
/// To encode the distinction above, we must inject the
2360+
/// temporaries `tmp1` and `tmp2`.
2361+
///
2362+
/// There are two cases of interest: binding by-value, and binding by-ref.
2363+
///
2364+
/// 1. Binding by-value: Things are simple.
2365+
///
2366+
/// * Establishing `tmp1` creates a reference into the
2367+
/// matched place. This code is emitted by
2368+
/// [`Self::bind_matched_candidate_for_guard`].
2369+
///
2370+
/// * `tmp2` is only initialized "lazily", after we have
2371+
/// checked the guard. Thus, the code that can trigger
2372+
/// moves out of the candidate can only fire after the
2373+
/// guard evaluated to true. This initialization code is
2374+
/// emitted by [`Self::bind_matched_candidate_for_arm_body`].
2375+
///
2376+
/// 2. Binding by-reference: Things are tricky.
2377+
///
2378+
/// * Here, the guard expression wants a `&&` or `&&mut`
2379+
/// into the original input. This means we need to borrow
2380+
/// the reference that we create for the arm.
2381+
/// * So we eagerly create the reference for the arm and then take a
2382+
/// reference to that.
2383+
///
2384+
/// ---
2385+
///
2386+
/// See these PRs for some historical context:
2387+
/// - <https://github.com/rust-lang/rust/pull/49870> (introduction of autoref)
2388+
/// - <https://github.com/rust-lang/rust/pull/59114> (always use autoref)
23902389
fn bind_matched_candidate_for_guard<'b>(
23912390
&mut self,
23922391
block: BasicBlock,
@@ -2418,10 +2417,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
24182417
);
24192418
match binding.binding_mode.0 {
24202419
ByRef::No => {
2420+
// The arm binding will be by value, so for the guard binding
2421+
// just take a shared reference to the matched place.
24212422
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, binding.source);
24222423
self.cfg.push_assign(block, source_info, ref_for_guard, rvalue);
24232424
}
24242425
ByRef::Yes(mutbl) => {
2426+
// The arm binding will be by reference, so eagerly create it now.
24252427
let value_for_arm = self.storage_live_binding(
24262428
block,
24272429
binding.var_id,
@@ -2433,6 +2435,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
24332435
let rvalue =
24342436
Rvalue::Ref(re_erased, util::ref_pat_borrow_kind(mutbl), binding.source);
24352437
self.cfg.push_assign(block, source_info, value_for_arm, rvalue);
2438+
// For the guard binding, take a shared reference to that reference.
24362439
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, value_for_arm);
24372440
self.cfg.push_assign(block, source_info, ref_for_guard, rvalue);
24382441
}

0 commit comments

Comments
 (0)