@@ -936,7 +936,9 @@ Session::expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx)
936
936
MacroExpander expander (crate, cfg, *this );
937
937
std::vector<Error> macro_errors;
938
938
939
- while (!fixed_point_reached && iterations < cfg.recursion_limit )
939
+ bool did_desugar = false ;
940
+
941
+ while (!fixed_point_reached)
940
942
{
941
943
CfgStrip ().go (crate);
942
944
// Errors might happen during cfg strip pass
@@ -958,8 +960,22 @@ Session::expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx)
958
960
ExpandVisitor (expander).go (crate);
959
961
960
962
fixed_point_reached = !expander.has_changed () && !visitor_dirty;
963
+
964
+ if (fixed_point_reached && macro_errors.is_empty () && !did_desugar)
965
+ {
966
+ AST::DesugarForLoops ().go (crate);
967
+ AST::DesugarQuestionMark ().go (crate);
968
+ AST::DesugarApit ().go (crate);
969
+
970
+ fixed_point_reached = false ;
971
+ did_desugar = true ;
972
+ }
973
+ else
974
+ {
975
+ fixed_point_reached |= (++iterations == cfg.recursion_limit );
976
+ }
977
+
961
978
expander.reset_changed_state ();
962
- iterations++;
963
979
964
980
if (saw_errors ())
965
981
break ;
@@ -982,20 +998,6 @@ Session::expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx)
982
998
rust_error_at (range, " reached recursion limit" );
983
999
}
984
1000
985
- // handle AST desugaring
986
- if (!saw_errors ())
987
- {
988
- AST::DesugarForLoops ().go (crate);
989
- AST::DesugarQuestionMark ().go (crate);
990
- AST::DesugarApit ().go (crate);
991
-
992
- // HACK: we may need a final TopLevel pass
993
- // however, this should not count towards the recursion limit
994
- // and we don't need a full Early pass
995
- if (flag_name_resolution_2_0)
996
- Resolver2_0::TopLevel (ctx).go (crate);
997
- }
998
-
999
1001
// error reporting - check unused macros, get missing fragment specifiers
1000
1002
1001
1003
// build test harness
0 commit comments