Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates
Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped).
This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](374997516
), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else.
I will also add this commit to the ignore list after it has landed.
The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree.
```
~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates
~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif
```
cc `@rust-lang/rustfmt`
r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :>
cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
This commit is contained in:
commit
a48396984a
207 changed files with 3121 additions and 2229 deletions
|
@ -97,13 +97,15 @@ impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
|
|||
// so emitting a lint would be redundant.
|
||||
if !lhs.projection.is_empty() {
|
||||
if let Some(def_id) = self.is_const_item_without_destructor(lhs.local)
|
||||
&& let Some((lint_root, span, item)) = self.should_lint_const_item_usage(&lhs, def_id, loc) {
|
||||
self.tcx.emit_spanned_lint(
|
||||
CONST_ITEM_MUTATION,
|
||||
lint_root,
|
||||
span,
|
||||
errors::ConstMutate::Modify { konst: item }
|
||||
);
|
||||
&& let Some((lint_root, span, item)) =
|
||||
self.should_lint_const_item_usage(&lhs, def_id, loc)
|
||||
{
|
||||
self.tcx.emit_spanned_lint(
|
||||
CONST_ITEM_MUTATION,
|
||||
lint_root,
|
||||
span,
|
||||
errors::ConstMutate::Modify { konst: item },
|
||||
);
|
||||
}
|
||||
}
|
||||
// We are looking for MIR of the form:
|
||||
|
|
|
@ -46,9 +46,14 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
|
|||
// If we ever reach here it means that the generated derive
|
||||
// code is somehow doing an unaligned reference, which it
|
||||
// shouldn't do.
|
||||
span_bug!(self.source_info.span, "builtin derive created an unaligned reference");
|
||||
span_bug!(
|
||||
self.source_info.span,
|
||||
"builtin derive created an unaligned reference"
|
||||
);
|
||||
} else {
|
||||
self.tcx.sess.emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
|
||||
self.tcx
|
||||
.sess
|
||||
.emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -540,8 +540,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
&& let BlockCheckMode::UnsafeBlock(_) = block.rules
|
||||
{
|
||||
true
|
||||
}
|
||||
else if let Some(sig) = tcx.hir().fn_sig_by_hir_id(*id)
|
||||
} else if let Some(sig) = tcx.hir().fn_sig_by_hir_id(*id)
|
||||
&& sig.header.is_unsafe()
|
||||
{
|
||||
true
|
||||
|
|
|
@ -55,7 +55,9 @@ fn find_optimization_opportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Const
|
|||
|
||||
let mut locals_to_debuginfo = BitSet::new_empty(body.local_decls.len());
|
||||
for debuginfo in &body.var_debug_info {
|
||||
if let VarDebugInfoContents::Place(p) = debuginfo.value && let Some(l) = p.as_local() {
|
||||
if let VarDebugInfoContents::Place(p) = debuginfo.value
|
||||
&& let Some(l) = p.as_local()
|
||||
{
|
||||
locals_to_debuginfo.insert(l);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -684,7 +684,9 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
|
|||
impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
|
||||
self.super_operand(operand, location);
|
||||
if let Some(place) = operand.place() && let Some(value) = self.replace_with_const(place) {
|
||||
if let Some(place) = operand.place()
|
||||
&& let Some(value) = self.replace_with_const(place)
|
||||
{
|
||||
self.patch.before_effect.insert((location, place), value);
|
||||
}
|
||||
}
|
||||
|
@ -718,7 +720,10 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||
if let Rvalue::Use(Operand::Constant(c)) = rvalue
|
||||
&& let Const::Val(..) = c.const_
|
||||
{
|
||||
trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c);
|
||||
trace!(
|
||||
"skipping replace of Rvalue::Use({:?} because it is already a const",
|
||||
c
|
||||
);
|
||||
} else if let Some(operand) = self.replace_with_const(*place) {
|
||||
self.patch.assignments.insert(location, operand);
|
||||
}
|
||||
|
|
|
@ -627,9 +627,10 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||
}
|
||||
TerminatorKind::SwitchInt { ref discr, ref targets } => {
|
||||
if let Some(ref value) = self.eval_operand(&discr, location)
|
||||
&& let Some(value_const) = self.use_ecx(location, |this| this.ecx.read_scalar(value))
|
||||
&& let Ok(constant) = value_const.try_to_int()
|
||||
&& let Ok(constant) = constant.to_bits(constant.size())
|
||||
&& let Some(value_const) =
|
||||
self.use_ecx(location, |this| this.ecx.read_scalar(value))
|
||||
&& let Ok(constant) = value_const.try_to_int()
|
||||
&& let Ok(constant) = constant.to_bits(constant.size())
|
||||
{
|
||||
// We managed to evaluate the discriminant, so we know we only need to visit
|
||||
// one target.
|
||||
|
|
|
@ -168,14 +168,15 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
|
|||
&& self.storage_to_remove.contains(l)
|
||||
{
|
||||
stmt.make_nop();
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
self.super_statement(stmt, loc);
|
||||
|
||||
// Do not leave tautological assignments around.
|
||||
if let StatementKind::Assign(box (lhs, ref rhs)) = stmt.kind
|
||||
&& let Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs)) | Rvalue::CopyForDeref(rhs) = *rhs
|
||||
&& let Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs)) | Rvalue::CopyForDeref(rhs) =
|
||||
*rhs
|
||||
&& lhs == rhs
|
||||
{
|
||||
stmt.make_nop();
|
||||
|
|
|
@ -159,11 +159,12 @@ impl CoverageSpan {
|
|||
/// If the span is part of a macro, and the macro is visible (expands directly to the given
|
||||
/// body_span), returns the macro name symbol.
|
||||
pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> {
|
||||
if let Some(current_macro) = self.current_macro() && self
|
||||
.expn_span
|
||||
.parent_callsite()
|
||||
.unwrap_or_else(|| bug!("macro must have a parent"))
|
||||
.eq_ctxt(body_span)
|
||||
if let Some(current_macro) = self.current_macro()
|
||||
&& self
|
||||
.expn_span
|
||||
.parent_callsite()
|
||||
.unwrap_or_else(|| bug!("macro must have a parent"))
|
||||
.eq_ctxt(body_span)
|
||||
{
|
||||
return Some(current_macro);
|
||||
}
|
||||
|
@ -460,7 +461,9 @@ impl<'a> CoverageSpansGenerator<'a> {
|
|||
/// In either case, no more spans will match the span of `pending_dups`, so
|
||||
/// add the `pending_dups` if they don't overlap `curr`, and clear the list.
|
||||
fn check_pending_dups(&mut self) {
|
||||
if let Some(dup) = self.pending_dups.last() && dup.span != self.prev().span {
|
||||
if let Some(dup) = self.pending_dups.last()
|
||||
&& dup.span != self.prev().span
|
||||
{
|
||||
debug!(
|
||||
" SAME spans, but pending_dups are NOT THE SAME, so BCBs matched on \
|
||||
previous iteration, or prev started a new disjoint span"
|
||||
|
|
|
@ -319,7 +319,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
}
|
||||
|
||||
if let Some(local) = self.try_as_local(value, location)
|
||||
&& local != place.local // in case we had no projection to begin with.
|
||||
&& local != place.local
|
||||
// in case we had no projection to begin with.
|
||||
{
|
||||
*place = local.into();
|
||||
self.reused_locals.insert(local);
|
||||
|
|
|
@ -503,7 +503,9 @@ impl<'tcx> Inliner<'tcx> {
|
|||
self.tcx,
|
||||
ty::EarlyBinder::bind(&place.ty(callee_body, tcx).ty),
|
||||
);
|
||||
if ty.needs_drop(tcx, self.param_env) && let UnwindAction::Cleanup(unwind) = unwind {
|
||||
if ty.needs_drop(tcx, self.param_env)
|
||||
&& let UnwindAction::Cleanup(unwind) = unwind
|
||||
{
|
||||
work_list.push(unwind);
|
||||
}
|
||||
} else if callee_attrs.instruction_set != self.codegen_fn_attrs.instruction_set
|
||||
|
@ -842,7 +844,9 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
|
|||
TerminatorKind::Call { func: Operand::Constant(ref f), unwind, .. } => {
|
||||
let fn_ty =
|
||||
self.instance.instantiate_mir(tcx, ty::EarlyBinder::bind(&f.const_.ty()));
|
||||
self.cost += if let ty::FnDef(def_id, _) = *fn_ty.kind() && tcx.is_intrinsic(def_id) {
|
||||
self.cost += if let ty::FnDef(def_id, _) = *fn_ty.kind()
|
||||
&& tcx.is_intrinsic(def_id)
|
||||
{
|
||||
// Don't give intrinsics the extra penalty for calls
|
||||
INSTR_COST
|
||||
} else {
|
||||
|
|
|
@ -93,7 +93,9 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(new) = new && self.should_simplify(source_info, rvalue) {
|
||||
if let Some(new) = new
|
||||
&& self.should_simplify(source_info, rvalue)
|
||||
{
|
||||
*rvalue = new;
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +152,8 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
|
|||
*rvalue = Rvalue::Use(operand.clone());
|
||||
} else if *kind == CastKind::Transmute {
|
||||
// Transmuting an integer to another integer is just a signedness cast
|
||||
if let (ty::Int(int), ty::Uint(uint)) | (ty::Uint(uint), ty::Int(int)) = (operand_ty.kind(), cast_ty.kind())
|
||||
if let (ty::Int(int), ty::Uint(uint)) | (ty::Uint(uint), ty::Int(int)) =
|
||||
(operand_ty.kind(), cast_ty.kind())
|
||||
&& int.bit_width() == uint.bit_width()
|
||||
{
|
||||
// The width check isn't strictly necessary, as different widths
|
||||
|
@ -172,8 +175,15 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
|
|||
for (i, field) in variant.fields.iter().enumerate() {
|
||||
let field_ty = field.ty(self.tcx, args);
|
||||
if field_ty == *cast_ty {
|
||||
let place = place.project_deeper(&[ProjectionElem::Field(FieldIdx::from_usize(i), *cast_ty)], self.tcx);
|
||||
let operand = if operand.is_move() { Operand::Move(place) } else { Operand::Copy(place) };
|
||||
let place = place.project_deeper(
|
||||
&[ProjectionElem::Field(FieldIdx::from_usize(i), *cast_ty)],
|
||||
self.tcx,
|
||||
);
|
||||
let operand = if operand.is_move() {
|
||||
Operand::Move(place)
|
||||
} else {
|
||||
Operand::Copy(place)
|
||||
};
|
||||
*rvalue = Rvalue::Use(operand);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -162,37 +162,50 @@ fn remap_mir_for_const_eval_select<'tcx>(
|
|||
&& tcx.item_name(def_id) == sym::const_eval_select
|
||||
&& tcx.is_intrinsic(def_id) =>
|
||||
{
|
||||
let [tupled_args, called_in_const, called_at_rt]: [_; 3] = std::mem::take(args).try_into().unwrap();
|
||||
let [tupled_args, called_in_const, called_at_rt]: [_; 3] =
|
||||
std::mem::take(args).try_into().unwrap();
|
||||
let ty = tupled_args.ty(&body.local_decls, tcx);
|
||||
let fields = ty.tuple_fields();
|
||||
let num_args = fields.len();
|
||||
let func = if context == hir::Constness::Const { called_in_const } else { called_at_rt };
|
||||
let (method, place): (fn(Place<'tcx>) -> Operand<'tcx>, Place<'tcx>) = match tupled_args {
|
||||
Operand::Constant(_) => {
|
||||
// there is no good way of extracting a tuple arg from a constant (const generic stuff)
|
||||
// so we just create a temporary and deconstruct that.
|
||||
let local = body.local_decls.push(LocalDecl::new(ty, fn_span));
|
||||
bb.statements.push(Statement {
|
||||
source_info: SourceInfo::outermost(fn_span),
|
||||
kind: StatementKind::Assign(Box::new((local.into(), Rvalue::Use(tupled_args.clone())))),
|
||||
});
|
||||
(Operand::Move, local.into())
|
||||
}
|
||||
Operand::Move(place) => (Operand::Move, place),
|
||||
Operand::Copy(place) => (Operand::Copy, place),
|
||||
};
|
||||
let place_elems = place.projection;
|
||||
let arguments = (0..num_args).map(|x| {
|
||||
let mut place_elems = place_elems.to_vec();
|
||||
place_elems.push(ProjectionElem::Field(x.into(), fields[x]));
|
||||
let projection = tcx.mk_place_elems(&place_elems);
|
||||
let place = Place {
|
||||
local: place.local,
|
||||
projection,
|
||||
let func =
|
||||
if context == hir::Constness::Const { called_in_const } else { called_at_rt };
|
||||
let (method, place): (fn(Place<'tcx>) -> Operand<'tcx>, Place<'tcx>) =
|
||||
match tupled_args {
|
||||
Operand::Constant(_) => {
|
||||
// there is no good way of extracting a tuple arg from a constant (const generic stuff)
|
||||
// so we just create a temporary and deconstruct that.
|
||||
let local = body.local_decls.push(LocalDecl::new(ty, fn_span));
|
||||
bb.statements.push(Statement {
|
||||
source_info: SourceInfo::outermost(fn_span),
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
local.into(),
|
||||
Rvalue::Use(tupled_args.clone()),
|
||||
))),
|
||||
});
|
||||
(Operand::Move, local.into())
|
||||
}
|
||||
Operand::Move(place) => (Operand::Move, place),
|
||||
Operand::Copy(place) => (Operand::Copy, place),
|
||||
};
|
||||
method(place)
|
||||
}).collect();
|
||||
terminator.kind = TerminatorKind::Call { func, args: arguments, destination, target, unwind, call_source: CallSource::Misc, fn_span };
|
||||
let place_elems = place.projection;
|
||||
let arguments = (0..num_args)
|
||||
.map(|x| {
|
||||
let mut place_elems = place_elems.to_vec();
|
||||
place_elems.push(ProjectionElem::Field(x.into(), fields[x]));
|
||||
let projection = tcx.mk_place_elems(&place_elems);
|
||||
let place = Place { local: place.local, projection };
|
||||
method(place)
|
||||
})
|
||||
.collect();
|
||||
terminator.kind = TerminatorKind::Call {
|
||||
func,
|
||||
args: arguments,
|
||||
destination,
|
||||
target,
|
||||
unwind,
|
||||
call_source: CallSource::Misc,
|
||||
fn_span,
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -166,12 +166,16 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
|||
let [arg] = args.as_slice() else {
|
||||
span_bug!(terminator.source_info.span, "Wrong number of arguments");
|
||||
};
|
||||
let derefed_place =
|
||||
if let Some(place) = arg.place() && let Some(local) = place.as_local() {
|
||||
tcx.mk_place_deref(local.into())
|
||||
} else {
|
||||
span_bug!(terminator.source_info.span, "Only passing a local is supported");
|
||||
};
|
||||
let derefed_place = if let Some(place) = arg.place()
|
||||
&& let Some(local) = place.as_local()
|
||||
{
|
||||
tcx.mk_place_deref(local.into())
|
||||
} else {
|
||||
span_bug!(
|
||||
terminator.source_info.span,
|
||||
"Only passing a local is supported"
|
||||
);
|
||||
};
|
||||
// Add new statement at the end of the block that does the read, and patch
|
||||
// up the terminator.
|
||||
block.statements.push(Statement {
|
||||
|
@ -198,12 +202,16 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
|||
"Wrong number of arguments for write_via_move intrinsic",
|
||||
);
|
||||
};
|
||||
let derefed_place =
|
||||
if let Some(place) = ptr.place() && let Some(local) = place.as_local() {
|
||||
tcx.mk_place_deref(local.into())
|
||||
} else {
|
||||
span_bug!(terminator.source_info.span, "Only passing a local is supported");
|
||||
};
|
||||
let derefed_place = if let Some(place) = ptr.place()
|
||||
&& let Some(local) = place.as_local()
|
||||
{
|
||||
tcx.mk_place_deref(local.into())
|
||||
} else {
|
||||
span_bug!(
|
||||
terminator.source_info.span,
|
||||
"Only passing a local is supported"
|
||||
);
|
||||
};
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
|
|
|
@ -64,8 +64,7 @@ fn lower_slice_len_call<'tcx>(
|
|||
// make new RValue for Len
|
||||
let deref_arg = tcx.mk_place_deref(arg);
|
||||
let r_value = Rvalue::Len(deref_arg);
|
||||
let len_statement_kind =
|
||||
StatementKind::Assign(Box::new((*destination, r_value)));
|
||||
let len_statement_kind = StatementKind::Assign(Box::new((*destination, r_value)));
|
||||
let add_statement =
|
||||
Statement { kind: len_statement_kind, source_info: terminator.source_info };
|
||||
|
||||
|
|
|
@ -57,7 +57,9 @@ fn compute_slice_length<'tcx>(
|
|||
}
|
||||
// The length information is stored in the fat pointer, so we treat `operand` as a value.
|
||||
Rvalue::Use(operand) => {
|
||||
if let Some(rhs) = operand.place() && let Some(rhs) = rhs.as_local() {
|
||||
if let Some(rhs) = operand.place()
|
||||
&& let Some(rhs) = rhs.as_local()
|
||||
{
|
||||
slice_lengths[local] = slice_lengths[rhs];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,14 +210,17 @@ fn compute_replacement<'tcx>(
|
|||
// have been visited before.
|
||||
Rvalue::Use(Operand::Copy(place) | Operand::Move(place))
|
||||
| Rvalue::CopyForDeref(place) => {
|
||||
if let Some(rhs) = place.as_local() && ssa.is_ssa(rhs) {
|
||||
if let Some(rhs) = place.as_local()
|
||||
&& ssa.is_ssa(rhs)
|
||||
{
|
||||
let target = targets[rhs];
|
||||
// Only see through immutable reference and pointers, as we do not know yet if
|
||||
// mutable references are fully replaced.
|
||||
if !needs_unique && matches!(target, Value::Pointer(..)) {
|
||||
targets[local] = target;
|
||||
} else {
|
||||
targets[local] = Value::Pointer(tcx.mk_place_deref(rhs.into()), needs_unique);
|
||||
targets[local] =
|
||||
Value::Pointer(tcx.mk_place_deref(rhs.into()), needs_unique);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +368,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
|
|||
*place = Place::from(target.local).project_deeper(rest, self.tcx);
|
||||
self.any_replacement = true;
|
||||
} else {
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,10 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
|
|||
&& let ty = place_for_ty.ty(self.local_decls, self.tcx).ty
|
||||
&& self.known_to_be_zst(ty)
|
||||
&& self.tcx.consider_optimizing(|| {
|
||||
format!("RemoveZsts - Place: {:?} SourceInfo: {:?}", place_for_ty, statement.source_info)
|
||||
format!(
|
||||
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
|
||||
place_for_ty, statement.source_info
|
||||
)
|
||||
})
|
||||
{
|
||||
statement.make_nop();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue