Skip to content

Commit 6afd0f5

Browse files
committed
Refactor: unwrap Option once in the beginning of closure
1 parent 43fb956 commit 6afd0f5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

crates/hir/src/source_analyzer.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ impl SourceAnalyzer {
487487

488488
let mut prefer_value_ns = false;
489489
let resolved = (|| {
490+
let infer = self.infer.as_deref()?;
490491
if let Some(path_expr) = parent().and_then(ast::PathExpr::cast) {
491492
let expr_id = self.expr_id(db, &path_expr.into())?;
492-
let infer = self.infer.as_ref()?;
493493
if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
494494
let assoc = match assoc {
495495
AssocItemId::FunctionId(f_in_trait) => {
@@ -520,18 +520,18 @@ impl SourceAnalyzer {
520520
prefer_value_ns = true;
521521
} else if let Some(path_pat) = parent().and_then(ast::PathPat::cast) {
522522
let pat_id = self.pat_id(&path_pat.into())?;
523-
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
523+
if let Some(assoc) = infer.assoc_resolutions_for_pat(pat_id) {
524524
return Some(PathResolution::Def(AssocItem::from(assoc).into()));
525525
}
526526
if let Some(VariantId::EnumVariantId(variant)) =
527-
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
527+
infer.variant_resolution_for_pat(pat_id)
528528
{
529529
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
530530
}
531531
} else if let Some(rec_lit) = parent().and_then(ast::RecordExpr::cast) {
532532
let expr_id = self.expr_id(db, &rec_lit.into())?;
533533
if let Some(VariantId::EnumVariantId(variant)) =
534-
self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
534+
infer.variant_resolution_for_expr(expr_id)
535535
{
536536
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
537537
}
@@ -541,8 +541,7 @@ impl SourceAnalyzer {
541541
|| parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from);
542542
if let Some(pat) = record_pat.or_else(tuple_struct_pat) {
543543
let pat_id = self.pat_id(&pat)?;
544-
let variant_res_for_pat =
545-
self.infer.as_ref()?.variant_resolution_for_pat(pat_id);
544+
let variant_res_for_pat = infer.variant_resolution_for_pat(pat_id);
546545
if let Some(VariantId::EnumVariantId(variant)) = variant_res_for_pat {
547546
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
548547
}

0 commit comments

Comments
 (0)