@@ -21,7 +21,7 @@ use limit::Limit;
2121use once_cell:: unsync:: OnceCell ;
2222use profile:: Count ;
2323use rustc_hash:: FxHashMap ;
24- use syntax:: { ast, AstPtr , SyntaxNode , SyntaxNodePtr } ;
24+ use syntax:: { ast, AstPtr , Parse , SyntaxNode , SyntaxNodePtr } ;
2525
2626use crate :: {
2727 attr:: Attrs ,
@@ -137,7 +137,7 @@ impl Expander {
137137 & mut self ,
138138 db : & dyn DefDatabase ,
139139 macro_call : ast:: MacroCall ,
140- ) -> Result < ExpandResult < Option < ( Mark , T ) > > , UnresolvedMacro > {
140+ ) -> Result < ExpandResult < Option < ( Mark , Parse < T > ) > > , UnresolvedMacro > {
141141 // FIXME: within_limit should support this, instead of us having to extract the error
142142 let mut unresolved_macro_err = None ;
143143
@@ -167,37 +167,37 @@ impl Expander {
167167 & mut self ,
168168 db : & dyn DefDatabase ,
169169 call_id : MacroCallId ,
170- ) -> ExpandResult < Option < ( Mark , T ) > > {
170+ ) -> ExpandResult < Option < ( Mark , Parse < T > ) > > {
171171 self . within_limit ( db, |_this| ExpandResult :: ok ( Some ( call_id) ) )
172172 }
173173
174174 fn enter_expand_inner (
175175 db : & dyn DefDatabase ,
176176 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 > > > > {
183179 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+ }
184185
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,
188188 None => {
189189 // Only `None` if the macro expansion produced no usable AST.
190- if err . is_none ( ) {
190+ if error . is_none ( ) {
191191 tracing:: warn!( "no error despite `parse_or_expand` failing" ) ;
192192 }
193193
194- return ExpandResult :: only_err ( err . unwrap_or_else ( || {
194+ return ExpandResult :: only_err ( error . unwrap_or_else ( || {
195195 ExpandError :: Other ( "failed to parse macro invocation" . into ( ) )
196196 } ) ) ;
197197 }
198198 } ;
199199
200- ExpandResult { value : Some ( ( file_id, raw_node ) ) , err }
200+ ExpandResult { value : Some ( InFile :: new ( file_id, parse ) ) , err : error }
201201 }
202202
203203 pub fn exit ( & mut self , db : & dyn DefDatabase , mut mark : Mark ) {
@@ -259,7 +259,7 @@ impl Expander {
259259 & mut self ,
260260 db : & dyn DefDatabase ,
261261 op : F ,
262- ) -> ExpandResult < Option < ( Mark , T ) > >
262+ ) -> ExpandResult < Option < ( Mark , Parse < T > ) > >
263263 where
264264 F : FnOnce ( & mut Self ) -> ExpandResult < Option < MacroCallId > > ,
265265 {
@@ -286,15 +286,15 @@ impl Expander {
286286 } ;
287287
288288 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 > ( ) ?;
291291
292292 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 ) ;
295295 let mark =
296296 Mark { file_id : old_file_id, bomb : DropBomb :: new ( "expansion mark dropped" ) } ;
297- Some ( ( mark, node ) )
297+ Some ( ( mark, parse ) )
298298 } )
299299 } )
300300 }
0 commit comments