@@ -1117,8 +1117,9 @@ impl DefCollector<'_> {
1117
1117
self . def_map . krate ,
1118
1118
resolver_def_id,
1119
1119
) ;
1120
- if let Ok ( ExpandResult { value : Some ( call_id) , .. } ) = call_id {
1120
+ if let Ok ( Some ( call_id) ) = call_id {
1121
1121
push_resolved ( directive, call_id) ;
1122
+
1122
1123
res = ReachedFixedPoint :: No ;
1123
1124
return false ;
1124
1125
}
@@ -1354,26 +1355,30 @@ impl DefCollector<'_> {
1354
1355
let file_id = macro_call_id. as_file ( ) ;
1355
1356
1356
1357
// 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
1358
1359
// 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) ;
1361
1361
if let Some ( err) = err {
1362
+ let loc: MacroCallLoc = self . db . lookup_intern_macro_call ( macro_call_id) ;
1362
1363
let diag = match err {
1364
+ // why is this reported here?
1363
1365
hir_expand:: ExpandError :: UnresolvedProcMacro ( krate) => {
1364
1366
always ! ( krate == loc. def. krate) ;
1365
- // Missing proc macros are non-fatal, so they are handled specially.
1366
1367
DefDiagnostic :: unresolved_proc_macro ( module_id, loc. kind . clone ( ) , loc. def . krate )
1367
1368
}
1368
- _ => DefDiagnostic :: macro_error ( module_id, loc. kind , err. to_string ( ) ) ,
1369
+ _ => DefDiagnostic :: macro_error ( module_id, loc. kind . clone ( ) , err. to_string ( ) ) ,
1369
1370
} ;
1370
1371
1371
1372
self . def_map . diagnostics . push ( diag) ;
1372
1373
}
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
+ }
1373
1379
1374
1380
// Then, fetch and process the item tree. This will reuse the expansion result from above.
1375
1381
let item_tree = self . db . file_item_tree ( file_id) ;
1376
- // FIXME: report parse errors for the macro expansion here
1377
1382
1378
1383
let mod_dir = self . mod_dirs [ & module_id] . clone ( ) ;
1379
1384
ModCollector {
@@ -1395,6 +1400,7 @@ impl DefCollector<'_> {
1395
1400
for directive in & self . unresolved_macros {
1396
1401
match & directive. kind {
1397
1402
MacroDirectiveKind :: FnLike { ast_id, expand_to } => {
1403
+ // FIXME: we shouldn't need to re-resolve the macro here just to get the unresolved error!
1398
1404
let macro_call_as_call_id = macro_call_as_call_id (
1399
1405
self . db ,
1400
1406
ast_id,
@@ -2110,7 +2116,7 @@ impl ModCollector<'_, '_> {
2110
2116
let ast_id = AstIdWithPath :: new ( self . file_id ( ) , mac. ast_id , ModPath :: clone ( & mac. path ) ) ;
2111
2117
2112
2118
// 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 (
2114
2120
self . def_collector . db ,
2115
2121
& ast_id,
2116
2122
mac. expand_to ,
@@ -2131,29 +2137,18 @@ impl ModCollector<'_, '_> {
2131
2137
} )
2132
2138
} ,
2133
2139
) {
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
+ ) ;
2155
2149
}
2156
- Err ( UnresolvedMacro { .. } ) => ( ) ,
2150
+
2151
+ return ;
2157
2152
}
2158
2153
2159
2154
// Case 2: resolve in module scope, expand during name resolution.
0 commit comments