Rollup merge of #93046 - est31:let_else, r=davidtwco

Use let_else in even more places

Followup of #89933, #91018, #91481.
This commit is contained in:
Matthias Krüger 2022-01-21 22:03:17 +01:00 committed by GitHub
commit ab19d4a515
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 134 additions and 140 deletions

View file

@ -1493,7 +1493,7 @@ fn generator_layout_and_saved_local_names<'tcx>(
let state_arg = mir::Local::new(1); let state_arg = mir::Local::new(1);
for var in &body.var_debug_info { for var in &body.var_debug_info {
let place = if let mir::VarDebugInfoContents::Place(p) = var.value { p } else { continue }; let mir::VarDebugInfoContents::Place(place) = &var.value else { continue };
if place.local != state_arg { if place.local != state_arg {
continue; continue;
} }

View file

@ -7,6 +7,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(let_else)]
#![feature(extern_types)] #![feature(extern_types)]
#![feature(nll)] #![feature(nll)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View file

@ -1,5 +1,6 @@
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(let_else)]
#![feature(internal_output_capture)] #![feature(internal_output_capture)]
#![feature(thread_spawn_unchecked)] #![feature(thread_spawn_unchecked)]
#![feature(nll)] #![feature(nll)]

View file

@ -717,7 +717,9 @@ impl<'a, 'b> ReplaceBodyWithLoop<'a, 'b> {
} }
fn should_ignore_fn(ret_ty: &ast::FnRetTy) -> bool { fn should_ignore_fn(ret_ty: &ast::FnRetTy) -> bool {
if let ast::FnRetTy::Ty(ref ty) = ret_ty { let ast::FnRetTy::Ty(ref ty) = ret_ty else {
return false;
};
fn involves_impl_trait(ty: &ast::Ty) -> bool { fn involves_impl_trait(ty: &ast::Ty) -> bool {
match ty.kind { match ty.kind {
ast::TyKind::ImplTrait(..) => true, ast::TyKind::ImplTrait(..) => true,
@ -734,8 +736,9 @@ impl<'a, 'b> ReplaceBodyWithLoop<'a, 'b> {
data.args.iter().any(|arg| match arg { data.args.iter().any(|arg| match arg {
ast::AngleBracketedArg::Arg(arg) => match arg { ast::AngleBracketedArg::Arg(arg) => match arg {
ast::GenericArg::Type(ty) => involves_impl_trait(ty), ast::GenericArg::Type(ty) => involves_impl_trait(ty),
ast::GenericArg::Lifetime(_) ast::GenericArg::Lifetime(_) | ast::GenericArg::Const(_) => {
| ast::GenericArg::Const(_) => false, false
}
}, },
ast::AngleBracketedArg::Constraint(c) => match c.kind { ast::AngleBracketedArg::Constraint(c) => match c.kind {
ast::AssocConstraintKind::Bound { .. } => true, ast::AssocConstraintKind::Bound { .. } => true,
@ -765,9 +768,6 @@ impl<'a, 'b> ReplaceBodyWithLoop<'a, 'b> {
} }
involves_impl_trait(ty) involves_impl_trait(ty)
} else {
false
}
} }
fn is_sig_const(sig: &ast::FnSig) -> bool { fn is_sig_const(sig: &ast::FnSig) -> bool {

View file

@ -1347,7 +1347,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let mut otherwise = None; let mut otherwise = None;
for match_pair in match_pairs { for match_pair in match_pairs {
if let PatKind::Or { ref pats } = *match_pair.pattern.kind { let PatKind::Or { ref pats } = &*match_pair.pattern.kind else {
bug!("Or-patterns should have been sorted to the end");
};
let or_span = match_pair.pattern.span; let or_span = match_pair.pattern.span;
let place = match_pair.place; let place = match_pair.place;
@ -1361,9 +1363,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fake_borrows, fake_borrows,
); );
}); });
} else {
bug!("Or-patterns should have been sorted to the end");
}
} }
let remainder_start = otherwise.unwrap_or_else(|| self.cfg.start_new_block()); let remainder_start = otherwise.unwrap_or_else(|| self.cfg.start_new_block());

View file

@ -88,11 +88,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
switch_ty: Ty<'tcx>, switch_ty: Ty<'tcx>,
options: &mut FxIndexMap<&'tcx ty::Const<'tcx>, u128>, options: &mut FxIndexMap<&'tcx ty::Const<'tcx>, u128>,
) -> bool { ) -> bool {
let match_pair = match candidate.match_pairs.iter().find(|mp| mp.place == *test_place) { let Some(match_pair) = candidate.match_pairs.iter().find(|mp| mp.place == *test_place) else {
Some(match_pair) => match_pair,
_ => {
return false; return false;
}
}; };
match *match_pair.pattern.kind { match *match_pair.pattern.kind {

View file

@ -1171,9 +1171,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
ident: Symbol, ident: Symbol,
kind: &AssocItemKind, kind: &AssocItemKind,
) -> Option<Symbol> { ) -> Option<Symbol> {
let module = if let Some((module, _)) = self.current_trait_ref { let Some((module, _)) = &self.current_trait_ref else {
module
} else {
return None; return None;
}; };
if ident == kw::Underscore { if ident == kw::Underscore {

View file

@ -1000,7 +1000,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// `fn foo<'a>() -> MyAnonTy<'a> { ... }` // `fn foo<'a>() -> MyAnonTy<'a> { ... }`
// ^ ^this gets resolved in the current scope // ^ ^this gets resolved in the current scope
for lifetime in lifetimes { for lifetime in lifetimes {
if let hir::GenericArg::Lifetime(lifetime) = lifetime { let hir::GenericArg::Lifetime(lifetime) = lifetime else {
continue
};
self.visit_lifetime(lifetime); self.visit_lifetime(lifetime);
// Check for predicates like `impl for<'a> Trait<impl OtherTrait<'a>>` // Check for predicates like `impl for<'a> Trait<impl OtherTrait<'a>>`
@ -1008,19 +1010,19 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// well-supported at the moment, so this doesn't work. // well-supported at the moment, so this doesn't work.
// In the future, this should be fixed and this error should be removed. // In the future, this should be fixed and this error should be removed.
let def = self.map.defs.get(&lifetime.hir_id).cloned(); let def = self.map.defs.get(&lifetime.hir_id).cloned();
if let Some(Region::LateBound(_, _, def_id, _)) = def { let Some(Region::LateBound(_, _, def_id, _)) = def else {
if let Some(def_id) = def_id.as_local() { continue
};
let Some(def_id) = def_id.as_local() else {
continue
};
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
// Ensure that the parent of the def is an item, not HRTB // Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().get_parent_node(hir_id); let parent_id = self.tcx.hir().get_parent_node(hir_id);
// FIXME(cjgillot) Can this check be replaced by // FIXME(cjgillot) Can this check be replaced by
// `let parent_is_item = parent_id.is_owner();`? // `let parent_is_item = parent_id.is_owner();`?
let parent_is_item = let parent_is_item = if let Some(parent_def_id) = parent_id.as_owner() {
if let Some(parent_def_id) = parent_id.as_owner() { matches!(self.tcx.hir().krate().owners.get(parent_def_id), Some(Some(_)),)
matches!(
self.tcx.hir().krate().owners.get(parent_def_id),
Some(Some(_)),
)
} else { } else {
false false
}; };
@ -1039,9 +1041,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.uninsert_lifetime_on_error(lifetime, def.unwrap()); self.uninsert_lifetime_on_error(lifetime, def.unwrap());
} }
} }
}
}
}
// We want to start our early-bound indices at the end of the parent scope, // We want to start our early-bound indices at the end of the parent scope,
// not including any parent `impl Trait`s. // not including any parent `impl Trait`s.

View file

@ -840,7 +840,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}; };
for refs_remaining in 0..refs_number { for refs_remaining in 0..refs_number {
if let ty::Ref(_, inner_ty, _) = suggested_ty.kind() { let ty::Ref(_, inner_ty, _) = suggested_ty.kind() else {
break;
};
suggested_ty = inner_ty; suggested_ty = inner_ty;
let new_obligation = self.mk_trait_obligation_with_new_self_ty( let new_obligation = self.mk_trait_obligation_with_new_self_ty(
@ -872,9 +874,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
); );
break; break;
} }
} else {
break;
}
} }
} }
} }