1 //! Name resolution façade.
9 use indexmap::IndexMap;
10 use rustc_hash::FxHashSet;
11 use smallvec::SmallVec;
14 body::scope::{ExprScopes, ScopeId},
15 builtin_type::BuiltinType,
17 expr::{ExprId, LabelId, PatId},
18 generics::GenericParams,
20 item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
22 path::{ModPath, PathKind},
24 visibility::{RawVisibility, Visibility},
25 AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId,
26 FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
27 LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
28 TypeParamId, VariantId,
31 #[derive(Debug, Clone, Default)]
33 /// The stack of scopes, where the inner-most scope is the last item.
35 /// When using, you generally want to process the scopes in reverse order,
36 /// there's `scopes` *method* for that.
40 // FIXME how to store these best
41 #[derive(Debug, Clone)]
42 struct ModuleItemMap {
44 module_id: LocalModuleId,
47 #[derive(Debug, Clone)]
50 expr_scopes: Arc<ExprScopes>,
54 #[derive(Debug, Clone)]
56 /// All the items and imported names of a module
57 ModuleScope(ModuleItemMap),
58 /// Brings the generic parameters of an item into scope
59 GenericParams { def: GenericDefId, params: Interned<GenericParams> },
60 /// Brings `Self` in `impl` block into scope
62 /// Brings `Self` in enum, struct and union definitions into scope
68 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
71 GenericParam(TypeParamId),
74 // Yup, enum variants are added to the types ns, but any usage of variant as
76 EnumVariantId(EnumVariantId),
77 TypeAliasId(TypeAliasId),
78 BuiltinType(BuiltinType),
80 // Module belong to type ns, but the resolver is used when all module paths
81 // are fully resolved.
85 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
86 pub enum ResolveValueResult {
88 Partial(TypeNs, usize),
91 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
95 FunctionId(FunctionId),
99 EnumVariantId(EnumVariantId),
100 GenericParam(ConstParamId),
104 /// Resolve known trait from std, like `std::futures::Future`
105 pub fn resolve_known_trait(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<TraitId> {
106 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
108 ModuleDefId::TraitId(it) => Some(it),
113 /// Resolve known struct from std, like `std::boxed::Box`
114 pub fn resolve_known_struct(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<StructId> {
115 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
117 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it),
122 /// Resolve known enum from std, like `std::result::Result`
123 pub fn resolve_known_enum(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<EnumId> {
124 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
126 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it),
131 fn scopes(&self) -> impl Iterator<Item = &Scope> {
132 self.scopes.iter().rev()
135 fn resolve_module_path(
137 db: &dyn DefDatabase,
139 shadow: BuiltinShadowMode,
141 let (item_map, module) = match self.module_scope() {
143 None => return PerNs::none(),
145 let (module_res, segment_index) = item_map.resolve_path(db, module, path, shadow);
146 if segment_index.is_some() {
147 return PerNs::none();
152 pub fn resolve_module_path_in_items(&self, db: &dyn DefDatabase, path: &ModPath) -> PerNs {
153 self.resolve_module_path(db, path, BuiltinShadowMode::Module)
156 pub fn resolve_module_path_in_trait_assoc_items(
158 db: &dyn DefDatabase,
161 let (item_map, module) = self.module_scope()?;
162 let (module_res, idx) = item_map.resolve_path(db, module, path, BuiltinShadowMode::Module);
163 match module_res.take_types()? {
164 ModuleDefId::TraitId(it) => {
166 let unresolved = &path.segments()[idx..];
167 let assoc = match unresolved {
171 let &(_, assoc) = db.trait_data(it).items.iter().find(|(n, _)| n == assoc)?;
173 AssocItemId::FunctionId(it) => PerNs::values(it.into(), Visibility::Public),
174 AssocItemId::ConstId(it) => PerNs::values(it.into(), Visibility::Public),
175 AssocItemId::TypeAliasId(it) => PerNs::types(it.into(), Visibility::Public),
182 pub fn resolve_path_in_type_ns(
184 db: &dyn DefDatabase,
186 ) -> Option<(TypeNs, Option<usize>)> {
187 let first_name = path.segments().first()?;
188 let skip_to_mod = path.kind != PathKind::Plain;
189 for scope in self.scopes() {
191 Scope::ExprScope(_) => continue,
192 Scope::GenericParams { .. } | Scope::ImplDefScope(_) if skip_to_mod => continue,
194 Scope::GenericParams { params, def } => {
195 if let Some(local_id) = params.find_type_by_name(first_name) {
196 let idx = if path.segments().len() == 1 { None } else { Some(1) };
198 TypeNs::GenericParam(TypeParamId { local_id, parent: *def }),
203 Scope::ImplDefScope(impl_) => {
204 if first_name == &name![Self] {
205 let idx = if path.segments().len() == 1 { None } else { Some(1) };
206 return Some((TypeNs::SelfType(*impl_), idx));
209 Scope::AdtScope(adt) => {
210 if first_name == &name![Self] {
211 let idx = if path.segments().len() == 1 { None } else { Some(1) };
212 return Some((TypeNs::AdtSelfType(*adt), idx));
215 Scope::ModuleScope(m) => {
216 if let Some(res) = m.resolve_path_in_type_ns(db, path) {
225 pub fn resolve_path_in_type_ns_fully(
227 db: &dyn DefDatabase,
229 ) -> Option<TypeNs> {
230 let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?;
231 if unresolved.is_some() {
237 pub fn resolve_visibility(
239 db: &dyn DefDatabase,
240 visibility: &RawVisibility,
241 ) -> Option<Visibility> {
243 RawVisibility::Module(_) => {
244 let (item_map, module) = match self.module_scope() {
248 item_map.resolve_visibility(db, module, visibility)
250 RawVisibility::Public => Some(Visibility::Public),
254 pub fn resolve_path_in_value_ns(
256 db: &dyn DefDatabase,
258 ) -> Option<ResolveValueResult> {
259 let n_segments = path.segments().len();
260 let tmp = name![self];
261 let first_name = if path.is_self() { &tmp } else { path.segments().first()? };
262 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
263 for scope in self.scopes() {
266 | Scope::ExprScope(_)
267 | Scope::GenericParams { .. }
268 | Scope::ImplDefScope(_)
274 Scope::ExprScope(scope) if n_segments <= 1 => {
277 .entries(scope.scope_id)
279 .find(|entry| entry.name() == first_name);
281 if let Some(e) = entry {
282 return Some(ResolveValueResult::ValueNs(ValueNs::LocalBinding(e.pat())));
285 Scope::ExprScope(_) => continue,
287 Scope::GenericParams { params, def } if n_segments > 1 => {
288 if let Some(local_id) = params.find_type_by_name(first_name) {
289 let ty = TypeNs::GenericParam(TypeParamId { local_id, parent: *def });
290 return Some(ResolveValueResult::Partial(ty, 1));
293 Scope::GenericParams { params, def } if n_segments == 1 => {
294 if let Some(local_id) = params.find_const_by_name(first_name) {
295 let val = ValueNs::GenericParam(ConstParamId { local_id, parent: *def });
296 return Some(ResolveValueResult::ValueNs(val));
299 Scope::GenericParams { .. } => continue,
301 Scope::ImplDefScope(impl_) => {
302 if first_name == &name![Self] {
304 let ty = TypeNs::SelfType(*impl_);
305 return Some(ResolveValueResult::Partial(ty, 1));
307 return Some(ResolveValueResult::ValueNs(ValueNs::ImplSelf(*impl_)));
311 Scope::AdtScope(adt) => {
313 // bare `Self` doesn't work in the value namespace in a struct/enum definition
316 if first_name == &name![Self] {
317 let ty = TypeNs::AdtSelfType(*adt);
318 return Some(ResolveValueResult::Partial(ty, 1));
322 Scope::ModuleScope(m) => {
323 if let Some(def) = m.resolve_path_in_value_ns(db, path) {
333 pub fn resolve_path_in_value_ns_fully(
335 db: &dyn DefDatabase,
337 ) -> Option<ValueNs> {
338 match self.resolve_path_in_value_ns(db, path)? {
339 ResolveValueResult::ValueNs(it) => Some(it),
340 ResolveValueResult::Partial(..) => None,
344 pub fn resolve_path_as_macro(
346 db: &dyn DefDatabase,
348 ) -> Option<MacroDefId> {
349 let (item_map, module) = self.module_scope()?;
350 item_map.resolve_path(db, module, path, BuiltinShadowMode::Other).0.take_macros()
353 /// Returns a set of names available in the current scope.
355 /// Note that this is a somewhat fuzzy concept -- internally, the compiler
356 /// doesn't necessary follow a strict scoping discipline. Rathe, it just
357 /// tells for each ident what it resolves to.
359 /// A good example is something like `str::from_utf8`. From scopes point of
360 /// view, this code is erroneous -- both `str` module and `str` type occupy
361 /// the same type namespace.
363 /// We don't try to model that super-correctly -- this functionality is
364 /// primarily exposed for completions.
366 /// Note that in Rust one name can be bound to several items:
369 /// macro_rules! t { () => (()) }
371 /// const t: t = t!()
374 /// That's why we return a multimap.
376 /// The shadowing is accounted for: in
386 /// there will be only one entry for `x` in the result.
388 /// The result is ordered *roughly* from the innermost scope to the
389 /// outermost: when the name is introduced in two namespaces in two scopes,
390 /// we use the position of the first scope.
391 pub fn names_in_scope(&self, db: &dyn DefDatabase) -> IndexMap<Name, SmallVec<[ScopeDef; 1]>> {
392 let mut res = ScopeNames::default();
393 for scope in self.scopes() {
394 scope.process_names(db, &mut res);
399 pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> {
400 let mut traits = FxHashSet::default();
401 for scope in self.scopes() {
403 Scope::ModuleScope(m) => {
404 if let Some(prelude) = m.def_map.prelude() {
405 let prelude_def_map = prelude.def_map(db);
406 traits.extend(prelude_def_map[prelude.local_id].scope.traits());
408 traits.extend(m.def_map[m.module_id].scope.traits());
410 // Add all traits that are in scope because of the containing DefMaps
411 m.def_map.with_ancestor_maps(db, m.module_id, &mut |def_map, module| {
412 if let Some(prelude) = def_map.prelude() {
413 let prelude_def_map = prelude.def_map(db);
414 traits.extend(prelude_def_map[prelude.local_id].scope.traits());
416 traits.extend(def_map[module].scope.traits());
420 &Scope::ImplDefScope(impl_) => {
421 if let Some(target_trait) = &db.impl_data(impl_).target_trait {
422 if let Some(TypeNs::TraitId(trait_)) =
423 self.resolve_path_in_type_ns_fully(db, target_trait.path.mod_path())
425 traits.insert(trait_);
435 fn module_scope(&self) -> Option<(&DefMap, LocalModuleId)> {
436 self.scopes().find_map(|scope| match scope {
437 Scope::ModuleScope(m) => Some((&*m.def_map, m.module_id)),
443 pub fn module(&self) -> Option<ModuleId> {
444 let (def_map, local_id) = self.module_scope()?;
445 Some(def_map.module_id(local_id))
448 pub fn krate(&self) -> Option<CrateId> {
449 // FIXME: can this ever be `None`?
450 self.module_scope().map(|t| t.0.krate())
453 pub fn where_predicates_in_scope(
455 ) -> impl Iterator<Item = &crate::generics::WherePredicate> {
457 .filter_map(|scope| match scope {
458 Scope::GenericParams { params, .. } => Some(params),
461 .flat_map(|params| params.where_predicates.iter())
464 pub fn generic_def(&self) -> Option<GenericDefId> {
465 self.scopes().find_map(|scope| match scope {
466 Scope::GenericParams { def, .. } => Some(*def),
471 pub fn body_owner(&self) -> Option<DefWithBodyId> {
472 self.scopes().find_map(|scope| match scope {
473 Scope::ExprScope(it) => Some(it.owner),
479 #[derive(Debug, PartialEq, Eq)]
481 ModuleDef(ModuleDefId),
482 MacroDef(MacroDefId),
484 ImplSelfType(ImplId),
486 GenericParam(GenericParamId),
492 fn process_names(&self, db: &dyn DefDatabase, acc: &mut ScopeNames) {
494 Scope::ModuleScope(m) => {
495 // FIXME: should we provide `self` here?
497 // Name::self_param(),
498 // PerNs::types(Resolution::Def {
499 // def: m.module.into(),
502 m.def_map[m.module_id].scope.entries().for_each(|(name, def)| {
503 acc.add_per_ns(name, def);
505 m.def_map[m.module_id].scope.legacy_macros().for_each(|(name, mac)| {
506 acc.add(name, ScopeDef::MacroDef(mac));
508 m.def_map.extern_prelude().for_each(|(name, &def)| {
509 acc.add(name, ScopeDef::ModuleDef(def));
511 BUILTIN_SCOPE.iter().for_each(|(name, &def)| {
512 acc.add_per_ns(name, def);
514 if let Some(prelude) = m.def_map.prelude() {
515 let prelude_def_map = prelude.def_map(db);
516 for (name, def) in prelude_def_map[prelude.local_id].scope.entries() {
517 acc.add_per_ns(name, def)
521 Scope::GenericParams { params, def: parent } => {
522 let parent = *parent;
523 for (local_id, param) in params.types.iter() {
524 if let Some(name) = ¶m.name {
525 let id = TypeParamId { parent, local_id };
526 acc.add(name, ScopeDef::GenericParam(id.into()))
529 for (local_id, param) in params.consts.iter() {
530 let id = ConstParamId { parent, local_id };
531 acc.add(¶m.name, ScopeDef::GenericParam(id.into()))
533 for (local_id, param) in params.lifetimes.iter() {
534 let id = LifetimeParamId { parent, local_id };
535 acc.add(¶m.name, ScopeDef::GenericParam(id.into()))
538 Scope::ImplDefScope(i) => {
539 acc.add(&name![Self], ScopeDef::ImplSelfType(*i));
541 Scope::AdtScope(i) => {
542 acc.add(&name![Self], ScopeDef::AdtSelfType(*i));
544 Scope::ExprScope(scope) => {
545 if let Some((label, name)) = scope.expr_scopes.label(scope.scope_id) {
546 acc.add(&name, ScopeDef::Label(label))
548 scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| {
549 acc.add_local(e.name(), e.pat());
556 // needs arbitrary_self_types to be a method... or maybe move to the def?
557 pub fn resolver_for_expr(db: &dyn DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver {
558 let scopes = db.expr_scopes(owner);
559 resolver_for_scope(db, owner, scopes.scope_for(expr_id))
562 pub fn resolver_for_scope(
563 db: &dyn DefDatabase,
564 owner: DefWithBodyId,
565 scope_id: Option<ScopeId>,
567 let mut r = owner.resolver(db);
568 let scopes = db.expr_scopes(owner);
569 let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
570 for scope in scope_chain.into_iter().rev() {
571 if let Some(block) = scopes.block(scope) {
572 if let Some(def_map) = db.block_def_map(block) {
573 let root = def_map.root();
574 r = r.push_module_scope(def_map, root);
575 // FIXME: This adds as many module scopes as there are blocks, but resolving in each
576 // already traverses all parents, so this is O(n²). I think we could only store the
577 // innermost module scope instead?
581 r = r.push_expr_scope(owner, Arc::clone(&scopes), scope);
587 fn push_scope(mut self, scope: Scope) -> Resolver {
588 self.scopes.push(scope);
592 fn push_generic_params_scope(self, db: &dyn DefDatabase, def: GenericDefId) -> Resolver {
593 let params = db.generic_params(def);
594 self.push_scope(Scope::GenericParams { def, params })
597 fn push_impl_def_scope(self, impl_def: ImplId) -> Resolver {
598 self.push_scope(Scope::ImplDefScope(impl_def))
601 fn push_module_scope(self, def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver {
602 self.push_scope(Scope::ModuleScope(ModuleItemMap { def_map, module_id }))
607 owner: DefWithBodyId,
608 expr_scopes: Arc<ExprScopes>,
611 self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
616 fn resolve_path_in_value_ns(
618 db: &dyn DefDatabase,
620 ) -> Option<ResolveValueResult> {
621 let (module_def, idx) =
622 self.def_map.resolve_path_locally(db, self.module_id, path, BuiltinShadowMode::Other);
625 let value = to_value_ns(module_def)?;
626 Some(ResolveValueResult::ValueNs(value))
629 let ty = match module_def.take_types()? {
630 ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
631 ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
632 ModuleDefId::TypeAliasId(it) => TypeNs::TypeAliasId(it),
633 ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
635 ModuleDefId::ModuleId(_)
636 | ModuleDefId::FunctionId(_)
637 | ModuleDefId::EnumVariantId(_)
638 | ModuleDefId::ConstId(_)
639 | ModuleDefId::StaticId(_) => return None,
641 Some(ResolveValueResult::Partial(ty, idx))
646 fn resolve_path_in_type_ns(
648 db: &dyn DefDatabase,
650 ) -> Option<(TypeNs, Option<usize>)> {
651 let (module_def, idx) =
652 self.def_map.resolve_path_locally(db, self.module_id, path, BuiltinShadowMode::Other);
653 let res = to_type_ns(module_def)?;
658 fn to_value_ns(per_ns: PerNs) -> Option<ValueNs> {
659 let res = match per_ns.take_values()? {
660 ModuleDefId::FunctionId(it) => ValueNs::FunctionId(it),
661 ModuleDefId::AdtId(AdtId::StructId(it)) => ValueNs::StructId(it),
662 ModuleDefId::EnumVariantId(it) => ValueNs::EnumVariantId(it),
663 ModuleDefId::ConstId(it) => ValueNs::ConstId(it),
664 ModuleDefId::StaticId(it) => ValueNs::StaticId(it),
666 ModuleDefId::AdtId(AdtId::EnumId(_) | AdtId::UnionId(_))
667 | ModuleDefId::TraitId(_)
668 | ModuleDefId::TypeAliasId(_)
669 | ModuleDefId::BuiltinType(_)
670 | ModuleDefId::ModuleId(_) => return None,
675 fn to_type_ns(per_ns: PerNs) -> Option<TypeNs> {
676 let res = match per_ns.take_types()? {
677 ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
678 ModuleDefId::EnumVariantId(it) => TypeNs::EnumVariantId(it),
680 ModuleDefId::TypeAliasId(it) => TypeNs::TypeAliasId(it),
681 ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
683 ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
685 ModuleDefId::FunctionId(_)
686 | ModuleDefId::ConstId(_)
687 | ModuleDefId::StaticId(_)
688 | ModuleDefId::ModuleId(_) => return None,
695 map: IndexMap<Name, SmallVec<[ScopeDef; 1]>>,
699 fn add(&mut self, name: &Name, def: ScopeDef) {
700 let set = self.map.entry(name.clone()).or_default();
701 if !set.contains(&def) {
705 fn add_per_ns(&mut self, name: &Name, def: PerNs) {
706 if let Some(ty) = &def.types {
707 self.add(name, ScopeDef::ModuleDef(ty.0))
709 if let Some(val) = &def.values {
710 self.add(name, ScopeDef::ModuleDef(val.0))
712 if let Some(mac) = &def.macros {
713 self.add(name, ScopeDef::MacroDef(mac.0))
716 self.add(name, ScopeDef::Unknown)
719 fn add_local(&mut self, name: &Name, pat: PatId) {
720 let set = self.map.entry(name.clone()).or_default();
721 // XXX: hack, account for local (and only local) shadowing.
723 // This should be somewhat more principled and take namespaces into
724 // accounts, but, alas, scoping rules are a hoax. `str` type and `str`
725 // module can be both available in the same scope.
726 if set.iter().any(|it| matches!(it, &ScopeDef::Local(_))) {
727 cov_mark::hit!(shadowing_shows_single_completion);
730 set.push(ScopeDef::Local(pat))
734 pub trait HasResolver: Copy {
735 /// Builds a resolver for type references inside this def.
736 fn resolver(self, db: &dyn DefDatabase) -> Resolver;
739 impl HasResolver for ModuleId {
740 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
741 let mut def_map = self.def_map(db);
742 let mut modules = vec![(def_map.clone(), self.local_id)];
743 while let Some(parent) = def_map.parent() {
744 def_map = parent.def_map(db);
745 modules.push((def_map.clone(), parent.local_id));
747 let mut resolver = Resolver::default();
748 for (def_map, module) in modules.into_iter().rev() {
749 resolver = resolver.push_module_scope(def_map, module);
755 impl HasResolver for TraitId {
756 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
757 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
761 impl<T: Into<AdtId> + Copy> HasResolver for T {
762 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
763 let def = self.into();
766 .push_generic_params_scope(db, def.into())
767 .push_scope(Scope::AdtScope(def))
771 impl HasResolver for FunctionId {
772 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
773 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
777 impl HasResolver for ConstId {
778 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
779 self.lookup(db).container.resolver(db)
783 impl HasResolver for StaticId {
784 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
785 self.lookup(db).container.resolver(db)
789 impl HasResolver for TypeAliasId {
790 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
791 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
795 impl HasResolver for ImplId {
796 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
800 .push_generic_params_scope(db, self.into())
801 .push_impl_def_scope(self)
805 impl HasResolver for ExternBlockId {
806 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
808 self.lookup(db).container.resolver(db)
812 impl HasResolver for DefWithBodyId {
813 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
815 DefWithBodyId::ConstId(c) => c.resolver(db),
816 DefWithBodyId::FunctionId(f) => f.resolver(db),
817 DefWithBodyId::StaticId(s) => s.resolver(db),
822 impl HasResolver for ItemContainerId {
823 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
825 ItemContainerId::ModuleId(it) => it.resolver(db),
826 ItemContainerId::TraitId(it) => it.resolver(db),
827 ItemContainerId::ImplId(it) => it.resolver(db),
828 ItemContainerId::ExternBlockId(it) => it.resolver(db),
833 impl HasResolver for GenericDefId {
834 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
836 GenericDefId::FunctionId(inner) => inner.resolver(db),
837 GenericDefId::AdtId(adt) => adt.resolver(db),
838 GenericDefId::TraitId(inner) => inner.resolver(db),
839 GenericDefId::TypeAliasId(inner) => inner.resolver(db),
840 GenericDefId::ImplId(inner) => inner.resolver(db),
841 GenericDefId::EnumVariantId(inner) => inner.parent.resolver(db),
842 GenericDefId::ConstId(inner) => inner.resolver(db),
847 impl HasResolver for VariantId {
848 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
850 VariantId::EnumVariantId(it) => it.parent.resolver(db),
851 VariantId::StructId(it) => it.resolver(db),
852 VariantId::UnionId(it) => it.resolver(db),