@@ -21,7 +21,7 @@ use limit::Limit;
21
21
use once_cell:: unsync:: OnceCell ;
22
22
use profile:: Count ;
23
23
use rustc_hash:: FxHashMap ;
24
- use syntax:: { ast, AstPtr , SyntaxNode , SyntaxNodePtr } ;
24
+ use syntax:: { ast, AstPtr , Parse , SyntaxNode , SyntaxNodePtr } ;
25
25
26
26
use crate :: {
27
27
attr:: Attrs ,
@@ -137,7 +137,7 @@ impl Expander {
137
137
& mut self ,
138
138
db : & dyn DefDatabase ,
139
139
macro_call : ast:: MacroCall ,
140
- ) -> Result < ExpandResult < Option < ( Mark , T ) > > , UnresolvedMacro > {
140
+ ) -> Result < ExpandResult < Option < ( Mark , Parse < T > ) > > , UnresolvedMacro > {
141
141
// FIXME: within_limit should support this, instead of us having to extract the error
142
142
let mut unresolved_macro_err = None ;
143
143
@@ -167,37 +167,37 @@ impl Expander {
167
167
& mut self ,
168
168
db : & dyn DefDatabase ,
169
169
call_id : MacroCallId ,
170
- ) -> ExpandResult < Option < ( Mark , T ) > > {
170
+ ) -> ExpandResult < Option < ( Mark , Parse < T > ) > > {
171
171
self . within_limit ( db, |_this| ExpandResult :: ok ( Some ( call_id) ) )
172
172
}
173
173
174
174
fn enter_expand_inner (
175
175
db : & dyn DefDatabase ,
176
176
call_id : MacroCallId ,
177
- mut err : Option < ExpandError > ,
178
- ) -> ExpandResult < Option < ( HirFileId , SyntaxNode ) > > {
179
- if err. is_none ( ) {
180
- err = db. macro_expand_error ( call_id) ;
181
- }
182
-
177
+ mut error : Option < ExpandError > ,
178
+ ) -> ExpandResult < Option < InFile < Parse < SyntaxNode > > > > {
183
179
let file_id = call_id. as_file ( ) ;
180
+ let ExpandResult { value, err } = db. parse_or_expand_with_err ( file_id) ;
181
+
182
+ if error. is_none ( ) {
183
+ error = err;
184
+ }
184
185
185
- let raw_node = match db. parse_or_expand_with_err ( file_id) {
186
- // FIXME: report parse errors
187
- Some ( it) => it. syntax_node ( ) ,
186
+ let parse = match value {
187
+ Some ( it) => it,
188
188
None => {
189
189
// Only `None` if the macro expansion produced no usable AST.
190
- if err . is_none ( ) {
190
+ if error . is_none ( ) {
191
191
tracing:: warn!( "no error despite `parse_or_expand` failing" ) ;
192
192
}
193
193
194
- return ExpandResult :: only_err ( err . unwrap_or_else ( || {
194
+ return ExpandResult :: only_err ( error . unwrap_or_else ( || {
195
195
ExpandError :: Other ( "failed to parse macro invocation" . into ( ) )
196
196
} ) ) ;
197
197
}
198
198
} ;
199
199
200
- ExpandResult { value : Some ( ( file_id, raw_node ) ) , err }
200
+ ExpandResult { value : Some ( InFile :: new ( file_id, parse ) ) , err : error }
201
201
}
202
202
203
203
pub fn exit ( & mut self , db : & dyn DefDatabase , mut mark : Mark ) {
@@ -259,7 +259,7 @@ impl Expander {
259
259
& mut self ,
260
260
db : & dyn DefDatabase ,
261
261
op : F ,
262
- ) -> ExpandResult < Option < ( Mark , T ) > >
262
+ ) -> ExpandResult < Option < ( Mark , Parse < T > ) > >
263
263
where
264
264
F : FnOnce ( & mut Self ) -> ExpandResult < Option < MacroCallId > > ,
265
265
{
@@ -286,15 +286,15 @@ impl Expander {
286
286
} ;
287
287
288
288
Self :: enter_expand_inner ( db, call_id, err) . map ( |value| {
289
- value. and_then ( |( new_file_id , node ) | {
290
- let node = T :: cast ( node ) ?;
289
+ value. and_then ( |InFile { file_id , value } | {
290
+ let parse = value . cast :: < T > ( ) ?;
291
291
292
292
self . recursion_depth += 1 ;
293
- self . cfg_expander . hygiene = Hygiene :: new ( db. upcast ( ) , new_file_id ) ;
294
- let old_file_id = std:: mem:: replace ( & mut self . current_file_id , new_file_id ) ;
293
+ self . cfg_expander . hygiene = Hygiene :: new ( db. upcast ( ) , file_id ) ;
294
+ let old_file_id = std:: mem:: replace ( & mut self . current_file_id , file_id ) ;
295
295
let mark =
296
296
Mark { file_id : old_file_id, bomb : DropBomb :: new ( "expansion mark dropped" ) } ;
297
- Some ( ( mark, node ) )
297
+ Some ( ( mark, parse ) )
298
298
} )
299
299
} )
300
300
}
0 commit comments