@@ -14,7 +14,7 @@ use hir_expand::{
1414 builtin_macro:: find_builtin_macro,
1515 name:: { name, AsName , Name } ,
1616 proc_macro:: ProcMacroExpander ,
17- FragmentKind , HirFileId , MacroCallId , MacroCallKind , MacroDefId , MacroDefKind ,
17+ ExpandTo , HirFileId , MacroCallId , MacroCallKind , MacroDefId , MacroDefKind ,
1818} ;
1919use hir_expand:: { InFile , MacroCallLoc } ;
2020use itertools:: Itertools ;
@@ -223,7 +223,7 @@ struct MacroDirective {
223223
224224#[ derive( Clone , Debug , Eq , PartialEq ) ]
225225enum MacroDirectiveKind {
226- FnLike { ast_id : AstIdWithPath < ast:: MacroCall > , fragment : FragmentKind } ,
226+ FnLike { ast_id : AstIdWithPath < ast:: MacroCall > , expand_to : ExpandTo } ,
227227 Derive { ast_id : AstIdWithPath < ast:: Item > , derive_attr : AttrId } ,
228228 Attr { ast_id : AstIdWithPath < ast:: Item > , attr : Attr , mod_item : ModItem } ,
229229}
@@ -1021,10 +1021,10 @@ impl DefCollector<'_> {
10211021 } ;
10221022
10231023 match & directive. kind {
1024- MacroDirectiveKind :: FnLike { ast_id, fragment } => {
1024+ MacroDirectiveKind :: FnLike { ast_id, expand_to } => {
10251025 match macro_call_as_call_id (
10261026 ast_id,
1027- * fragment ,
1027+ * expand_to ,
10281028 self . db ,
10291029 self . def_map . krate ,
10301030 & resolver,
@@ -1223,32 +1223,34 @@ impl DefCollector<'_> {
12231223
12241224 for directive in & self . unresolved_macros {
12251225 match & directive. kind {
1226- MacroDirectiveKind :: FnLike { ast_id, fragment } => match macro_call_as_call_id (
1227- ast_id,
1228- * fragment,
1229- self . db ,
1230- self . def_map . krate ,
1231- |path| {
1232- let resolved_res = self . def_map . resolve_path_fp_with_macro (
1233- self . db ,
1234- ResolveMode :: Other ,
1235- directive. module_id ,
1236- & path,
1237- BuiltinShadowMode :: Module ,
1238- ) ;
1239- resolved_res. resolved_def . take_macros ( )
1240- } ,
1241- & mut |_| ( ) ,
1242- ) {
1243- Ok ( _) => ( ) ,
1244- Err ( UnresolvedMacro { path } ) => {
1245- self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_macro_call (
1246- directive. module_id ,
1247- ast_id. ast_id ,
1248- path,
1249- ) ) ;
1226+ MacroDirectiveKind :: FnLike { ast_id, expand_to } => {
1227+ match macro_call_as_call_id (
1228+ ast_id,
1229+ * expand_to,
1230+ self . db ,
1231+ self . def_map . krate ,
1232+ |path| {
1233+ let resolved_res = self . def_map . resolve_path_fp_with_macro (
1234+ self . db ,
1235+ ResolveMode :: Other ,
1236+ directive. module_id ,
1237+ & path,
1238+ BuiltinShadowMode :: Module ,
1239+ ) ;
1240+ resolved_res. resolved_def . take_macros ( )
1241+ } ,
1242+ & mut |_| ( ) ,
1243+ ) {
1244+ Ok ( _) => ( ) ,
1245+ Err ( UnresolvedMacro { path } ) => {
1246+ self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_macro_call (
1247+ directive. module_id ,
1248+ ast_id. ast_id ,
1249+ path,
1250+ ) ) ;
1251+ }
12501252 }
1251- } ,
1253+ }
12521254 MacroDirectiveKind :: Derive { .. } | MacroDirectiveKind :: Attr { .. } => {
12531255 // FIXME: we might want to diagnose this too
12541256 }
@@ -1899,7 +1901,7 @@ impl ModCollector<'_, '_> {
18991901 let mut error = None ;
19001902 match macro_call_as_call_id (
19011903 & ast_id,
1902- mac. fragment ,
1904+ mac. expand_to ,
19031905 self . def_collector . db ,
19041906 self . def_collector . def_map . krate ,
19051907 |path| {
@@ -1930,12 +1932,11 @@ impl ModCollector<'_, '_> {
19301932 // Built-in macro failed eager expansion.
19311933
19321934 // FIXME: don't parse the file here
1933- let fragment = hir_expand:: to_fragment_kind (
1934- & ast_id. ast_id . to_node ( self . def_collector . db . upcast ( ) ) ,
1935- ) ;
1935+ let macro_call = ast_id. ast_id . to_node ( self . def_collector . db . upcast ( ) ) ;
1936+ let expand_to = hir_expand:: ExpandTo :: from_call_site ( & macro_call) ;
19361937 self . def_collector . def_map . diagnostics . push ( DefDiagnostic :: macro_error (
19371938 self . module_id ,
1938- MacroCallKind :: FnLike { ast_id : ast_id. ast_id , fragment } ,
1939+ MacroCallKind :: FnLike { ast_id : ast_id. ast_id , expand_to } ,
19391940 error. unwrap ( ) . to_string ( ) ,
19401941 ) ) ;
19411942 return ;
@@ -1947,7 +1948,7 @@ impl ModCollector<'_, '_> {
19471948 self . def_collector . unresolved_macros . push ( MacroDirective {
19481949 module_id : self . module_id ,
19491950 depth : self . macro_depth + 1 ,
1950- kind : MacroDirectiveKind :: FnLike { ast_id, fragment : mac. fragment } ,
1951+ kind : MacroDirectiveKind :: FnLike { ast_id, expand_to : mac. expand_to } ,
19511952 } ) ;
19521953 }
19531954
0 commit comments