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

@ -351,13 +351,11 @@ impl<'a> Resolver<'a> {
if !self.is_accessible_from(single_import.vis.get(), parent_scope.module) {
continue;
}
let module = match single_import.imported_module.get() {
Some(x) => x,
None => return Err((Undetermined, Weak::No)),
let Some(module) = single_import.imported_module.get() else {
return Err((Undetermined, Weak::No));
};
let ident = match single_import.kind {
ImportKind::Single { source, .. } => source,
_ => unreachable!(),
let ImportKind::Single { source: ident, .. } = single_import.kind else {
unreachable!();
};
match self.resolve_ident_in_module(
module,
@ -1347,12 +1345,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
}
fn resolve_glob_import(&mut self, import: &'b Import<'b>) {
let module = match import.imported_module.get().unwrap() {
ModuleOrUniformRoot::Module(module) => module,
_ => {
self.r.session.span_err(import.span, "cannot glob-import all possible crates");
return;
}
let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap() else {
self.r.session.span_err(import.span, "cannot glob-import all possible crates");
return;
};
if module.is_trait() {

View file

@ -1582,12 +1582,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
def_id: DefId,
span: Span,
) {
let variants = match self.collect_enum_ctors(def_id) {
Some(variants) => variants,
None => {
err.note("you might have meant to use one of the enum's variants");
return;
}
let Some(variants) = self.collect_enum_ctors(def_id) else {
err.note("you might have meant to use one of the enum's variants");
return;
};
let suggest_only_tuple_variants =

View file

@ -1748,10 +1748,7 @@ fn object_lifetime_defaults_for_item<'tcx>(
let param_def_id = tcx.hir().local_def_id(param.hir_id);
for predicate in generics.where_clause.predicates {
// Look for `type: ...` where clauses.
let data = match *predicate {
hir::WherePredicate::BoundPredicate(ref data) => data,
_ => continue,
};
let hir::WherePredicate::BoundPredicate(ref data) = *predicate else { continue };
// Ignore `for<'a> type: ...` as they can change what
// lifetimes mean (although we could "just" handle it).
@ -1976,12 +1973,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
fn check_uses_for_lifetimes_defined_by_scope(&mut self) {
let defined_by = match self.scope {
Scope::Binder { lifetimes, .. } => lifetimes,
_ => {
debug!("check_uses_for_lifetimes_defined_by_scope: not in a binder scope");
return;
}
let Scope::Binder { lifetimes: defined_by, .. } = self.scope else {
debug!("check_uses_for_lifetimes_defined_by_scope: not in a binder scope");
return;
};
let def_ids: Vec<_> = defined_by
@ -2636,9 +2630,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
smallvec![(def_id, smallvec![])];
let mut visited: FxHashSet<DefId> = FxHashSet::default();
loop {
let (def_id, bound_vars) = match stack.pop() {
Some(next) => next,
None => break None,
let Some((def_id, bound_vars)) = stack.pop() else {
break None;
};
// See issue #83753. If someone writes an associated type on a non-trait, just treat it as
// there being no supertrait HRTBs.
@ -2723,10 +2716,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
});
let output = match output {
Some(ty) => ty,
None => return,
};
let Some(output) = output else { return };
debug!("determine output");

View file

@ -3479,16 +3479,15 @@ impl<'a> Resolver<'a> {
let ident = Ident::with_dummy_span(sym::main);
let parent_scope = &ParentScope::module(module, self);
let name_binding = match self.resolve_ident_in_module(
let Ok(name_binding) = self.resolve_ident_in_module(
ModuleOrUniformRoot::Module(module),
ident,
ValueNS,
parent_scope,
false,
DUMMY_SP,
) {
Ok(name_binding) => name_binding,
_ => return,
) else {
return;
};
let res = name_binding.res();