remove unreachable!()
This commit is contained in:
@@ -54,7 +54,7 @@ pub(crate) fn reference_definition(
|
|||||||
) -> ReferenceResult {
|
) -> ReferenceResult {
|
||||||
use self::ReferenceResult::*;
|
use self::ReferenceResult::*;
|
||||||
|
|
||||||
let name_kind = classify_name_ref(db, file_id, &name_ref).and_then(|d| Some(d.item));
|
let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.item);
|
||||||
match name_kind {
|
match name_kind {
|
||||||
Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)),
|
Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)),
|
||||||
Some(Field(field)) => return Exact(NavigationTarget::from_field(db, field)),
|
Some(Field(field)) => return Exact(NavigationTarget::from_field(db, field)),
|
||||||
|
|||||||
@@ -32,32 +32,32 @@ pub(crate) fn classify_name(
|
|||||||
let ast = hir::ModuleSource::Module(it);
|
let ast = hir::ModuleSource::Module(it);
|
||||||
let src = hir::Source { file_id, ast };
|
let src = hir::Source { file_id, ast };
|
||||||
let def = hir::Module::from_definition(db, src)?;
|
let def = hir::Module::from_definition(db, src)?;
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
},
|
},
|
||||||
ast::StructDef(it) => {
|
ast::StructDef(it) => {
|
||||||
let src = hir::Source { file_id, ast: it };
|
let src = hir::Source { file_id, ast: it };
|
||||||
let def = hir::Struct::from_source(db, src)?;
|
let def = hir::Struct::from_source(db, src)?;
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
},
|
},
|
||||||
ast::EnumDef(it) => {
|
ast::EnumDef(it) => {
|
||||||
let src = hir::Source { file_id, ast: it };
|
let src = hir::Source { file_id, ast: it };
|
||||||
let def = hir::Enum::from_source(db, src)?;
|
let def = hir::Enum::from_source(db, src)?;
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
},
|
},
|
||||||
ast::TraitDef(it) => {
|
ast::TraitDef(it) => {
|
||||||
let src = hir::Source { file_id, ast: it };
|
let src = hir::Source { file_id, ast: it };
|
||||||
let def = hir::Trait::from_source(db, src)?;
|
let def = hir::Trait::from_source(db, src)?;
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
},
|
},
|
||||||
ast::StaticDef(it) => {
|
ast::StaticDef(it) => {
|
||||||
let src = hir::Source { file_id, ast: it };
|
let src = hir::Source { file_id, ast: it };
|
||||||
let def = hir::Static::from_source(db, src)?;
|
let def = hir::Static::from_source(db, src)?;
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
},
|
},
|
||||||
ast::EnumVariant(it) => {
|
ast::EnumVariant(it) => {
|
||||||
let src = hir::Source { file_id, ast: it };
|
let src = hir::Source { file_id, ast: it };
|
||||||
let def = hir::EnumVariant::from_source(db, src)?;
|
let def = hir::EnumVariant::from_source(db, src)?;
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
},
|
},
|
||||||
ast::FnDef(it) => {
|
ast::FnDef(it) => {
|
||||||
let src = hir::Source { file_id, ast: it };
|
let src = hir::Source { file_id, ast: it };
|
||||||
@@ -65,7 +65,7 @@ pub(crate) fn classify_name(
|
|||||||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||||
Some(from_assoc_item(db, def.into()))
|
Some(from_assoc_item(db, def.into()))
|
||||||
} else {
|
} else {
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ast::ConstDef(it) => {
|
ast::ConstDef(it) => {
|
||||||
@@ -74,7 +74,7 @@ pub(crate) fn classify_name(
|
|||||||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||||
Some(from_assoc_item(db, def.into()))
|
Some(from_assoc_item(db, def.into()))
|
||||||
} else {
|
} else {
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ast::TypeAliasDef(it) => {
|
ast::TypeAliasDef(it) => {
|
||||||
@@ -83,7 +83,7 @@ pub(crate) fn classify_name(
|
|||||||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||||
Some(from_assoc_item(db, def.into()))
|
Some(from_assoc_item(db, def.into()))
|
||||||
} else {
|
} else {
|
||||||
Some(from_module_def(db, def.into()))
|
Some(from_module_def(db, def.into(), None))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
@@ -143,7 +143,7 @@ pub(crate) fn classify_name_ref(
|
|||||||
let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
|
let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
|
||||||
let resolved = analyzer.resolve_path(db, &path)?;
|
let resolved = analyzer.resolve_path(db, &path)?;
|
||||||
match resolved {
|
match resolved {
|
||||||
Def(def) => Some(from_module_def(db, def)),
|
Def(def) => Some(from_module_def(db, def, Some(container))),
|
||||||
AssocItem(item) => Some(from_assoc_item(db, item)),
|
AssocItem(item) => Some(from_assoc_item(db, item)),
|
||||||
LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat),
|
LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat),
|
||||||
LocalBinding(Either::B(par)) => {
|
LocalBinding(Either::B(par)) => {
|
||||||
|
|||||||
@@ -77,7 +77,11 @@ pub(super) fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDe
|
|||||||
NameDefinition { item, container, visibility }
|
NameDefinition { item, container, visibility }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn from_module_def(db: &RootDatabase, def: ModuleDef) -> NameDefinition {
|
pub(super) fn from_module_def(
|
||||||
|
db: &RootDatabase,
|
||||||
|
def: ModuleDef,
|
||||||
|
module: Option<Module>,
|
||||||
|
) -> NameDefinition {
|
||||||
let item = NameKind::Def(def);
|
let item = NameKind::Def(def);
|
||||||
let (container, visibility) = match def {
|
let (container, visibility) = match def {
|
||||||
ModuleDef::Module(it) => {
|
ModuleDef::Module(it) => {
|
||||||
@@ -98,7 +102,7 @@ pub(super) fn from_module_def(db: &RootDatabase, def: ModuleDef) -> NameDefiniti
|
|||||||
ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).ast.visibility()),
|
ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).ast.visibility()),
|
||||||
ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).ast.visibility()),
|
ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).ast.visibility()),
|
||||||
ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).ast.visibility()),
|
ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).ast.visibility()),
|
||||||
ModuleDef::BuiltinType(..) => unreachable!(),
|
ModuleDef::BuiltinType(..) => (module.unwrap(), None),
|
||||||
};
|
};
|
||||||
NameDefinition { item, container, visibility }
|
NameDefinition { item, container, visibility }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,8 +101,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(name_ref) = node.as_node().cloned().and_then(ast::NameRef::cast) {
|
if let Some(name_ref) = node.as_node().cloned().and_then(ast::NameRef::cast) {
|
||||||
let name_kind =
|
let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.item);
|
||||||
classify_name_ref(db, file_id, &name_ref).and_then(|d| Some(d.item));
|
|
||||||
match name_kind {
|
match name_kind {
|
||||||
Some(Macro(_)) => "macro",
|
Some(Macro(_)) => "macro",
|
||||||
Some(Field(_)) => "field",
|
Some(Field(_)) => "field",
|
||||||
|
|||||||
Reference in New Issue
Block a user