File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -1013,6 +1013,21 @@ impl TypedAstContext {
10131013 }
10141014 }
10151015
1016+ /// Sort the top-level declarations with macros coming last.
1017+ /// This is needed during conversion so that when recreating macros,
1018+ /// we can look up the [`Translation::expr_override_tys`],
1019+ /// which are set when the macro expansion expressions are converted.
1020+ pub fn sort_top_decls_for_converting ( & mut self ) {
1021+ self . c_decls_top . sort_unstable_by_key ( |decl_id| {
1022+ let reverse_order = match self . c_decls . get ( decl_id) . unwrap ( ) . kind {
1023+ CDeclKind :: MacroFunction { .. } => 0 ,
1024+ CDeclKind :: MacroObject { .. } => 1 ,
1025+ _ => 2 ,
1026+ } ;
1027+ -reverse_order
1028+ } ) ;
1029+ }
1030+
10161031 /// Sort the top-level declarations by file and source location
10171032 /// so that we preserve the ordering of all declarations in each file.
10181033 /// This preserves the order when we emit the converted declarations.
Original file line number Diff line number Diff line change @@ -689,6 +689,8 @@ pub fn translate(
689689 }
690690 }
691691
692+ t. ast_context . sort_top_decls_for_converting ( ) ;
693+
692694 // Export top-level value declarations.
693695 // We do this in a conversion pass and then an insertion pass
694696 // so that the conversion order can differ from the order they're emitted in.
You can’t perform that action at this time.
0 commit comments