diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-20 00:37:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-20 00:37:34 +0100 |
| commit | f2d6770f779051f1f5a28451b68784d2103bca32 (patch) | |
| tree | 90ba27b14c38a8ff603d9aef8642a16b58a7f52d /compiler/rustc_resolve | |
| parent | 7ca1c48bbb6d300bda665a59b7ad226bc71e7be9 (diff) | |
| parent | 2ef8af66196f7cc270a0532ea989f2fc6bc6885d (diff) | |
| download | rust-f2d6770f779051f1f5a28451b68784d2103bca32.tar.gz rust-f2d6770f779051f1f5a28451b68784d2103bca32.zip | |
Rollup merge of #94146 - est31:let_else, r=cjgillot
Adopt let else in more places Continuation of #89933, #91018, #91481, #93046, #93590, #94011. I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
Diffstat (limited to 'compiler/rustc_resolve')
| -rw-r--r-- | compiler/rustc_resolve/src/imports.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late/lifetimes.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 7 |
4 files changed, 20 insertions, 39 deletions
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index a8c2a5e1424..5e21161f2e0 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -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() { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 129db038f4a..f20cf29cc89 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -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 = diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 3bea95fa1d5..2f0ad60709d 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -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"); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 28d8d9247ac..04b0a18b12b 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -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(); |
