mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
remove unreachable!()
This commit is contained in:
parent
835173d065
commit
19fbf2c16b
4 changed files with 18 additions and 15 deletions
|
@ -54,7 +54,7 @@ pub(crate) fn reference_definition(
|
|||
) -> 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 {
|
||||
Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)),
|
||||
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 src = hir::Source { file_id, ast };
|
||||
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) => {
|
||||
let src = hir::Source { file_id, ast: it };
|
||||
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) => {
|
||||
let src = hir::Source { file_id, ast: it };
|
||||
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) => {
|
||||
let src = hir::Source { file_id, ast: it };
|
||||
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) => {
|
||||
let src = hir::Source { file_id, ast: it };
|
||||
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) => {
|
||||
let src = hir::Source { file_id, ast: it };
|
||||
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) => {
|
||||
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() {
|
||||
Some(from_assoc_item(db, def.into()))
|
||||
} else {
|
||||
Some(from_module_def(db, def.into()))
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
}
|
||||
},
|
||||
ast::ConstDef(it) => {
|
||||
|
@ -74,7 +74,7 @@ pub(crate) fn classify_name(
|
|||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||
Some(from_assoc_item(db, def.into()))
|
||||
} else {
|
||||
Some(from_module_def(db, def.into()))
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
}
|
||||
},
|
||||
ast::TypeAliasDef(it) => {
|
||||
|
@ -83,7 +83,7 @@ pub(crate) fn classify_name(
|
|||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||
Some(from_assoc_item(db, def.into()))
|
||||
} else {
|
||||
Some(from_module_def(db, def.into()))
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
}
|
||||
},
|
||||
_ => None,
|
||||
|
@ -143,7 +143,7 @@ pub(crate) fn classify_name_ref(
|
|||
let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
|
||||
let resolved = analyzer.resolve_path(db, &path)?;
|
||||
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)),
|
||||
LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat),
|
||||
LocalBinding(Either::B(par)) => {
|
||||
|
|
|
@ -77,7 +77,11 @@ pub(super) fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDe
|
|||
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 (container, visibility) = match def {
|
||||
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::Union(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 }
|
||||
}
|
||||
|
|
|
@ -101,8 +101,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
|||
continue;
|
||||
}
|
||||
if let Some(name_ref) = node.as_node().cloned().and_then(ast::NameRef::cast) {
|
||||
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 {
|
||||
Some(Macro(_)) => "macro",
|
||||
Some(Field(_)) => "field",
|
||||
|
|
Loading…
Reference in a new issue