mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 03:54:42 +00:00 
			
		
		
		
	Remove ast ids from item tree mod items
This commit is contained in:
		
							parent
							
								
									65e2e2c083
								
							
						
					
					
						commit
						048a01a05d
					
				
					 4 changed files with 122 additions and 162 deletions
				
			
		|  | @ -212,13 +212,13 @@ impl ItemTree { | ||||||
|                 SmallModItem::Trait(_) => traits += 1, |                 SmallModItem::Trait(_) => traits += 1, | ||||||
|                 SmallModItem::Impl(_) => impls += 1, |                 SmallModItem::Impl(_) => impls += 1, | ||||||
|                 SmallModItem::MacroRules(_) => macro_rules += 1, |                 SmallModItem::MacroRules(_) => macro_rules += 1, | ||||||
|  |                 SmallModItem::MacroCall(_) => macro_calls += 1, | ||||||
|                 _ => {} |                 _ => {} | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         for item in self.big_data.values() { |         for item in self.big_data.values() { | ||||||
|             match item { |             match item { | ||||||
|                 BigModItem::Mod(_) => mods += 1, |                 BigModItem::Mod(_) => mods += 1, | ||||||
|                 BigModItem::MacroCall(_) => macro_calls += 1, |  | ||||||
|                 _ => {} |                 _ => {} | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | @ -246,11 +246,14 @@ struct ItemVisibilities { | ||||||
| enum SmallModItem { | enum SmallModItem { | ||||||
|     Const(Const), |     Const(Const), | ||||||
|     Enum(Enum), |     Enum(Enum), | ||||||
|  |     ExternBlock(ExternBlock), | ||||||
|     Function(Function), |     Function(Function), | ||||||
|     Impl(Impl), |     Impl(Impl), | ||||||
|     Macro2(Macro2), |     Macro2(Macro2), | ||||||
|  |     MacroCall(MacroCall), | ||||||
|     MacroRules(MacroRules), |     MacroRules(MacroRules), | ||||||
|     Static(Static), |     Static(Static), | ||||||
|  |     Struct(Struct), | ||||||
|     Trait(Trait), |     Trait(Trait), | ||||||
|     TraitAlias(TraitAlias), |     TraitAlias(TraitAlias), | ||||||
|     TypeAlias(TypeAlias), |     TypeAlias(TypeAlias), | ||||||
|  | @ -259,11 +262,8 @@ enum SmallModItem { | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| enum BigModItem { | enum BigModItem { | ||||||
|     ExternBlock(ExternBlock), |  | ||||||
|     ExternCrate(ExternCrate), |     ExternCrate(ExternCrate), | ||||||
|     MacroCall(MacroCall), |  | ||||||
|     Mod(Mod), |     Mod(Mod), | ||||||
|     Struct(Struct), |  | ||||||
|     Use(Use), |     Use(Use), | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -370,23 +370,23 @@ macro_rules! mod_items { | ||||||
| 
 | 
 | ||||||
| mod_items! { | mod_items! { | ||||||
| ModItemId -> | ModItemId -> | ||||||
|     Use in big_data -> ast::Use, |  | ||||||
|     ExternCrate in big_data -> ast::ExternCrate, |  | ||||||
|     ExternBlock in big_data -> ast::ExternBlock, |  | ||||||
|     Function in small_data -> ast::Fn, |  | ||||||
|     Struct in big_data -> ast::Struct, |  | ||||||
|     Union in small_data -> ast::Union, |  | ||||||
|     Enum in small_data -> ast::Enum, |  | ||||||
|     Const in small_data -> ast::Const, |     Const in small_data -> ast::Const, | ||||||
|  |     Enum in small_data -> ast::Enum, | ||||||
|  |     ExternBlock in small_data -> ast::ExternBlock, | ||||||
|  |     ExternCrate in big_data -> ast::ExternCrate, | ||||||
|  |     Function in small_data -> ast::Fn, | ||||||
|  |     Impl in small_data -> ast::Impl, | ||||||
|  |     Macro2 in small_data -> ast::MacroDef, | ||||||
|  |     MacroCall in small_data -> ast::MacroCall, | ||||||
|  |     MacroRules in small_data -> ast::MacroRules, | ||||||
|  |     Mod in big_data -> ast::Module, | ||||||
|     Static in small_data -> ast::Static, |     Static in small_data -> ast::Static, | ||||||
|  |     Struct in small_data -> ast::Struct, | ||||||
|     Trait in small_data -> ast::Trait, |     Trait in small_data -> ast::Trait, | ||||||
|     TraitAlias in small_data -> ast::TraitAlias, |     TraitAlias in small_data -> ast::TraitAlias, | ||||||
|     Impl in small_data -> ast::Impl, |  | ||||||
|     TypeAlias in small_data -> ast::TypeAlias, |     TypeAlias in small_data -> ast::TypeAlias, | ||||||
|     Mod in big_data -> ast::Module, |     Union in small_data -> ast::Union, | ||||||
|     MacroCall in big_data -> ast::MacroCall, |     Use in big_data -> ast::Use, | ||||||
|     MacroRules in small_data -> ast::MacroRules, |  | ||||||
|     Macro2 in small_data -> ast::MacroDef, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Index<RawVisibilityId> for ItemTree { | impl Index<RawVisibilityId> for ItemTree { | ||||||
|  | @ -425,7 +425,6 @@ impl Index<RawVisibilityId> for ItemTree { | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct Use { | pub struct Use { | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub(crate) ast_id: FileAstId<ast::Use>, |  | ||||||
|     pub(crate) use_tree: UseTree, |     pub(crate) use_tree: UseTree, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -490,12 +489,10 @@ pub struct ExternCrate { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub alias: Option<ImportAlias>, |     pub alias: Option<ImportAlias>, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::ExternCrate>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct ExternBlock { | pub struct ExternBlock { | ||||||
|     pub ast_id: FileAstId<ast::ExternBlock>, |  | ||||||
|     pub(crate) children: Box<[ModItemId]>, |     pub(crate) children: Box<[ModItemId]>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -503,7 +500,6 @@ pub struct ExternBlock { | ||||||
| pub struct Function { | pub struct Function { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::Fn>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
|  | @ -511,21 +507,18 @@ pub struct Struct { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub shape: FieldsShape, |     pub shape: FieldsShape, | ||||||
|     pub ast_id: FileAstId<ast::Struct>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct Union { | pub struct Union { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::Union>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct Enum { | pub struct Enum { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::Enum>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq)] | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||||||
|  | @ -564,40 +557,33 @@ pub struct Const { | ||||||
|     /// `None` for `const _: () = ();`
 |     /// `None` for `const _: () = ();`
 | ||||||
|     pub name: Option<Name>, |     pub name: Option<Name>, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::Const>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct Static { | pub struct Static { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::Static>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct Trait { | pub struct Trait { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::Trait>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct TraitAlias { | pub struct TraitAlias { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::TraitAlias>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
| pub struct Impl { | pub struct Impl {} | ||||||
|     pub ast_id: FileAstId<ast::Impl>, |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, PartialEq, Eq)] | #[derive(Debug, Clone, PartialEq, Eq)] | ||||||
| pub struct TypeAlias { | pub struct TypeAlias { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::TypeAlias>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
|  | @ -605,7 +591,6 @@ pub struct Mod { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub(crate) kind: ModKind, |     pub(crate) kind: ModKind, | ||||||
|     pub ast_id: FileAstId<ast::Module>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Eq, PartialEq)] | #[derive(Debug, Clone, Eq, PartialEq)] | ||||||
|  | @ -620,7 +605,6 @@ pub(crate) enum ModKind { | ||||||
| pub struct MacroCall { | pub struct MacroCall { | ||||||
|     /// Path to the called macro.
 |     /// Path to the called macro.
 | ||||||
|     pub path: Interned<ModPath>, |     pub path: Interned<ModPath>, | ||||||
|     pub ast_id: FileAstId<ast::MacroCall>, |  | ||||||
|     pub expand_to: ExpandTo, |     pub expand_to: ExpandTo, | ||||||
|     pub ctxt: SyntaxContext, |     pub ctxt: SyntaxContext, | ||||||
| } | } | ||||||
|  | @ -629,7 +613,6 @@ pub struct MacroCall { | ||||||
| pub struct MacroRules { | pub struct MacroRules { | ||||||
|     /// The name of the declared macro.
 |     /// The name of the declared macro.
 | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub ast_id: FileAstId<ast::MacroRules>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// "Macros 2.0" macro definition.
 | /// "Macros 2.0" macro definition.
 | ||||||
|  | @ -637,7 +620,6 @@ pub struct MacroRules { | ||||||
| pub struct Macro2 { | pub struct Macro2 { | ||||||
|     pub name: Name, |     pub name: Name, | ||||||
|     pub(crate) visibility: RawVisibilityId, |     pub(crate) visibility: RawVisibilityId, | ||||||
|     pub ast_id: FileAstId<ast::MacroDef>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||||||
|  |  | ||||||
|  | @ -168,8 +168,8 @@ impl<'a> Ctx<'a> { | ||||||
|         let name = strukt.name()?.as_name(); |         let name = strukt.name()?.as_name(); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(strukt); |         let ast_id = self.source_ast_id_map.ast_id(strukt); | ||||||
|         let shape = adt_shape(strukt.kind()); |         let shape = adt_shape(strukt.kind()); | ||||||
|         let res = Struct { name, visibility, shape, ast_id }; |         let res = Struct { name, visibility, shape }; | ||||||
|         self.tree.big_data.insert(ast_id.upcast(), BigModItem::Struct(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Struct(res)); | ||||||
| 
 | 
 | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -178,7 +178,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let visibility = self.lower_visibility(union); |         let visibility = self.lower_visibility(union); | ||||||
|         let name = union.name()?.as_name(); |         let name = union.name()?.as_name(); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(union); |         let ast_id = self.source_ast_id_map.ast_id(union); | ||||||
|         let res = Union { name, visibility, ast_id }; |         let res = Union { name, visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Union(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Union(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -187,7 +187,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let visibility = self.lower_visibility(enum_); |         let visibility = self.lower_visibility(enum_); | ||||||
|         let name = enum_.name()?.as_name(); |         let name = enum_.name()?.as_name(); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(enum_); |         let ast_id = self.source_ast_id_map.ast_id(enum_); | ||||||
|         let res = Enum { name, visibility, ast_id }; |         let res = Enum { name, visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Enum(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Enum(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -198,7 +198,7 @@ impl<'a> Ctx<'a> { | ||||||
| 
 | 
 | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(func); |         let ast_id = self.source_ast_id_map.ast_id(func); | ||||||
| 
 | 
 | ||||||
|         let res = Function { name, visibility, ast_id }; |         let res = Function { name, visibility }; | ||||||
| 
 | 
 | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Function(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Function(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|  | @ -211,7 +211,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let name = type_alias.name()?.as_name(); |         let name = type_alias.name()?.as_name(); | ||||||
|         let visibility = self.lower_visibility(type_alias); |         let visibility = self.lower_visibility(type_alias); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(type_alias); |         let ast_id = self.source_ast_id_map.ast_id(type_alias); | ||||||
|         let res = TypeAlias { name, visibility, ast_id }; |         let res = TypeAlias { name, visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TypeAlias(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TypeAlias(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -220,7 +220,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let name = static_.name()?.as_name(); |         let name = static_.name()?.as_name(); | ||||||
|         let visibility = self.lower_visibility(static_); |         let visibility = self.lower_visibility(static_); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(static_); |         let ast_id = self.source_ast_id_map.ast_id(static_); | ||||||
|         let res = Static { name, visibility, ast_id }; |         let res = Static { name, visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Static(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Static(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -229,7 +229,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let name = konst.name().map(|it| it.as_name()); |         let name = konst.name().map(|it| it.as_name()); | ||||||
|         let visibility = self.lower_visibility(konst); |         let visibility = self.lower_visibility(konst); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(konst); |         let ast_id = self.source_ast_id_map.ast_id(konst); | ||||||
|         let res = Const { name, visibility, ast_id }; |         let res = Const { name, visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Const(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Const(res)); | ||||||
|         ast_id |         ast_id | ||||||
|     } |     } | ||||||
|  | @ -251,7 +251,7 @@ impl<'a> Ctx<'a> { | ||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(module); |         let ast_id = self.source_ast_id_map.ast_id(module); | ||||||
|         let res = Mod { name, visibility, kind, ast_id }; |         let res = Mod { name, visibility, kind }; | ||||||
|         self.tree.big_data.insert(ast_id.upcast(), BigModItem::Mod(res)); |         self.tree.big_data.insert(ast_id.upcast(), BigModItem::Mod(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -261,7 +261,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let visibility = self.lower_visibility(trait_def); |         let visibility = self.lower_visibility(trait_def); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(trait_def); |         let ast_id = self.source_ast_id_map.ast_id(trait_def); | ||||||
| 
 | 
 | ||||||
|         let def = Trait { name, visibility, ast_id }; |         let def = Trait { name, visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Trait(def)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Trait(def)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -274,7 +274,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let visibility = self.lower_visibility(trait_alias_def); |         let visibility = self.lower_visibility(trait_alias_def); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(trait_alias_def); |         let ast_id = self.source_ast_id_map.ast_id(trait_alias_def); | ||||||
| 
 | 
 | ||||||
|         let alias = TraitAlias { name, visibility, ast_id }; |         let alias = TraitAlias { name, visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TraitAlias(alias)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TraitAlias(alias)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -283,7 +283,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(impl_def); |         let ast_id = self.source_ast_id_map.ast_id(impl_def); | ||||||
|         // Note that trait impls don't get implicit `Self` unlike traits, because here they are a
 |         // Note that trait impls don't get implicit `Self` unlike traits, because here they are a
 | ||||||
|         // type alias rather than a type parameter, so this is handled by the resolver.
 |         // type alias rather than a type parameter, so this is handled by the resolver.
 | ||||||
|         let res = Impl { ast_id }; |         let res = Impl {}; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Impl(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Impl(res)); | ||||||
|         ast_id |         ast_id | ||||||
|     } |     } | ||||||
|  | @ -295,7 +295,7 @@ impl<'a> Ctx<'a> { | ||||||
|             self.span_map().span_for_range(range).ctx |             self.span_map().span_for_range(range).ctx | ||||||
|         })?; |         })?; | ||||||
| 
 | 
 | ||||||
|         let res = Use { visibility, ast_id, use_tree }; |         let res = Use { visibility, use_tree }; | ||||||
|         self.tree.big_data.insert(ast_id.upcast(), BigModItem::Use(res)); |         self.tree.big_data.insert(ast_id.upcast(), BigModItem::Use(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -311,7 +311,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let visibility = self.lower_visibility(extern_crate); |         let visibility = self.lower_visibility(extern_crate); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(extern_crate); |         let ast_id = self.source_ast_id_map.ast_id(extern_crate); | ||||||
| 
 | 
 | ||||||
|         let res = ExternCrate { name, alias, visibility, ast_id }; |         let res = ExternCrate { name, alias, visibility }; | ||||||
|         self.tree.big_data.insert(ast_id.upcast(), BigModItem::ExternCrate(res)); |         self.tree.big_data.insert(ast_id.upcast(), BigModItem::ExternCrate(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -325,8 +325,8 @@ impl<'a> Ctx<'a> { | ||||||
|         })?); |         })?); | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(m); |         let ast_id = self.source_ast_id_map.ast_id(m); | ||||||
|         let expand_to = hir_expand::ExpandTo::from_call_site(m); |         let expand_to = hir_expand::ExpandTo::from_call_site(m); | ||||||
|         let res = MacroCall { path, ast_id, expand_to, ctxt: span_map.span_for_range(range).ctx }; |         let res = MacroCall { path, expand_to, ctxt: span_map.span_for_range(range).ctx }; | ||||||
|         self.tree.big_data.insert(ast_id.upcast(), BigModItem::MacroCall(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::MacroCall(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -334,7 +334,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let name = m.name()?; |         let name = m.name()?; | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(m); |         let ast_id = self.source_ast_id_map.ast_id(m); | ||||||
| 
 | 
 | ||||||
|         let res = MacroRules { name: name.as_name(), ast_id }; |         let res = MacroRules { name: name.as_name() }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::MacroRules(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::MacroRules(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -345,7 +345,7 @@ impl<'a> Ctx<'a> { | ||||||
|         let ast_id = self.source_ast_id_map.ast_id(m); |         let ast_id = self.source_ast_id_map.ast_id(m); | ||||||
|         let visibility = self.lower_visibility(m); |         let visibility = self.lower_visibility(m); | ||||||
| 
 | 
 | ||||||
|         let res = Macro2 { name: name.as_name(), ast_id, visibility }; |         let res = Macro2 { name: name.as_name(), visibility }; | ||||||
|         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Macro2(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Macro2(res)); | ||||||
|         Some(ast_id) |         Some(ast_id) | ||||||
|     } |     } | ||||||
|  | @ -372,8 +372,8 @@ impl<'a> Ctx<'a> { | ||||||
|                 .collect() |                 .collect() | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         let res = ExternBlock { ast_id, children }; |         let res = ExternBlock { children }; | ||||||
|         self.tree.big_data.insert(ast_id.upcast(), BigModItem::ExternBlock(res)); |         self.tree.small_data.insert(ast_id.upcast(), SmallModItem::ExternBlock(res)); | ||||||
|         ast_id |         ast_id | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -161,16 +161,16 @@ impl Printer<'_> { | ||||||
|         self.print_attrs_of(item, "\n"); |         self.print_attrs_of(item, "\n"); | ||||||
| 
 | 
 | ||||||
|         match item { |         match item { | ||||||
|             ModItemId::Use(it) => { |             ModItemId::Use(ast_id) => { | ||||||
|                 let Use { visibility, use_tree, ast_id } = &self.tree[it]; |                 let Use { visibility, use_tree } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "use "); |                 w!(self, "use "); | ||||||
|                 self.print_use_tree(use_tree); |                 self.print_use_tree(use_tree); | ||||||
|                 wln!(self, ";"); |                 wln!(self, ";"); | ||||||
|             } |             } | ||||||
|             ModItemId::ExternCrate(it) => { |             ModItemId::ExternCrate(ast_id) => { | ||||||
|                 let ExternCrate { name, alias, visibility, ast_id } = &self.tree[it]; |                 let ExternCrate { name, alias, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "extern crate {}", name.display(self.db, self.edition)); |                 w!(self, "extern crate {}", name.display(self.db, self.edition)); | ||||||
|  | @ -179,8 +179,8 @@ impl Printer<'_> { | ||||||
|                 } |                 } | ||||||
|                 wln!(self, ";"); |                 wln!(self, ";"); | ||||||
|             } |             } | ||||||
|             ModItemId::ExternBlock(it) => { |             ModItemId::ExternBlock(ast_id) => { | ||||||
|                 let ExternBlock { ast_id, children } = &self.tree[it]; |                 let ExternBlock { children } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 w!(self, "extern {{"); |                 w!(self, "extern {{"); | ||||||
|                 self.indented(|this| { |                 self.indented(|this| { | ||||||
|  | @ -190,14 +190,14 @@ impl Printer<'_> { | ||||||
|                 }); |                 }); | ||||||
|                 wln!(self, "}}"); |                 wln!(self, "}}"); | ||||||
|             } |             } | ||||||
|             ModItemId::Function(it) => { |             ModItemId::Function(ast_id) => { | ||||||
|                 let Function { name, visibility, ast_id } = &self.tree[it]; |                 let Function { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 wln!(self, "fn {};", name.display(self.db, self.edition)); |                 wln!(self, "fn {};", name.display(self.db, self.edition)); | ||||||
|             } |             } | ||||||
|             ModItemId::Struct(it) => { |             ModItemId::Struct(ast_id) => { | ||||||
|                 let Struct { visibility, name, shape: kind, ast_id } = &self.tree[it]; |                 let Struct { visibility, name, shape: kind } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "struct {}", name.display(self.db, self.edition)); |                 w!(self, "struct {}", name.display(self.db, self.edition)); | ||||||
|  | @ -208,22 +208,22 @@ impl Printer<'_> { | ||||||
|                     wln!(self, ";"); |                     wln!(self, ";"); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             ModItemId::Union(it) => { |             ModItemId::Union(ast_id) => { | ||||||
|                 let Union { name, visibility, ast_id } = &self.tree[it]; |                 let Union { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "union {}", name.display(self.db, self.edition)); |                 w!(self, "union {}", name.display(self.db, self.edition)); | ||||||
|                 self.print_fields(FieldsShape::Record); |                 self.print_fields(FieldsShape::Record); | ||||||
|                 wln!(self); |                 wln!(self); | ||||||
|             } |             } | ||||||
|             ModItemId::Enum(it) => { |             ModItemId::Enum(ast_id) => { | ||||||
|                 let Enum { name, visibility, ast_id } = &self.tree[it]; |                 let Enum { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "enum {} {{ ... }}", name.display(self.db, self.edition)); |                 w!(self, "enum {} {{ ... }}", name.display(self.db, self.edition)); | ||||||
|             } |             } | ||||||
|             ModItemId::Const(it) => { |             ModItemId::Const(ast_id) => { | ||||||
|                 let Const { name, visibility, ast_id } = &self.tree[it]; |                 let Const { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "const "); |                 w!(self, "const "); | ||||||
|  | @ -233,8 +233,8 @@ impl Printer<'_> { | ||||||
|                 } |                 } | ||||||
|                 wln!(self, " = _;"); |                 wln!(self, " = _;"); | ||||||
|             } |             } | ||||||
|             ModItemId::Static(it) => { |             ModItemId::Static(ast_id) => { | ||||||
|                 let Static { name, visibility, ast_id } = &self.tree[it]; |                 let Static { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "static "); |                 w!(self, "static "); | ||||||
|  | @ -242,33 +242,33 @@ impl Printer<'_> { | ||||||
|                 w!(self, " = _;"); |                 w!(self, " = _;"); | ||||||
|                 wln!(self); |                 wln!(self); | ||||||
|             } |             } | ||||||
|             ModItemId::Trait(it) => { |             ModItemId::Trait(ast_id) => { | ||||||
|                 let Trait { name, visibility, ast_id } = &self.tree[it]; |                 let Trait { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "trait {} {{ ... }}", name.display(self.db, self.edition)); |                 w!(self, "trait {} {{ ... }}", name.display(self.db, self.edition)); | ||||||
|             } |             } | ||||||
|             ModItemId::TraitAlias(it) => { |             ModItemId::TraitAlias(ast_id) => { | ||||||
|                 let TraitAlias { name, visibility, ast_id } = &self.tree[it]; |                 let TraitAlias { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 wln!(self, "trait {} = ..;", name.display(self.db, self.edition)); |                 wln!(self, "trait {} = ..;", name.display(self.db, self.edition)); | ||||||
|             } |             } | ||||||
|             ModItemId::Impl(it) => { |             ModItemId::Impl(ast_id) => { | ||||||
|                 let Impl { ast_id } = &self.tree[it]; |                 let Impl {} = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 w!(self, "impl {{ ... }}"); |                 w!(self, "impl {{ ... }}"); | ||||||
|             } |             } | ||||||
|             ModItemId::TypeAlias(it) => { |             ModItemId::TypeAlias(ast_id) => { | ||||||
|                 let TypeAlias { name, visibility, ast_id } = &self.tree[it]; |                 let TypeAlias { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "type {}", name.display(self.db, self.edition)); |                 w!(self, "type {}", name.display(self.db, self.edition)); | ||||||
|                 w!(self, ";"); |                 w!(self, ";"); | ||||||
|                 wln!(self); |                 wln!(self); | ||||||
|             } |             } | ||||||
|             ModItemId::Mod(it) => { |             ModItemId::Mod(ast_id) => { | ||||||
|                 let Mod { name, visibility, kind, ast_id } = &self.tree[it]; |                 let Mod { name, visibility, kind } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 w!(self, "mod {}", name.display(self.db, self.edition)); |                 w!(self, "mod {}", name.display(self.db, self.edition)); | ||||||
|  | @ -287,8 +287,8 @@ impl Printer<'_> { | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             ModItemId::MacroCall(it) => { |             ModItemId::MacroCall(ast_id) => { | ||||||
|                 let MacroCall { path, ast_id, expand_to, ctxt } = &self.tree[it]; |                 let MacroCall { path, expand_to, ctxt } = &self.tree[ast_id]; | ||||||
|                 let _ = writeln!( |                 let _ = writeln!( | ||||||
|                     self, |                     self, | ||||||
|                     "// AstId: {:#?}, SyntaxContextId: {}, ExpandTo: {:?}", |                     "// AstId: {:#?}, SyntaxContextId: {}, ExpandTo: {:?}", | ||||||
|  | @ -298,13 +298,13 @@ impl Printer<'_> { | ||||||
|                 ); |                 ); | ||||||
|                 wln!(self, "{}!(...);", path.display(self.db, self.edition)); |                 wln!(self, "{}!(...);", path.display(self.db, self.edition)); | ||||||
|             } |             } | ||||||
|             ModItemId::MacroRules(it) => { |             ModItemId::MacroRules(ast_id) => { | ||||||
|                 let MacroRules { name, ast_id } = &self.tree[it]; |                 let MacroRules { name } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db, self.edition)); |                 wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db, self.edition)); | ||||||
|             } |             } | ||||||
|             ModItemId::Macro2(it) => { |             ModItemId::Macro2(ast_id) => { | ||||||
|                 let Macro2 { name, visibility, ast_id } = &self.tree[it]; |                 let Macro2 { name, visibility } = &self.tree[ast_id]; | ||||||
|                 self.print_ast_id(ast_id.erase()); |                 self.print_ast_id(ast_id.erase()); | ||||||
|                 self.print_visibility(*visibility); |                 self.print_visibility(*visibility); | ||||||
|                 wln!(self, "macro {} {{ ... }}", name.display(self.db, self.edition)); |                 wln!(self, "macro {} {{ ... }}", name.display(self.db, self.edition)); | ||||||
|  |  | ||||||
|  | @ -1434,11 +1434,10 @@ impl DefCollector<'_> { | ||||||
|                         // normal (as that would just be an identity expansion with extra output)
 |                         // normal (as that would just be an identity expansion with extra output)
 | ||||||
|                         // Instead we treat derive attributes special and apply them separately.
 |                         // Instead we treat derive attributes special and apply them separately.
 | ||||||
| 
 | 
 | ||||||
|                         let item_tree = tree.item_tree(self.db); |  | ||||||
|                         let ast_adt_id: FileAstId<ast::Adt> = match *mod_item { |                         let ast_adt_id: FileAstId<ast::Adt> = match *mod_item { | ||||||
|                             ModItemId::Struct(strukt) => item_tree[strukt].ast_id.upcast(), |                             ModItemId::Struct(ast_id) => ast_id.upcast(), | ||||||
|                             ModItemId::Union(union) => item_tree[union].ast_id.upcast(), |                             ModItemId::Union(ast_id) => ast_id.upcast(), | ||||||
|                             ModItemId::Enum(enum_) => item_tree[enum_].ast_id.upcast(), |                             ModItemId::Enum(ast_id) => ast_id.upcast(), | ||||||
|                             _ => { |                             _ => { | ||||||
|                                 let diag = DefDiagnostic::invalid_derive_target( |                                 let diag = DefDiagnostic::invalid_derive_target( | ||||||
|                                     directive.module_id, |                                     directive.module_id, | ||||||
|  | @ -1750,10 +1749,8 @@ impl ModCollector<'_, '_> { | ||||||
|             match item { |             match item { | ||||||
|                 ModItemId::Mod(m) => self.collect_module(m, &attrs), |                 ModItemId::Mod(m) => self.collect_module(m, &attrs), | ||||||
|                 ModItemId::Use(item_tree_id) => { |                 ModItemId::Use(item_tree_id) => { | ||||||
|                     let id = UseLoc { |                     let id = | ||||||
|                         container: module, |                         UseLoc { container: module, id: InFile::new(self.file_id(), item_tree_id) } | ||||||
|                         id: InFile::new(self.file_id(), self.item_tree[item_tree_id].ast_id), |  | ||||||
|                     } |  | ||||||
|                             .intern(db); |                             .intern(db); | ||||||
|                     let is_prelude = attrs.by_key(sym::prelude_import).exists(); |                     let is_prelude = attrs.by_key(sym::prelude_import).exists(); | ||||||
|                     Import::from_use( |                     Import::from_use( | ||||||
|  | @ -1772,12 +1769,12 @@ impl ModCollector<'_, '_> { | ||||||
|                     ) |                     ) | ||||||
|                 } |                 } | ||||||
|                 ModItemId::ExternCrate(item_tree_id) => { |                 ModItemId::ExternCrate(item_tree_id) => { | ||||||
|                     let item_tree::ExternCrate { name, visibility, alias, ast_id } = |                     let item_tree::ExternCrate { name, visibility, alias } = | ||||||
|                         &self.item_tree[item_tree_id]; |                         &self.item_tree[item_tree_id]; | ||||||
| 
 | 
 | ||||||
|                     let id = ExternCrateLoc { |                     let id = ExternCrateLoc { | ||||||
|                         container: module, |                         container: module, | ||||||
|                         id: InFile::new(self.tree_id.file_id(), *ast_id), |                         id: InFile::new(self.tree_id.file_id(), item_tree_id), | ||||||
|                     } |                     } | ||||||
|                     .intern(db); |                     .intern(db); | ||||||
|                     def_map.modules[self.module_id].scope.define_extern_crate_decl(id); |                     def_map.modules[self.module_id].scope.define_extern_crate_decl(id); | ||||||
|  | @ -1840,7 +1837,7 @@ impl ModCollector<'_, '_> { | ||||||
|                         self.def_collector.def_map.diagnostics.push( |                         self.def_collector.def_map.diagnostics.push( | ||||||
|                             DefDiagnostic::unresolved_extern_crate( |                             DefDiagnostic::unresolved_extern_crate( | ||||||
|                                 module_id, |                                 module_id, | ||||||
|                                 InFile::new(self.file_id(), *ast_id), |                                 InFile::new(self.file_id(), item_tree_id), | ||||||
|                             ), |                             ), | ||||||
|                         ); |                         ); | ||||||
|                     } |                     } | ||||||
|  | @ -1848,7 +1845,7 @@ impl ModCollector<'_, '_> { | ||||||
|                 ModItemId::ExternBlock(block) => { |                 ModItemId::ExternBlock(block) => { | ||||||
|                     let extern_block_id = ExternBlockLoc { |                     let extern_block_id = ExternBlockLoc { | ||||||
|                         container: module, |                         container: module, | ||||||
|                         id: InFile::new(self.file_id(), self.item_tree[block].ast_id), |                         id: InFile::new(self.file_id(), block), | ||||||
|                     } |                     } | ||||||
|                     .intern(db); |                     .intern(db); | ||||||
|                     self.def_collector.def_map.modules[self.module_id] |                     self.def_collector.def_map.modules[self.module_id] | ||||||
|  | @ -1859,25 +1856,19 @@ impl ModCollector<'_, '_> { | ||||||
|                         ItemContainerId::ExternBlockId(extern_block_id), |                         ItemContainerId::ExternBlockId(extern_block_id), | ||||||
|                     ) |                     ) | ||||||
|                 } |                 } | ||||||
|                 ModItemId::MacroCall(mac) => { |                 ModItemId::MacroCall(mac) => self.collect_macro_call(mac, container), | ||||||
|                     self.collect_macro_call(&self.item_tree[mac], container) |  | ||||||
|                 } |  | ||||||
|                 ModItemId::MacroRules(id) => self.collect_macro_rules(id, module), |                 ModItemId::MacroRules(id) => self.collect_macro_rules(id, module), | ||||||
|                 ModItemId::Macro2(id) => self.collect_macro_def(id, module), |                 ModItemId::Macro2(id) => self.collect_macro_def(id, module), | ||||||
|                 ModItemId::Impl(imp) => { |                 ModItemId::Impl(imp) => { | ||||||
|                     let impl_id = ImplLoc { |                     let impl_id = | ||||||
|                         container: module, |                         ImplLoc { container: module, id: InFile::new(self.file_id(), imp) } | ||||||
|                         id: InFile::new(self.file_id(), self.item_tree[imp].ast_id), |  | ||||||
|                     } |  | ||||||
|                             .intern(db); |                             .intern(db); | ||||||
|                     self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id) |                     self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id) | ||||||
|                 } |                 } | ||||||
|                 ModItemId::Function(id) => { |                 ModItemId::Function(id) => { | ||||||
|                     let it = &self.item_tree[id]; |                     let it = &self.item_tree[id]; | ||||||
|                     let fn_id = FunctionLoc { |                     let fn_id = | ||||||
|                         container, |                         FunctionLoc { container, id: InFile::new(self.tree_id.file_id(), id) } | ||||||
|                         id: InFile::new(self.tree_id.file_id(), it.ast_id), |  | ||||||
|                     } |  | ||||||
|                             .intern(db); |                             .intern(db); | ||||||
| 
 | 
 | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|  | @ -1889,7 +1880,7 @@ impl ModCollector<'_, '_> { | ||||||
|                         if let Some(proc_macro) = attrs.parse_proc_macro_decl(&it.name) { |                         if let Some(proc_macro) = attrs.parse_proc_macro_decl(&it.name) { | ||||||
|                             self.def_collector.export_proc_macro( |                             self.def_collector.export_proc_macro( | ||||||
|                                 proc_macro, |                                 proc_macro, | ||||||
|                                 InFile::new(self.file_id(), self.item_tree[id].ast_id), |                                 InFile::new(self.file_id(), id), | ||||||
|                                 fn_id, |                                 fn_id, | ||||||
|                             ); |                             ); | ||||||
|                         } |                         } | ||||||
|  | @ -1903,7 +1894,7 @@ impl ModCollector<'_, '_> { | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|                     update_def( |                     update_def( | ||||||
|                         self.def_collector, |                         self.def_collector, | ||||||
|                         StructLoc { container: module, id: InFile::new(self.file_id(), it.ast_id) } |                         StructLoc { container: module, id: InFile::new(self.file_id(), id) } | ||||||
|                             .intern(db) |                             .intern(db) | ||||||
|                             .into(), |                             .into(), | ||||||
|                         &it.name, |                         &it.name, | ||||||
|  | @ -1917,7 +1908,7 @@ impl ModCollector<'_, '_> { | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|                     update_def( |                     update_def( | ||||||
|                         self.def_collector, |                         self.def_collector, | ||||||
|                         UnionLoc { container: module, id: InFile::new(self.file_id(), it.ast_id) } |                         UnionLoc { container: module, id: InFile::new(self.file_id(), id) } | ||||||
|                             .intern(db) |                             .intern(db) | ||||||
|                             .into(), |                             .into(), | ||||||
|                         &it.name, |                         &it.name, | ||||||
|  | @ -1927,10 +1918,8 @@ impl ModCollector<'_, '_> { | ||||||
|                 } |                 } | ||||||
|                 ModItemId::Enum(id) => { |                 ModItemId::Enum(id) => { | ||||||
|                     let it = &self.item_tree[id]; |                     let it = &self.item_tree[id]; | ||||||
|                     let enum_ = EnumLoc { |                     let enum_ = | ||||||
|                         container: module, |                         EnumLoc { container: module, id: InFile::new(self.tree_id.file_id(), id) } | ||||||
|                         id: InFile::new(self.tree_id.file_id(), it.ast_id), |  | ||||||
|                     } |  | ||||||
|                             .intern(db); |                             .intern(db); | ||||||
| 
 | 
 | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|  | @ -1939,7 +1928,7 @@ impl ModCollector<'_, '_> { | ||||||
|                 ModItemId::Const(id) => { |                 ModItemId::Const(id) => { | ||||||
|                     let it = &self.item_tree[id]; |                     let it = &self.item_tree[id]; | ||||||
|                     let const_id = |                     let const_id = | ||||||
|                         ConstLoc { container, id: InFile::new(self.tree_id.file_id(), it.ast_id) } |                         ConstLoc { container, id: InFile::new(self.tree_id.file_id(), id) } | ||||||
|                             .intern(db); |                             .intern(db); | ||||||
| 
 | 
 | ||||||
|                     match &it.name { |                     match &it.name { | ||||||
|  | @ -1962,7 +1951,7 @@ impl ModCollector<'_, '_> { | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|                     update_def( |                     update_def( | ||||||
|                         self.def_collector, |                         self.def_collector, | ||||||
|                         StaticLoc { container, id: InFile::new(self.file_id(), it.ast_id) } |                         StaticLoc { container, id: InFile::new(self.file_id(), id) } | ||||||
|                             .intern(db) |                             .intern(db) | ||||||
|                             .into(), |                             .into(), | ||||||
|                         &it.name, |                         &it.name, | ||||||
|  | @ -1976,7 +1965,7 @@ impl ModCollector<'_, '_> { | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|                     update_def( |                     update_def( | ||||||
|                         self.def_collector, |                         self.def_collector, | ||||||
|                         TraitLoc { container: module, id: InFile::new(self.file_id(), it.ast_id) } |                         TraitLoc { container: module, id: InFile::new(self.file_id(), id) } | ||||||
|                             .intern(db) |                             .intern(db) | ||||||
|                             .into(), |                             .into(), | ||||||
|                         &it.name, |                         &it.name, | ||||||
|  | @ -1990,10 +1979,7 @@ impl ModCollector<'_, '_> { | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|                     update_def( |                     update_def( | ||||||
|                         self.def_collector, |                         self.def_collector, | ||||||
|                         TraitAliasLoc { |                         TraitAliasLoc { container: module, id: InFile::new(self.file_id(), id) } | ||||||
|                             container: module, |  | ||||||
|                             id: InFile::new(self.file_id(), it.ast_id), |  | ||||||
|                         } |  | ||||||
|                             .intern(db) |                             .intern(db) | ||||||
|                             .into(), |                             .into(), | ||||||
|                         &it.name, |                         &it.name, | ||||||
|  | @ -2007,7 +1993,7 @@ impl ModCollector<'_, '_> { | ||||||
|                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); |                     let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]); | ||||||
|                     update_def( |                     update_def( | ||||||
|                         self.def_collector, |                         self.def_collector, | ||||||
|                         TypeAliasLoc { container, id: InFile::new(self.file_id(), it.ast_id) } |                         TypeAliasLoc { container, id: InFile::new(self.file_id(), id) } | ||||||
|                             .intern(db) |                             .intern(db) | ||||||
|                             .into(), |                             .into(), | ||||||
|                         &it.name, |                         &it.name, | ||||||
|  | @ -2070,16 +2056,16 @@ impl ModCollector<'_, '_> { | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn collect_module(&mut self, module_id: ItemTreeAstId<Mod>, attrs: &Attrs) { |     fn collect_module(&mut self, module_ast_id: ItemTreeAstId<Mod>, attrs: &Attrs) { | ||||||
|         let path_attr = attrs.by_key(sym::path).string_value_unescape(); |         let path_attr = attrs.by_key(sym::path).string_value_unescape(); | ||||||
|         let is_macro_use = attrs.by_key(sym::macro_use).exists(); |         let is_macro_use = attrs.by_key(sym::macro_use).exists(); | ||||||
|         let module = &self.item_tree[module_id]; |         let module = &self.item_tree[module_ast_id]; | ||||||
|         match &module.kind { |         match &module.kind { | ||||||
|             // inline module, just recurse
 |             // inline module, just recurse
 | ||||||
|             ModKind::Inline { items } => { |             ModKind::Inline { items } => { | ||||||
|                 let module_id = self.push_child_module( |                 let module_id = self.push_child_module( | ||||||
|                     module.name.clone(), |                     module.name.clone(), | ||||||
|                     module.ast_id, |                     module_ast_id, | ||||||
|                     None, |                     None, | ||||||
|                     &self.item_tree[module.visibility], |                     &self.item_tree[module.visibility], | ||||||
|                 ); |                 ); | ||||||
|  | @ -2104,7 +2090,7 @@ impl ModCollector<'_, '_> { | ||||||
|             } |             } | ||||||
|             // out of line module, resolve, parse and recurse
 |             // out of line module, resolve, parse and recurse
 | ||||||
|             ModKind::Outline => { |             ModKind::Outline => { | ||||||
|                 let ast_id = AstId::new(self.file_id(), module.ast_id); |                 let ast_id = AstId::new(self.file_id(), module_ast_id); | ||||||
|                 let db = self.def_collector.db; |                 let db = self.def_collector.db; | ||||||
|                 match self.mod_dir.resolve_declaration( |                 match self.mod_dir.resolve_declaration( | ||||||
|                     db, |                     db, | ||||||
|  | @ -2123,10 +2109,7 @@ impl ModCollector<'_, '_> { | ||||||
|                         match is_enabled { |                         match is_enabled { | ||||||
|                             Err(cfg) => { |                             Err(cfg) => { | ||||||
|                                 self.emit_unconfigured_diagnostic( |                                 self.emit_unconfigured_diagnostic( | ||||||
|                                     InFile::new( |                                     InFile::new(self.file_id(), module_ast_id.erase()), | ||||||
|                                         self.file_id(), |  | ||||||
|                                         self.item_tree[module_id].ast_id.erase(), |  | ||||||
|                                     ), |  | ||||||
|                                     &cfg, |                                     &cfg, | ||||||
|                                 ); |                                 ); | ||||||
|                             } |                             } | ||||||
|  | @ -2295,11 +2278,11 @@ impl ModCollector<'_, '_> { | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn collect_macro_rules(&mut self, id: ItemTreeAstId<MacroRules>, module: ModuleId) { |     fn collect_macro_rules(&mut self, ast_id: ItemTreeAstId<MacroRules>, module: ModuleId) { | ||||||
|         let krate = self.def_collector.def_map.krate; |         let krate = self.def_collector.def_map.krate; | ||||||
|         let mac = &self.item_tree[id]; |         let mac = &self.item_tree[ast_id]; | ||||||
|         let attrs = self.item_tree.attrs(self.def_collector.db, krate, id.upcast()); |         let attrs = self.item_tree.attrs(self.def_collector.db, krate, ast_id.upcast()); | ||||||
|         let ast_id = InFile::new(self.file_id(), mac.ast_id.upcast()); |         let f_ast_id = InFile::new(self.file_id(), ast_id.upcast()); | ||||||
| 
 | 
 | ||||||
|         let export_attr = || attrs.by_key(sym::macro_export); |         let export_attr = || attrs.by_key(sym::macro_export); | ||||||
| 
 | 
 | ||||||
|  | @ -2346,7 +2329,7 @@ impl ModCollector<'_, '_> { | ||||||
|                     self.def_collector |                     self.def_collector | ||||||
|                         .def_map |                         .def_map | ||||||
|                         .diagnostics |                         .diagnostics | ||||||
|                         .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id)); |                         .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, f_ast_id)); | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  | @ -2362,16 +2345,13 @@ impl ModCollector<'_, '_> { | ||||||
| 
 | 
 | ||||||
|         let macro_id = MacroRulesLoc { |         let macro_id = MacroRulesLoc { | ||||||
|             container: module, |             container: module, | ||||||
|             id: InFile::new(self.file_id(), mac.ast_id), |             id: InFile::new(self.file_id(), ast_id), | ||||||
|             flags, |             flags, | ||||||
|             expander, |             expander, | ||||||
|             edition: self.def_collector.def_map.data.edition, |             edition: self.def_collector.def_map.data.edition, | ||||||
|         } |         } | ||||||
|         .intern(self.def_collector.db); |         .intern(self.def_collector.db); | ||||||
|         self.def_collector.def_map.macro_def_to_macro_id.insert( |         self.def_collector.def_map.macro_def_to_macro_id.insert(f_ast_id.erase(), macro_id.into()); | ||||||
|             InFile::new(self.file_id(), self.item_tree[id].ast_id).erase(), |  | ||||||
|             macro_id.into(), |  | ||||||
|         ); |  | ||||||
|         self.def_collector.define_macro_rules( |         self.def_collector.define_macro_rules( | ||||||
|             self.module_id, |             self.module_id, | ||||||
|             mac.name.clone(), |             mac.name.clone(), | ||||||
|  | @ -2380,14 +2360,14 @@ impl ModCollector<'_, '_> { | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn collect_macro_def(&mut self, id: ItemTreeAstId<Macro2>, module: ModuleId) { |     fn collect_macro_def(&mut self, ast_id: ItemTreeAstId<Macro2>, module: ModuleId) { | ||||||
|         let krate = self.def_collector.def_map.krate; |         let krate = self.def_collector.def_map.krate; | ||||||
|         let mac = &self.item_tree[id]; |         let mac = &self.item_tree[ast_id]; | ||||||
|         let ast_id = InFile::new(self.file_id(), mac.ast_id.upcast()); |         let attrs = self.item_tree.attrs(self.def_collector.db, krate, ast_id.upcast()); | ||||||
|  |         let f_ast_id = InFile::new(self.file_id(), ast_id.upcast()); | ||||||
| 
 | 
 | ||||||
|         // Case 1: builtin macros
 |         // Case 1: builtin macros
 | ||||||
|         let mut helpers_opt = None; |         let mut helpers_opt = None; | ||||||
|         let attrs = self.item_tree.attrs(self.def_collector.db, krate, id.upcast()); |  | ||||||
|         let expander = if attrs.by_key(sym::rustc_builtin_macro).exists() { |         let expander = if attrs.by_key(sym::rustc_builtin_macro).exists() { | ||||||
|             if let Some(expander) = find_builtin_macro(&mac.name) { |             if let Some(expander) = find_builtin_macro(&mac.name) { | ||||||
|                 match expander { |                 match expander { | ||||||
|  | @ -2419,7 +2399,7 @@ impl ModCollector<'_, '_> { | ||||||
|                 self.def_collector |                 self.def_collector | ||||||
|                     .def_map |                     .def_map | ||||||
|                     .diagnostics |                     .diagnostics | ||||||
|                     .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id)); |                     .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, f_ast_id)); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|  | @ -2430,16 +2410,13 @@ impl ModCollector<'_, '_> { | ||||||
| 
 | 
 | ||||||
|         let macro_id = Macro2Loc { |         let macro_id = Macro2Loc { | ||||||
|             container: module, |             container: module, | ||||||
|             id: InFile::new(self.file_id(), mac.ast_id), |             id: InFile::new(self.file_id(), ast_id), | ||||||
|             expander, |             expander, | ||||||
|             allow_internal_unsafe, |             allow_internal_unsafe, | ||||||
|             edition: self.def_collector.def_map.data.edition, |             edition: self.def_collector.def_map.data.edition, | ||||||
|         } |         } | ||||||
|         .intern(self.def_collector.db); |         .intern(self.def_collector.db); | ||||||
|         self.def_collector.def_map.macro_def_to_macro_id.insert( |         self.def_collector.def_map.macro_def_to_macro_id.insert(f_ast_id.erase(), macro_id.into()); | ||||||
|             InFile::new(self.file_id(), self.item_tree[id].ast_id).erase(), |  | ||||||
|             macro_id.into(), |  | ||||||
|         ); |  | ||||||
|         self.def_collector.define_macro_def( |         self.def_collector.define_macro_def( | ||||||
|             self.module_id, |             self.module_id, | ||||||
|             mac.name.clone(), |             mac.name.clone(), | ||||||
|  | @ -2458,9 +2435,10 @@ impl ModCollector<'_, '_> { | ||||||
| 
 | 
 | ||||||
|     fn collect_macro_call( |     fn collect_macro_call( | ||||||
|         &mut self, |         &mut self, | ||||||
|         &MacroCall { ref path, ast_id, expand_to, ctxt }: &MacroCall, |         ast_id: FileAstId<ast::MacroCall>, | ||||||
|         container: ItemContainerId, |         container: ItemContainerId, | ||||||
|     ) { |     ) { | ||||||
|  |         let &MacroCall { ref path, expand_to, ctxt } = &self.item_tree[ast_id]; | ||||||
|         let ast_id = AstIdWithPath::new(self.file_id(), ast_id, path.clone()); |         let ast_id = AstIdWithPath::new(self.file_id(), ast_id, path.clone()); | ||||||
|         let db = self.def_collector.db; |         let db = self.def_collector.db; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Wirth
						Lukas Wirth