Skip to content

Commit

Permalink
Initialize a few variables directly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LingMan committed Jan 17, 2021
1 parent efdb859 commit 0a74e17
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0a74e17

Please sign in to comment.