Skip to content

Commit b4defec

Browse files
authored
Rollup merge of #81105 - LingMan:init_directly, r=nagisa
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.
2 parents d3ff9ac + 0a74e17 commit b4defec

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

compiler/rustc_resolve/src/late/lifetimes.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1398,12 +1398,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13981398
fn lifetime_deletion_span(&self, name: Ident, generics: &hir::Generics<'_>) -> Option<Span> {
13991399
generics.params.iter().enumerate().find_map(|(i, param)| {
14001400
if param.name.ident() == name {
1401-
let mut in_band = false;
1402-
if let hir::GenericParamKind::Lifetime { kind } = param.kind {
1403-
if let hir::LifetimeParamKind::InBand = kind {
1404-
in_band = true;
1405-
}
1406-
}
1401+
let in_band = matches!(
1402+
param.kind,
1403+
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::InBand }
1404+
);
14071405
if in_band {
14081406
Some(param.span)
14091407
} else if generics.params.len() == 1 {
@@ -1433,12 +1431,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14331431
lifetime: &hir::Lifetime,
14341432
) {
14351433
let name = lifetime.name.ident();
1436-
let mut remove_decl = None;
1437-
if let Some(parent_def_id) = self.tcx.parent(def_id) {
1438-
if let Some(generics) = self.tcx.hir().get_generics(parent_def_id) {
1439-
remove_decl = self.lifetime_deletion_span(name, generics);
1440-
}
1441-
}
1434+
let remove_decl = self
1435+
.tcx
1436+
.parent(def_id)
1437+
.and_then(|parent_def_id| self.tcx.hir().get_generics(parent_def_id))
1438+
.and_then(|generics| self.lifetime_deletion_span(name, generics));
14421439

14431440
let mut remove_use = None;
14441441
let mut elide_use = None;

0 commit comments

Comments
 (0)