6 use ra_db::{CrateId, Edition, FileId, SourceRootId};
7 use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
10 adt::{EnumVariantId, StructFieldId, VariantDef},
11 diagnostics::DiagnosticSink,
12 expr::{validation::ExprValidator, Body, BodySourceMap},
13 generics::HasGenericParams,
15 AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId,
18 impl_block::ImplBlock,
20 BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64,
23 nameres::{CrateModuleId, ImportId, ModuleScope, Namespace},
25 traits::{TraitData, TraitItem},
27 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness},
28 InferenceResult, TraitRef,
32 AsName, AstDatabase, AstId, DefDatabase, Either, HasSource, HirDatabase, Name, Ty,
35 /// hir::Crate describes a single crate. It's the main interface with which
36 /// a crate's dependencies interact. Mostly, it should be just a proxy for the
38 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
40 pub(crate) crate_id: CrateId,
44 pub struct CrateDependency {
50 pub fn crate_id(self) -> CrateId {
54 pub fn dependencies(self, db: &impl DefDatabase) -> Vec<CrateDependency> {
56 .dependencies(self.crate_id)
58 let krate = Crate { crate_id: dep.crate_id() };
59 let name = dep.as_name();
60 CrateDependency { krate, name }
65 pub fn root_module(self, db: &impl DefDatabase) -> Option<Module> {
66 let module_id = db.crate_def_map(self).root();
67 let module = Module { krate: self, module_id };
71 pub fn edition(self, db: &impl DefDatabase) -> Edition {
72 let crate_graph = db.crate_graph();
73 crate_graph.edition(self.crate_id)
76 // FIXME: should this be in source_binder?
77 pub fn source_root_crates(db: &impl DefDatabase, source_root: SourceRootId) -> Vec<Crate> {
78 let crate_ids = db.source_root_crates(source_root);
79 crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect()
83 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
85 pub(crate) krate: Crate,
86 pub(crate) module_id: CrateModuleId,
89 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
90 pub enum BuiltinType {
100 pub(crate) const ALL: &'static [(Name, BuiltinType)] = &[
101 (CHAR, BuiltinType::Char),
102 (BOOL, BuiltinType::Bool),
103 (STR, BuiltinType::Str),
105 (ISIZE, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })),
106 (I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })),
107 (I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })),
108 (I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })),
109 (I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })),
110 (I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })),
112 (USIZE, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })),
113 (U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })),
114 (U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })),
115 (U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })),
116 (U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })),
117 (U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })),
119 (F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })),
120 (F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })),
124 /// The defs which can be visible in the module.
125 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
132 // Can't be directly declared, but can be imported.
133 EnumVariant(EnumVariant),
137 TypeAlias(TypeAlias),
138 BuiltinType(BuiltinType),
154 pub enum ModuleSource {
155 SourceFile(ast::SourceFile),
161 db: &(impl DefDatabase + AstDatabase),
162 file_id: Option<FileId>,
163 decl_id: Option<AstId<ast::Module>>,
165 match (file_id, decl_id) {
166 (Some(file_id), _) => {
167 let source_file = db.parse(file_id).tree().to_owned();
168 ModuleSource::SourceFile(source_file)
170 (None, Some(item_id)) => {
171 let module = item_id.to_node(db);
172 assert!(module.item_list().is_some(), "expected inline module");
173 ModuleSource::Module(module)
175 (None, None) => panic!(),
181 /// Name of this module.
182 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
183 let def_map = db.crate_def_map(self.krate);
184 let parent = def_map[self.module_id].parent?;
185 def_map[parent].children.iter().find_map(|(name, module_id)| {
186 if *module_id == self.module_id {
194 /// Returns the syntax of the last path segment corresponding to this import
195 pub fn import_source(
197 db: &impl HirDatabase,
199 ) -> Either<ast::UseTree, ast::ExternCrateItem> {
200 let src = self.definition_source(db);
201 let (_, source_map) = db.raw_items_with_source_map(src.file_id);
202 source_map.get(&src.ast, import)
205 /// Returns the crate this module is part of.
206 pub fn krate(self, _db: &impl DefDatabase) -> Option<Crate> {
210 /// Topmost parent of this module. Every module has a `crate_root`, but some
211 /// might be missing `krate`. This can happen if a module's file is not included
212 /// in the module tree of any target in `Cargo.toml`.
213 pub fn crate_root(self, db: &impl DefDatabase) -> Module {
214 let def_map = db.crate_def_map(self.krate);
215 self.with_module_id(def_map.root())
218 /// Finds a child module with the specified name.
219 pub fn child(self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
220 let def_map = db.crate_def_map(self.krate);
221 let child_id = def_map[self.module_id].children.get(name)?;
222 Some(self.with_module_id(*child_id))
225 /// Iterates over all child modules.
226 pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
227 let def_map = db.crate_def_map(self.krate);
228 let children = def_map[self.module_id]
231 .map(|(_, module_id)| self.with_module_id(*module_id))
232 .collect::<Vec<_>>();
236 /// Finds a parent module.
237 pub fn parent(self, db: &impl DefDatabase) -> Option<Module> {
238 let def_map = db.crate_def_map(self.krate);
239 let parent_id = def_map[self.module_id].parent?;
240 Some(self.with_module_id(parent_id))
243 pub fn path_to_root(self, db: &impl HirDatabase) -> Vec<Module> {
244 let mut res = vec![self];
246 while let Some(next) = curr.parent(db) {
253 /// Returns a `ModuleScope`: a set of items, visible in this module.
254 pub fn scope(self, db: &impl HirDatabase) -> ModuleScope {
255 db.crate_def_map(self.krate)[self.module_id].scope.clone()
258 pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
259 db.crate_def_map(self.krate).add_diagnostics(db, self.module_id, sink);
260 for decl in self.declarations(db) {
262 crate::ModuleDef::Function(f) => f.diagnostics(db, sink),
263 crate::ModuleDef::Module(m) => {
264 // Only add diagnostics from inline modules
265 if let ModuleSource::Module(_) = m.definition_source(db).ast {
266 m.diagnostics(db, sink)
273 for impl_block in self.impl_blocks(db) {
274 for item in impl_block.items(db) {
275 if let crate::ImplItem::Method(f) = item {
276 f.diagnostics(db, sink);
282 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
283 let def_map = db.crate_def_map(self.krate);
284 Resolver::default().push_module_scope(def_map, self.module_id)
287 pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> {
288 let def_map = db.crate_def_map(self.krate);
289 def_map[self.module_id]
292 .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None })
294 per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter())
299 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
300 let module_impl_blocks = db.impls_in_module(self);
304 .map(|(impl_id, _)| ImplBlock::from_id(self, impl_id))
308 fn with_module_id(self, module_id: CrateModuleId) -> Module {
309 Module { module_id, krate: self.krate }
313 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
314 pub struct StructField {
315 pub(crate) parent: VariantDef,
316 pub(crate) id: StructFieldId,
320 pub enum FieldSource {
321 Named(ast::NamedFieldDef),
322 Pos(ast::PosFieldDef),
326 pub fn name(&self, db: &impl HirDatabase) -> Name {
327 self.parent.variant_data(db).fields().unwrap()[self.id].name.clone()
330 pub fn ty(&self, db: &impl HirDatabase) -> Ty {
331 db.type_for_field(*self)
334 pub fn parent_def(&self, _db: &impl HirDatabase) -> VariantDef {
339 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
341 pub(crate) id: StructId,
345 pub fn module(self, db: &impl HirDatabase) -> Module {
349 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
350 db.struct_data(self).name.clone()
353 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
358 .flat_map(|it| it.iter())
359 .map(|(id, _)| StructField { parent: self.into(), id })
363 pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
368 .flat_map(|it| it.iter())
369 .find(|(_id, data)| data.name == *name)
370 .map(|(id, _)| StructField { parent: self.into(), id })
373 pub fn ty(self, db: &impl HirDatabase) -> Ty {
374 db.type_for_def(self.into(), Namespace::Types)
377 pub fn constructor_ty(self, db: &impl HirDatabase) -> Ty {
378 db.type_for_def(self.into(), Namespace::Values)
381 // FIXME move to a more general type
382 /// Builds a resolver for type references inside this struct.
383 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
384 // take the outer scope...
385 let r = self.module(db).resolver(db);
386 // ...and add generic params, if present
387 let p = self.generic_params(db);
388 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
393 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
395 pub(crate) id: StructId,
399 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
400 db.struct_data(Struct { id: self.id }).name.clone()
403 pub fn module(self, db: &impl HirDatabase) -> Module {
407 pub fn ty(self, db: &impl HirDatabase) -> Ty {
408 db.type_for_def(self.into(), Namespace::Types)
411 // FIXME move to a more general type
412 /// Builds a resolver for type references inside this union.
413 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
414 // take the outer scope...
415 let r = self.module(db).resolver(db);
416 // ...and add generic params, if present
417 let p = self.generic_params(db);
418 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
423 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
425 pub(crate) id: EnumId,
429 pub fn module(self, db: &impl HirDatabase) -> Module {
433 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
434 db.enum_data(self).name.clone()
437 pub fn variants(self, db: &impl DefDatabase) -> Vec<EnumVariant> {
438 db.enum_data(self).variants.iter().map(|(id, _)| EnumVariant { parent: self, id }).collect()
441 pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> {
445 .find(|(_id, data)| data.name.as_ref() == Some(name))
446 .map(|(id, _)| EnumVariant { parent: self, id })
449 pub fn ty(self, db: &impl HirDatabase) -> Ty {
450 db.type_for_def(self.into(), Namespace::Types)
453 // FIXME: move to a more general type
454 /// Builds a resolver for type references inside this struct.
455 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
456 // take the outer scope...
457 let r = self.module(db).resolver(db);
458 // ...and add generic params, if present
459 let p = self.generic_params(db);
460 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
465 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
466 pub struct EnumVariant {
467 pub(crate) parent: Enum,
468 pub(crate) id: EnumVariantId,
472 pub fn module(self, db: &impl HirDatabase) -> Module {
473 self.parent.module(db)
475 pub fn parent_enum(self, _db: &impl DefDatabase) -> Enum {
479 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
480 db.enum_data(self.parent).variants[self.id].name.clone()
483 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
484 self.variant_data(db)
487 .flat_map(|it| it.iter())
488 .map(|(id, _)| StructField { parent: self.into(), id })
492 pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
493 self.variant_data(db)
496 .flat_map(|it| it.iter())
497 .find(|(_id, data)| data.name == *name)
498 .map(|(id, _)| StructField { parent: self.into(), id })
502 /// The defs which have a body.
503 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
504 pub enum DefWithBody {
510 impl_froms!(DefWithBody: Function, Const, Static);
513 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
517 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
521 pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
522 db.body_with_source_map(self).1
525 /// Builds a resolver for code inside this item.
526 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
528 DefWithBody::Const(c) => c.resolver(db),
529 DefWithBody::Function(f) => f.resolver(db),
530 DefWithBody::Static(s) => s.resolver(db),
535 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
536 pub struct Function {
537 pub(crate) id: FunctionId,
540 #[derive(Debug, Clone, PartialEq, Eq)]
542 pub(crate) name: Name,
543 pub(crate) params: Vec<TypeRef>,
544 pub(crate) ret_type: TypeRef,
545 /// True if the first param is `self`. This is relevant to decide whether this
546 /// can be called as a method.
547 pub(crate) has_self_param: bool,
551 pub(crate) fn fn_data_query(
552 db: &(impl DefDatabase + AstDatabase),
555 let src = func.source(db);
556 let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
557 let mut params = Vec::new();
558 let mut has_self_param = false;
559 if let Some(param_list) = src.ast.param_list() {
560 if let Some(self_param) = param_list.self_param() {
561 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
562 TypeRef::from_ast(type_ref)
564 let self_type = TypeRef::Path(SELF_TYPE.into());
565 match self_param.kind() {
566 ast::SelfParamKind::Owned => self_type,
567 ast::SelfParamKind::Ref => {
568 TypeRef::Reference(Box::new(self_type), Mutability::Shared)
570 ast::SelfParamKind::MutRef => {
571 TypeRef::Reference(Box::new(self_type), Mutability::Mut)
575 params.push(self_type);
576 has_self_param = true;
578 for param in param_list.params() {
579 let type_ref = TypeRef::from_ast_opt(param.ascribed_type());
580 params.push(type_ref);
583 let ret_type = if let Some(type_ref) = src.ast.ret_type().and_then(|rt| rt.type_ref()) {
584 TypeRef::from_ast(type_ref)
589 let sig = FnData { name, params, ret_type, has_self_param };
592 pub fn name(&self) -> &Name {
596 pub fn params(&self) -> &[TypeRef] {
600 pub fn ret_type(&self) -> &TypeRef {
604 /// True if the first arg is `self`. This is relevant to decide whether this
605 /// can be called as a method.
606 pub fn has_self_param(&self) -> bool {
612 pub fn module(self, db: &impl DefDatabase) -> Module {
616 pub fn name(self, db: &impl HirDatabase) -> Name {
617 self.data(db).name.clone()
620 pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
621 db.body_with_source_map(self.into()).1
624 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
625 db.body_hir(self.into())
628 pub fn ty(self, db: &impl HirDatabase) -> Ty {
629 db.type_for_def(self.into(), Namespace::Values)
632 pub fn data(self, db: &impl HirDatabase) -> Arc<FnData> {
636 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
637 db.infer(self.into())
640 /// The containing impl block, if this is a method.
641 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
642 let module_impls = db.impls_in_module(self.module(db));
643 ImplBlock::containing(module_impls, self.into())
646 /// The containing trait, if this is a trait method definition.
647 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
648 db.trait_items_index(self.module(db)).get_parent_trait(self.into())
651 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
652 if let Some(impl_block) = self.impl_block(db) {
653 Some(impl_block.into())
654 } else if let Some(trait_) = self.parent_trait(db) {
661 // FIXME: move to a more general type for 'body-having' items
662 /// Builds a resolver for code inside this item.
663 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
664 // take the outer scope...
665 let r = self.container(db).map_or_else(|| self.module(db).resolver(db), |c| c.resolver(db));
666 // ...and add generic params, if present
667 let p = self.generic_params(db);
668 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
672 pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
673 let infer = self.infer(db);
674 infer.add_diagnostics(db, self, sink);
675 let mut validator = ExprValidator::new(self, infer, sink);
676 validator.validate_body(db);
680 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
682 pub(crate) id: ConstId,
686 pub fn module(self, db: &impl DefDatabase) -> Module {
690 pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
694 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
695 db.infer(self.into())
698 /// The containing impl block, if this is a method.
699 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
700 let module_impls = db.impls_in_module(self.module(db));
701 ImplBlock::containing(module_impls, self.into())
704 // FIXME: move to a more general type for 'body-having' items
705 /// Builds a resolver for code inside this item.
706 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
707 // take the outer scope...
710 .map(|ib| ib.resolver(db))
711 .unwrap_or_else(|| self.module(db).resolver(db));
716 #[derive(Debug, Clone, PartialEq, Eq)]
717 pub struct ConstData {
718 pub(crate) name: Name,
719 pub(crate) type_ref: TypeRef,
723 pub fn name(&self) -> &Name {
727 pub fn type_ref(&self) -> &TypeRef {
731 pub(crate) fn const_data_query(
732 db: &(impl DefDatabase + AstDatabase),
734 ) -> Arc<ConstData> {
735 let node = konst.source(db).ast;
736 const_data_for(&node)
739 pub(crate) fn static_data_query(
740 db: &(impl DefDatabase + AstDatabase),
742 ) -> Arc<ConstData> {
743 let node = konst.source(db).ast;
744 const_data_for(&node)
748 fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> {
749 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
750 let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
751 let sig = ConstData { name, type_ref };
755 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
757 pub(crate) id: StaticId,
761 pub fn module(self, db: &impl DefDatabase) -> Module {
765 pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
769 /// Builds a resolver for code inside this item.
770 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
771 // take the outer scope...
772 self.module(db).resolver(db)
775 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
776 db.infer(self.into())
780 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
782 pub(crate) id: TraitId,
786 pub fn module(self, db: &impl DefDatabase) -> Module {
790 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
791 self.trait_data(db).name().clone()
794 pub fn items(self, db: &impl DefDatabase) -> Vec<TraitItem> {
795 self.trait_data(db).items().to_vec()
798 pub fn associated_type_by_name(self, db: &impl DefDatabase, name: Name) -> Option<TypeAlias> {
799 let trait_data = self.trait_data(db);
803 .filter_map(|item| match item {
804 TraitItem::TypeAlias(t) => Some(*t),
807 .find(|t| t.name(db) == name)
810 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> {
814 pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef {
815 TraitRef::for_trait(db, self)
818 pub fn is_auto(self, db: &impl DefDatabase) -> bool {
819 self.trait_data(db).is_auto()
822 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
823 let r = self.module(db).resolver(db);
824 // add generic params, if present
825 let p = self.generic_params(db);
826 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
831 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
832 pub struct TypeAlias {
833 pub(crate) id: TypeAliasId,
837 pub fn module(self, db: &impl DefDatabase) -> Module {
841 /// The containing impl block, if this is a method.
842 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
843 let module_impls = db.impls_in_module(self.module(db));
844 ImplBlock::containing(module_impls, self.into())
847 /// The containing trait, if this is a trait method definition.
848 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
849 db.trait_items_index(self.module(db)).get_parent_trait(self.into())
852 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
853 if let Some(impl_block) = self.impl_block(db) {
854 Some(impl_block.into())
855 } else if let Some(trait_) = self.parent_trait(db) {
862 pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> {
863 db.type_alias_data(self).type_ref.clone()
866 pub fn ty(self, db: &impl HirDatabase) -> Ty {
867 db.type_for_def(self.into(), Namespace::Types)
870 pub fn name(self, db: &impl DefDatabase) -> Name {
871 db.type_alias_data(self).name.clone()
874 /// Builds a resolver for the type references in this type alias.
875 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
876 // take the outer scope...
879 .map(|ib| ib.resolver(db))
880 .unwrap_or_else(|| self.module(db).resolver(db));
881 // ...and add generic params, if present
882 let p = self.generic_params(db);
883 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
888 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
889 pub struct MacroDef {
890 pub(crate) id: MacroDefId,
897 ImplBlock(ImplBlock),
899 impl_froms!(Container: Trait, ImplBlock);
902 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
904 Container::Trait(trait_) => trait_.resolver(db),
905 Container::ImplBlock(impl_block) => impl_block.resolver(db),