Skip to content

Commit 9915103

Browse files
committed
Simplify
1 parent 536ed7c commit 9915103

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

crates/hir/src/source_analyzer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,12 @@ impl SourceAnalyzer {
291291
}
292292
}
293293

294-
if let Some(pat) = parent()
295-
.and_then(ast::RecordPat::cast)
296-
.map(ast::Pat::from)
297-
.or_else(|| parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from))
298-
{
294+
let record_pat = parent().and_then(ast::RecordPat::cast).map(ast::Pat::from);
295+
let tuple_struct_pat = || parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from);
296+
if let Some(pat) = record_pat.or_else(tuple_struct_pat) {
299297
let pat_id = self.pat_id(&pat)?;
300-
if let Some(VariantId::EnumVariantId(variant)) =
301-
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
302-
{
298+
let variant_res_for_pat = self.infer.as_ref()?.variant_resolution_for_pat(pat_id);
299+
if let Some(VariantId::EnumVariantId(variant)) = variant_res_for_pat {
303300
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
304301
}
305302
}
@@ -335,6 +332,9 @@ impl SourceAnalyzer {
335332
}
336333
}
337334
} else if is_path_of_attr {
335+
// Case where we are resolving the final path segment of a path in an attribute
336+
// in this case we have to check for inert/builtin attributes and tools and prioritize
337+
// resolution of attributes over other namesapces
338338
let name_ref = path.as_single_name_ref();
339339
let builtin =
340340
name_ref.as_ref().map(ast::NameRef::text).as_deref().and_then(BuiltinAttr::by_name);

crates/ide_db/src/defs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl NameRefClass {
447447
}
448448
}
449449

450-
if let Some(path) = name_ref.syntax().ancestors().find_map(ast::Path::cast) {
450+
if let Some(path) = ast::PathSegment::cast(parent.clone()).map(|it| it.parent_path()) {
451451
if path.qualifier().is_none() {
452452
if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
453453
// Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment

0 commit comments

Comments
 (0)