1
Fork 0

Adopt let else in more places

This commit is contained in:
est31 2022-02-19 00:48:49 +01:00
parent b8c56fa8c3
commit 2ef8af6619
132 changed files with 539 additions and 881 deletions

View file

@ -1318,9 +1318,8 @@ impl CheckAttrVisitor<'_> {
return false;
}
let list = match attr.meta_item_list() {
None => return false,
Some(it) => it,
let Some(list) = attr.meta_item_list() else {
return false;
};
if matches!(&list[..], &[NestedMetaItem::Literal(Lit { kind: LitKind::Int(..), .. })]) {
@ -1352,18 +1351,16 @@ impl CheckAttrVisitor<'_> {
return false;
}
let list = match attr.meta_item_list() {
let Some(list) = attr.meta_item_list() else {
// The attribute form is validated on AST.
None => return false,
Some(it) => it,
return false;
};
let (decl, generics) = match item {
Some(ItemLike::Item(Item {
kind: ItemKind::Fn(FnSig { decl, .. }, generics, _),
..
})) => (decl, generics),
_ => bug!("should be a function item"),
let Some(ItemLike::Item(Item {
kind: ItemKind::Fn(FnSig { decl, .. }, generics, _),
..
})) = item else {
bug!("should be a function item");
};
for param in generics.params {

View file

@ -35,10 +35,7 @@ struct ExprVisitor<'tcx> {
/// If the type is `Option<T>`, it will return `T`, otherwise
/// the type itself. Works on most `Option`-like types.
fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
let (def, substs) = match *ty.kind() {
ty::Adt(def, substs) => (def, substs),
_ => return ty,
};
let ty::Adt(def, substs) = *ty.kind() else { return ty };
if def.variants.len() == 2 && !def.repr.c() && def.repr.int.is_none() {
let data_idx;
@ -202,18 +199,15 @@ impl<'tcx> ExprVisitor<'tcx> {
}
_ => None,
};
let asm_ty = match asm_ty {
Some(asm_ty) => asm_ty,
None => {
let msg = &format!("cannot use value of type `{}` for inline assembly", ty);
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
err.note(
"only integers, floats, SIMD vectors, pointers and function pointers \
can be used as arguments for inline assembly",
);
err.emit();
return None;
}
let Some(asm_ty) = asm_ty else {
let msg = &format!("cannot use value of type `{}` for inline assembly", ty);
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
err.note(
"only integers, floats, SIMD vectors, pointers and function pointers \
can be used as arguments for inline assembly",
);
err.emit();
return None;
};
// Check that the type implements Copy. The only case where this can
@ -260,27 +254,24 @@ impl<'tcx> ExprVisitor<'tcx> {
let asm_arch = self.tcx.sess.asm_arch.unwrap();
let reg_class = reg.reg_class();
let supported_tys = reg_class.supported_types(asm_arch);
let feature = match supported_tys.iter().find(|&&(t, _)| t == asm_ty) {
Some((_, feature)) => feature,
None => {
let msg = &format!("type `{}` cannot be used with this register class", ty);
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
let supported_tys: Vec<_> =
supported_tys.iter().map(|(t, _)| t.to_string()).collect();
err.note(&format!(
"register class `{}` supports these types: {}",
reg_class.name(),
supported_tys.join(", "),
let Some((_, feature)) = supported_tys.iter().find(|&&(t, _)| t == asm_ty) else {
let msg = &format!("type `{}` cannot be used with this register class", ty);
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
let supported_tys: Vec<_> =
supported_tys.iter().map(|(t, _)| t.to_string()).collect();
err.note(&format!(
"register class `{}` supports these types: {}",
reg_class.name(),
supported_tys.join(", "),
));
if let Some(suggest) = reg_class.suggest_class(asm_arch, asm_ty) {
err.help(&format!(
"consider using the `{}` register class instead",
suggest.name()
));
if let Some(suggest) = reg_class.suggest_class(asm_arch, asm_ty) {
err.help(&format!(
"consider using the `{}` register class instead",
suggest.name()
));
}
err.emit();
return Some(asm_ty);
}
err.emit();
return Some(asm_ty);
};
// Check whether the selected type requires a target feature. Note that

View file

@ -1430,9 +1430,8 @@ impl<'tcx> Liveness<'_, 'tcx> {
}
fn warn_about_unused_upvars(&self, entry_ln: LiveNode) {
let closure_min_captures = match self.closure_min_captures {
None => return,
Some(closure_min_captures) => closure_min_captures,
let Some(closure_min_captures) = self.closure_min_captures else {
return;
};
// If closure_min_captures is Some(), upvars must be Some() too.

View file

@ -354,9 +354,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
let tcx = self.tcx;
self.worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id));
let trait_def_id = match trait_ref.path.res {
Res::Def(DefKind::Trait, def_id) => def_id,
_ => unreachable!(),
let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res else {
unreachable!();
};
if !trait_def_id.is_local() {

View file

@ -756,9 +756,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
return;
}
let cnum = match self.tcx.extern_mod_stmt_cnum(item.def_id) {
Some(cnum) => cnum,
None => return,
let Some(cnum) = self.tcx.extern_mod_stmt_cnum(item.def_id) else {
return;
};
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span, None);
@ -808,10 +807,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
// so semi-randomly perform it here in stability.rs
hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => {
let ty = self.tcx.type_of(item.def_id);
let (adt_def, substs) = match ty.kind() {
ty::Adt(adt_def, substs) => (adt_def, substs),
_ => bug!(),
};
let ty::Adt(adt_def, substs) = ty.kind() else { bug!() };
// Non-`Copy` fields are unstable, except for `ManuallyDrop`.
let param_env = self.tcx.param_env(item.def_id);