diff options
| author | LingMan <LingMan@users.noreply.github.com> | 2021-01-17 02:07:37 +0100 |
|---|---|---|
| committer | LingMan <LingMan@users.noreply.github.com> | 2021-01-17 02:07:37 +0100 |
| commit | 0a74e17211b9ba95555790be3a0a16a562d74280 (patch) | |
| tree | 5100575a4a47ef62023e3ac255361720af201af5 | |
| parent | efdb859dcdf7077cf6b8c85af0ea8820c93bcbdf (diff) | |
| download | rust-0a74e17211b9ba95555790be3a0a16a562d74280.tar.gz rust-0a74e17211b9ba95555790be3a0a16a562d74280.zip | |
Initialize a few variables directly
Currently they are declared as `mut`, get initialized to a default value, and then possibly overwritten. By initializing to the final value directly, they don't need to be `mut` and it's clear that they don't get mutated elsewhere later on.
| -rw-r--r-- | compiler/rustc_resolve/src/late/lifetimes.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index aab5c3cf8f5..761e5242f87 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -1370,12 +1370,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { fn lifetime_deletion_span(&self, name: Ident, generics: &hir::Generics<'_>) -> Option<Span> { generics.params.iter().enumerate().find_map(|(i, param)| { if param.name.ident() == name { - let mut in_band = false; - if let hir::GenericParamKind::Lifetime { kind } = param.kind { - if let hir::LifetimeParamKind::InBand = kind { - in_band = true; - } - } + let in_band = matches!( + param.kind, + hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::InBand } + ); if in_band { Some(param.span) } else if generics.params.len() == 1 { @@ -1405,12 +1403,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { lifetime: &hir::Lifetime, ) { let name = lifetime.name.ident(); - let mut remove_decl = None; - if let Some(parent_def_id) = self.tcx.parent(def_id) { - if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) { - remove_decl = self.lifetime_deletion_span(name, generics); - } - } + let remove_decl = self + .tcx + .parent(def_id) + .and_then(|parent_def_id| self.tcx.hir().get_generics(parent_def_id)) + .and_then(|generics| self.lifetime_deletion_span(name, generics)); let mut remove_use = None; let mut elide_use = None; |
