mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Simplify
This commit is contained in:
parent
536ed7c451
commit
9915103c9e
2 changed files with 9 additions and 9 deletions
|
@ -291,15 +291,12 @@ impl SourceAnalyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(pat) = parent()
|
let record_pat = parent().and_then(ast::RecordPat::cast).map(ast::Pat::from);
|
||||||
.and_then(ast::RecordPat::cast)
|
let tuple_struct_pat = || parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from);
|
||||||
.map(ast::Pat::from)
|
if let Some(pat) = record_pat.or_else(tuple_struct_pat) {
|
||||||
.or_else(|| parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from))
|
|
||||||
{
|
|
||||||
let pat_id = self.pat_id(&pat)?;
|
let pat_id = self.pat_id(&pat)?;
|
||||||
if let Some(VariantId::EnumVariantId(variant)) =
|
let variant_res_for_pat = self.infer.as_ref()?.variant_resolution_for_pat(pat_id);
|
||||||
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
|
if let Some(VariantId::EnumVariantId(variant)) = variant_res_for_pat {
|
||||||
{
|
|
||||||
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
|
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,6 +332,9 @@ impl SourceAnalyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if is_path_of_attr {
|
} else if is_path_of_attr {
|
||||||
|
// Case where we are resolving the final path segment of a path in an attribute
|
||||||
|
// in this case we have to check for inert/builtin attributes and tools and prioritize
|
||||||
|
// resolution of attributes over other namesapces
|
||||||
let name_ref = path.as_single_name_ref();
|
let name_ref = path.as_single_name_ref();
|
||||||
let builtin =
|
let builtin =
|
||||||
name_ref.as_ref().map(ast::NameRef::text).as_deref().and_then(BuiltinAttr::by_name);
|
name_ref.as_ref().map(ast::NameRef::text).as_deref().and_then(BuiltinAttr::by_name);
|
||||||
|
|
|
@ -447,7 +447,7 @@ impl NameRefClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path) = name_ref.syntax().ancestors().find_map(ast::Path::cast) {
|
if let Some(path) = ast::PathSegment::cast(parent.clone()).map(|it| it.parent_path()) {
|
||||||
if path.qualifier().is_none() {
|
if path.qualifier().is_none() {
|
||||||
if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
|
if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
|
||||||
// Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment
|
// Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue