@@ -1117,8 +1117,9 @@ impl DefCollector<'_> {
11171117 self . def_map . krate ,
11181118 resolver_def_id,
11191119 ) ;
1120- if let Ok ( ExpandResult { value : Some ( call_id) , .. } ) = call_id {
1120+ if let Ok ( Some ( call_id) ) = call_id {
11211121 push_resolved ( directive, call_id) ;
1122+
11221123 res = ReachedFixedPoint :: No ;
11231124 return false ;
11241125 }
@@ -1354,26 +1355,30 @@ impl DefCollector<'_> {
13541355 let file_id = macro_call_id. as_file ( ) ;
13551356
13561357 // First, fetch the raw expansion result for purposes of error reporting. This goes through
1357- // `macro_expand_error ` to avoid depending on the full expansion result (to improve
1358+ // `parse_macro_expansion_error ` to avoid depending on the full expansion result (to improve
13581359 // incrementality).
1359- let loc: MacroCallLoc = self . db . lookup_intern_macro_call ( macro_call_id) ;
1360- let err = self . db . macro_expand_error ( macro_call_id) ;
1360+ let ExpandResult { value, err } = self . db . parse_macro_expansion_error ( macro_call_id) ;
13611361 if let Some ( err) = err {
1362+ let loc: MacroCallLoc = self . db . lookup_intern_macro_call ( macro_call_id) ;
13621363 let diag = match err {
1364+ // why is this reported here?
13631365 hir_expand:: ExpandError :: UnresolvedProcMacro ( krate) => {
13641366 always ! ( krate == loc. def. krate) ;
1365- // Missing proc macros are non-fatal, so they are handled specially.
13661367 DefDiagnostic :: unresolved_proc_macro ( module_id, loc. kind . clone ( ) , loc. def . krate )
13671368 }
1368- _ => DefDiagnostic :: macro_error ( module_id, loc. kind , err. to_string ( ) ) ,
1369+ _ => DefDiagnostic :: macro_error ( module_id, loc. kind . clone ( ) , err. to_string ( ) ) ,
13691370 } ;
13701371
13711372 self . def_map . diagnostics . push ( diag) ;
13721373 }
1374+ if let Some ( errors) = value {
1375+ let loc: MacroCallLoc = self . db . lookup_intern_macro_call ( macro_call_id) ;
1376+ let diag = DefDiagnostic :: macro_expansion_parse_error ( module_id, loc. kind , & errors) ;
1377+ self . def_map . diagnostics . push ( diag) ;
1378+ }
13731379
13741380 // Then, fetch and process the item tree. This will reuse the expansion result from above.
13751381 let item_tree = self . db . file_item_tree ( file_id) ;
1376- // FIXME: report parse errors for the macro expansion here
13771382
13781383 let mod_dir = self . mod_dirs [ & module_id] . clone ( ) ;
13791384 ModCollector {
@@ -1395,6 +1400,7 @@ impl DefCollector<'_> {
13951400 for directive in & self . unresolved_macros {
13961401 match & directive. kind {
13971402 MacroDirectiveKind :: FnLike { ast_id, expand_to } => {
1403+ // FIXME: we shouldn't need to re-resolve the macro here just to get the unresolved error!
13981404 let macro_call_as_call_id = macro_call_as_call_id (
13991405 self . db ,
14001406 ast_id,
@@ -2110,7 +2116,7 @@ impl ModCollector<'_, '_> {
21102116 let ast_id = AstIdWithPath :: new ( self . file_id ( ) , mac. ast_id , ModPath :: clone ( & mac. path ) ) ;
21112117
21122118 // Case 1: try to resolve in legacy scope and expand macro_rules
2113- match macro_call_as_call_id (
2119+ if let Ok ( res ) = macro_call_as_call_id (
21142120 self . def_collector . db ,
21152121 & ast_id,
21162122 mac. expand_to ,
@@ -2131,29 +2137,18 @@ impl ModCollector<'_, '_> {
21312137 } )
21322138 } ,
21332139 ) {
2134- Ok ( res) => {
2135- // Legacy macros need to be expanded immediately, so that any macros they produce
2136- // are in scope.
2137- if let Some ( val) = res. value {
2138- self . def_collector . collect_macro_expansion (
2139- self . module_id ,
2140- val,
2141- self . macro_depth + 1 ,
2142- container,
2143- ) ;
2144- }
2145-
2146- if let Some ( err) = res. err {
2147- self . def_collector . def_map . diagnostics . push ( DefDiagnostic :: macro_error (
2148- self . module_id ,
2149- MacroCallKind :: FnLike { ast_id : ast_id. ast_id , expand_to : mac. expand_to } ,
2150- err. to_string ( ) ,
2151- ) ) ;
2152- }
2153-
2154- return ;
2140+ // Legacy macros need to be expanded immediately, so that any macros they produce
2141+ // are in scope.
2142+ if let Some ( val) = res {
2143+ self . def_collector . collect_macro_expansion (
2144+ self . module_id ,
2145+ val,
2146+ self . macro_depth + 1 ,
2147+ container,
2148+ ) ;
21552149 }
2156- Err ( UnresolvedMacro { .. } ) => ( ) ,
2150+
2151+ return ;
21572152 }
21582153
21592154 // Case 2: resolve in module scope, expand during name resolution.
0 commit comments