mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Simplify NameClass::classify
This commit is contained in:
parent
37a87708ae
commit
a574434c3f
3 changed files with 102 additions and 116 deletions
|
@ -92,8 +92,8 @@ use hir_def::{
|
|||
expr::{LabelId, PatId},
|
||||
keys::{self, Key},
|
||||
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId,
|
||||
GenericDefId, ImplId, LifetimeParamId, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
|
||||
TypeParamId, UnionId, VariantId,
|
||||
GenericDefId, GenericParamId, ImplId, LifetimeParamId, ModuleId, StaticId, StructId, TraitId,
|
||||
TypeAliasId, TypeParamId, UnionId, VariantId,
|
||||
};
|
||||
use hir_expand::{name::AsName, AstId, HirFileId, MacroCallId, MacroDefId, MacroDefKind};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
@ -299,6 +299,23 @@ impl SourceToDefCtx<'_, '_> {
|
|||
dyn_map[keys::CONST_PARAM].get(&src).copied()
|
||||
}
|
||||
|
||||
pub(super) fn generic_param_to_def(
|
||||
&mut self,
|
||||
InFile { file_id, value }: InFile<ast::GenericParam>,
|
||||
) -> Option<GenericParamId> {
|
||||
match value {
|
||||
ast::GenericParam::ConstParam(it) => {
|
||||
self.const_param_to_def(InFile::new(file_id, it)).map(GenericParamId::ConstParamId)
|
||||
}
|
||||
ast::GenericParam::LifetimeParam(it) => self
|
||||
.lifetime_param_to_def(InFile::new(file_id, it))
|
||||
.map(GenericParamId::LifetimeParamId),
|
||||
ast::GenericParam::TypeParam(it) => {
|
||||
self.type_param_to_def(InFile::new(file_id, it)).map(GenericParamId::TypeParamId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn macro_to_def(&mut self, src: InFile<ast::Macro>) -> Option<MacroDefId> {
|
||||
let makro = self.dyn_map(src.as_ref()).and_then(|it| it[keys::MACRO].get(&src).copied());
|
||||
if let res @ Some(_) = makro {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue