1
Fork 0

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](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/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:
bors 2023-10-15 13:23:55 +00:00
commit a48396984a
207 changed files with 3121 additions and 2229 deletions

View file

@ -104,7 +104,7 @@ impl CanonicalVarValues<'_> {
} else {
// It's ok if this region var isn't unique
}
},
}
ty::GenericArgKind::Type(ty) => {
if let ty::Bound(ty::INNERMOST, bt) = *ty.kind()
&& var == bt.var

View file

@ -244,7 +244,9 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
if !(inherited_effective_vis_at_prev_level == inherited_effective_vis_at_level
&& level != l)
{
calculated_effective_vis = if let Some(max_vis) = max_vis && !max_vis.is_at_least(inherited_effective_vis_at_level, tcx) {
calculated_effective_vis = if let Some(max_vis) = max_vis
&& !max_vis.is_at_least(inherited_effective_vis_at_level, tcx)
{
max_vis
} else {
inherited_effective_vis_at_level

View file

@ -455,7 +455,9 @@ impl<'tcx> TyCtxt<'tcx> {
// If this item was previously part of a now-stabilized feature which is still
// active (i.e. the user hasn't removed the attribute for the stabilized feature
// yet) then allow use of this item.
if let Some(implied_by) = implied_by && self.features().declared(implied_by) {
if let Some(implied_by) = implied_by
&& self.features().declared(implied_by)
{
return EvalResult::Allow;
}

View file

@ -315,7 +315,9 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
self.ptrs.insert_presorted(dest_ptrs.into());
}
if Prov::OFFSET_IS_ADDR {
if let Some(dest_bytes) = copy.dest_bytes && !dest_bytes.is_empty() {
if let Some(dest_bytes) = copy.dest_bytes
&& !dest_bytes.is_empty()
{
self.bytes.get_or_insert_with(Box::default).insert_presorted(dest_bytes.into());
}
} else {

View file

@ -99,7 +99,9 @@ impl<'tcx> MirPatch<'tcx> {
}
pub fn terminate_block(&mut self, reason: UnwindTerminateReason) -> BasicBlock {
if let Some((cached_bb, cached_reason)) = self.terminate_block && reason == cached_reason {
if let Some((cached_bb, cached_reason)) = self.terminate_block
&& reason == cached_reason
{
return cached_bb;
}

View file

@ -1126,7 +1126,11 @@ impl<'tcx> TyCtxt<'tcx> {
{
v.visit_ty(alias_ty);
if !v.0.is_empty() {
return Some((v.0, alias_generics.span, alias_generics.span_for_lifetime_suggestion()));
return Some((
v.0,
alias_generics.span,
alias_generics.span_for_lifetime_suggestion(),
));
}
}
return None;

View file

@ -494,7 +494,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
let parent = self.tcx.parent(def_id);
let parent_ty = self.tcx.type_of(parent).instantiate_identity();
if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent)
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) =
*parent_ty.kind()
&& parent_opaque_def_id == def_id
{
// Okay
@ -577,8 +578,10 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
Alias(Opaque, AliasTy { def_id, .. }) => {
let parent = self.tcx.parent(def_id);
let parent_ty = self.tcx.type_of(parent).instantiate_identity();
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy =
self.tcx.def_kind(parent)
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) =
*parent_ty.kind()
&& parent_opaque_def_id == def_id
{
t

View file

@ -253,7 +253,13 @@ impl<'tcx> Ty<'tcx> {
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
ty::Alias(ty::Projection | ty::Inherent, _) => "associated type".into(),
ty::Param(p) => format!("type parameter `{p}`").into(),
ty::Alias(ty::Opaque, ..) => if tcx.ty_is_opaque_future(self) { "future".into() } else { "opaque type".into() },
ty::Alias(ty::Opaque, ..) => {
if tcx.ty_is_opaque_future(self) {
"future".into()
} else {
"opaque type".into()
}
}
ty::Error(_) => "type error".into(),
_ => {
let width = tcx.sess.diagnostic_width();

View file

@ -868,7 +868,7 @@ where
{
let metadata = tcx.normalize_erasing_regions(
cx.param_env(),
Ty::new_projection(tcx,metadata_def_id, [pointee]),
Ty::new_projection(tcx, metadata_def_id, [pointee]),
);
// Map `Metadata = DynMetadata<dyn Trait>` back to a vtable, since it

View file

@ -319,8 +319,7 @@ pub trait PrettyPrinter<'tcx>:
&& let DefPathData::TypeNs(_) = key.disambiguated_data.data
&& Some(*visible_parent) != actual_parent
{
this
.tcx()
this.tcx()
// FIXME(typed_def_id): Further propagate ModDefId
.module_children(ModDefId::new_unchecked(*visible_parent))
.iter()
@ -359,8 +358,14 @@ pub trait PrettyPrinter<'tcx>:
// the parent type in the path. For example, `Iterator::Item`.
self.write_str(get_local_name(&self, symbol, parent, parent_key).as_str())?;
self.write_str("::")?;
} else if let DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait
| DefKind::TyAlias | DefKind::Fn | DefKind::Const | DefKind::Static(_) = kind
} else if let DefKind::Struct
| DefKind::Union
| DefKind::Enum
| DefKind::Trait
| DefKind::TyAlias
| DefKind::Fn
| DefKind::Const
| DefKind::Static(_) = kind
{
} else {
// If not covered above, like for example items out of `impl` blocks, fallback.
@ -1119,8 +1124,10 @@ pub trait PrettyPrinter<'tcx>:
}
if self.tcx().features().return_type_notation
&& let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = self.tcx().opt_rpitit_info(def_id)
&& let ty::Alias(_, alias_ty) = self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind()
&& let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) =
self.tcx().opt_rpitit_info(def_id)
&& let ty::Alias(_, alias_ty) =
self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind()
&& alias_ty.def_id == def_id
{
let num_args = self.tcx().generics_of(fn_def_id).count();
@ -1364,20 +1371,22 @@ pub trait PrettyPrinter<'tcx>:
// cause printing to enter an infinite recursion if the anon const is in the self type i.e.
// `impl<T: Default> Default for [T; 32 - 1 - 1 - 1] {`
// where we would try to print `<[T; /* print `constant#0` again */] as Default>::{constant#0}`
p!(write("{}::{}", self.tcx().crate_name(def.krate), self.tcx().def_path(def).to_string_no_crate_verbose()))
p!(write(
"{}::{}",
self.tcx().crate_name(def.krate),
self.tcx().def_path(def).to_string_no_crate_verbose()
))
}
}
defkind => bug!("`{:?}` has unexpected defkind {:?}", ct, defkind),
}
}
ty::ConstKind::Infer(infer_ct) => {
match infer_ct {
ty::InferConst::Var(ct_vid)
if let Some(name) = self.const_infer_name(ct_vid) =>
p!(write("{}", name)),
_ => print_underscore!(),
ty::ConstKind::Infer(infer_ct) => match infer_ct {
ty::InferConst::Var(ct_vid) if let Some(name) = self.const_infer_name(ct_vid) => {
p!(write("{}", name))
}
}
_ => print_underscore!(),
},
ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)),
ty::ConstKind::Value(value) => {
return self.pretty_print_const_valtree(value, ct.ty(), print_ty);
@ -2246,7 +2255,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
| ty::RePlaceholder(ty::Placeholder {
bound: ty::BoundRegion { kind: br, .. }, ..
}) => {
if let ty::BrNamed(_, name) = br && br.is_named() {
if let ty::BrNamed(_, name) = br
&& br.is_named()
{
p!(write("{}", name));
return Ok(self);
}

View file

@ -1220,7 +1220,12 @@ pub struct AliasTy<'tcx> {
impl<'tcx> AliasTy<'tcx> {
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
match tcx.def_kind(self.def_id) {
DefKind::AssocTy if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def_id)) => ty::Inherent,
DefKind::AssocTy
if let DefKind::Impl { of_trait: false } =
tcx.def_kind(tcx.parent(self.def_id)) =>
{
ty::Inherent
}
DefKind::AssocTy => ty::Projection,
DefKind::OpaqueTy => ty::Opaque,
DefKind::TyAlias => ty::Weak,

View file

@ -217,7 +217,8 @@ fn find_item_ty_spans(
match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
if let Res::Def(kind, def_id) = path.res
&& !matches!(kind, DefKind::TyAlias) {
&& !matches!(kind, DefKind::TyAlias)
{
let check_params = def_id.as_local().map_or(true, |def_id| {
if def_id == needle {
spans.push(ty.span);
@ -227,8 +228,11 @@ fn find_item_ty_spans(
if check_params && let Some(args) = path.segments.last().unwrap().args {
let params_in_repr = tcx.params_in_repr(def_id);
// the domain size check is needed because the HIR may not be well-formed at this point
for (i, arg) in args.args.iter().enumerate().take(params_in_repr.domain_size()) {
if let hir::GenericArg::Type(ty) = arg && params_in_repr.contains(i as u32) {
for (i, arg) in args.args.iter().enumerate().take(params_in_repr.domain_size())
{
if let hir::GenericArg::Type(ty) = arg
&& params_in_repr.contains(i as u32)
{
find_item_ty_spans(tcx, ty, needle, spans, seen_representable);
}
}