@@ -62,19 +62,88 @@ enum HirFileIdRepr {
6262 FileId ( FileId ) ,
6363 MacroFile ( MacroFile ) ,
6464}
65-
6665impl From < FileId > for HirFileId {
6766 fn from ( id : FileId ) -> Self {
6867 HirFileId ( HirFileIdRepr :: FileId ( id) )
6968 }
7069}
71-
7270impl From < MacroFile > for HirFileId {
7371 fn from ( id : MacroFile ) -> Self {
7472 HirFileId ( HirFileIdRepr :: MacroFile ( id) )
7573 }
7674}
7775
76+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
77+ pub struct MacroFile {
78+ pub macro_call_id : MacroCallId ,
79+ }
80+
81+ /// `MacroCallId` identifies a particular macro invocation, like
82+ /// `println!("Hello, {}", world)`.
83+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
84+ pub struct MacroCallId ( salsa:: InternId ) ;
85+ impl_intern_key ! ( MacroCallId ) ;
86+
87+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
88+ pub struct MacroCallLoc {
89+ pub def : MacroDefId ,
90+ pub ( crate ) krate : CrateId ,
91+ eager : Option < EagerCallInfo > ,
92+ pub kind : MacroCallKind ,
93+ }
94+
95+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
96+ pub struct MacroDefId {
97+ pub krate : CrateId ,
98+ pub kind : MacroDefKind ,
99+ pub local_inner : bool ,
100+ }
101+
102+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
103+ pub enum MacroDefKind {
104+ Declarative ( AstId < ast:: Macro > ) ,
105+ BuiltIn ( BuiltinFnLikeExpander , AstId < ast:: Macro > ) ,
106+ // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
107+ BuiltInAttr ( BuiltinAttrExpander , AstId < ast:: Macro > ) ,
108+ BuiltInDerive ( BuiltinDeriveExpander , AstId < ast:: Macro > ) ,
109+ BuiltInEager ( EagerExpander , AstId < ast:: Macro > ) ,
110+ ProcMacro ( ProcMacroExpander , ProcMacroKind , AstId < ast:: Fn > ) ,
111+ }
112+
113+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
114+ struct EagerCallInfo {
115+ /// NOTE: This can be *either* the expansion result, *or* the argument to the eager macro!
116+ arg_or_expansion : Arc < tt:: Subtree > ,
117+ included_file : Option < FileId > ,
118+ }
119+
120+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
121+ pub enum MacroCallKind {
122+ FnLike {
123+ ast_id : AstId < ast:: MacroCall > ,
124+ expand_to : ExpandTo ,
125+ } ,
126+ Derive {
127+ ast_id : AstId < ast:: Item > ,
128+ derive_name : String ,
129+ /// Syntactical index of the invoking `#[derive]` attribute.
130+ ///
131+ /// Outer attributes are counted first, then inner attributes. This does not support
132+ /// out-of-line modules, which may have attributes spread across 2 files!
133+ derive_attr_index : u32 ,
134+ } ,
135+ Attr {
136+ ast_id : AstId < ast:: Item > ,
137+ attr_name : String ,
138+ attr_args : ( tt:: Subtree , mbe:: TokenMap ) ,
139+ /// Syntactical index of the invoking `#[attribute]`.
140+ ///
141+ /// Outer attributes are counted first, then inner attributes. This does not support
142+ /// out-of-line modules, which may have attributes spread across 2 files!
143+ invoc_attr_index : u32 ,
144+ } ,
145+ }
146+
78147impl HirFileId {
79148 /// For macro-expansion files, returns the file original source file the
80149 /// expansion originated from.
@@ -215,25 +284,6 @@ impl HirFileId {
215284 }
216285}
217286
218- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
219- pub struct MacroFile {
220- pub macro_call_id : MacroCallId ,
221- }
222-
223- /// `MacroCallId` identifies a particular macro invocation, like
224- /// `println!("Hello, {}", world)`.
225- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
226- pub struct MacroCallId ( salsa:: InternId ) ;
227- impl_intern_key ! ( MacroCallId ) ;
228-
229- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
230- pub struct MacroDefId {
231- pub krate : CrateId ,
232- pub kind : MacroDefKind ,
233-
234- pub local_inner : bool ,
235- }
236-
237287impl MacroDefId {
238288 pub fn as_lazy_macro (
239289 self ,
@@ -261,59 +311,6 @@ impl MacroDefId {
261311 }
262312}
263313
264- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
265- pub enum MacroDefKind {
266- Declarative ( AstId < ast:: Macro > ) ,
267- BuiltIn ( BuiltinFnLikeExpander , AstId < ast:: Macro > ) ,
268- // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
269- BuiltInAttr ( BuiltinAttrExpander , AstId < ast:: Macro > ) ,
270- BuiltInDerive ( BuiltinDeriveExpander , AstId < ast:: Macro > ) ,
271- BuiltInEager ( EagerExpander , AstId < ast:: Macro > ) ,
272- ProcMacro ( ProcMacroExpander , ProcMacroKind , AstId < ast:: Fn > ) ,
273- }
274-
275- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
276- struct EagerCallInfo {
277- /// NOTE: This can be *either* the expansion result, *or* the argument to the eager macro!
278- arg_or_expansion : Arc < tt:: Subtree > ,
279- included_file : Option < FileId > ,
280- }
281-
282- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
283- pub struct MacroCallLoc {
284- pub def : MacroDefId ,
285- pub ( crate ) krate : CrateId ,
286- eager : Option < EagerCallInfo > ,
287- pub kind : MacroCallKind ,
288- }
289-
290- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
291- pub enum MacroCallKind {
292- FnLike {
293- ast_id : AstId < ast:: MacroCall > ,
294- expand_to : ExpandTo ,
295- } ,
296- Derive {
297- ast_id : AstId < ast:: Item > ,
298- derive_name : String ,
299- /// Syntactical index of the invoking `#[derive]` attribute.
300- ///
301- /// Outer attributes are counted first, then inner attributes. This does not support
302- /// out-of-line modules, which may have attributes spread across 2 files!
303- derive_attr_index : u32 ,
304- } ,
305- Attr {
306- ast_id : AstId < ast:: Item > ,
307- attr_name : String ,
308- attr_args : ( tt:: Subtree , mbe:: TokenMap ) ,
309- /// Syntactical index of the invoking `#[attribute]`.
310- ///
311- /// Outer attributes are counted first, then inner attributes. This does not support
312- /// out-of-line modules, which may have attributes spread across 2 files!
313- invoc_attr_index : u32 ,
314- } ,
315- }
316-
317314// FIXME: attribute indices do not account for `cfg_attr`, which means that we'll strip the whole
318315// `cfg_attr` instead of just one of the attributes it expands to
319316
0 commit comments