@@ -958,19 +958,21 @@ impl<'src> ParserState<'src> {
958958 self . breakable_entry_stack
959959 . push ( Breakable :: InlineConditional ( entry) ) ;
960960
961+ // Format in source order — statement before predicate — so that
962+ // `on_line` calls advance in the order of the source
961963 self . with_start_of_line ( false , |ps| {
962- ps. new_block ( format_predicate ) ;
964+ ps. new_block ( format_statement ) ;
963965 } ) ;
964966
965967 self . breakable_entry_stack
966968 . last_mut ( )
967969 . expect ( "just pushed InlineConditional" )
968970 . as_conditional_layout_mut ( )
969971 . expect ( "just pushed InlineConditional" )
970- . switch_to_statement ( ) ;
972+ . switch_to_predicate ( ) ;
971973
972974 self . with_start_of_line ( false , |ps| {
973- ps. new_block ( format_statement ) ;
975+ ps. new_block ( format_predicate ) ;
974976 } ) ;
975977
976978 let cle = self
@@ -980,7 +982,21 @@ impl<'src> ParserState<'src> {
980982 . into_conditional_layout ( )
981983 . expect ( "InlineConditional always returns Some from into_conditional_layout" ) ;
982984
985+ // Preserve any comments that were extracted during the conditional
986+ // (e.g. a trailing `# comment` on the modifier line) so they aren't
987+ // dropped when restoring the comments that were pending beforehand.
988+ // The accumulated comments may have an inner-scope indent baked in
989+ // (from `apply_spaces` at capture time), so re-apply at the
990+ // conditional's outer indent before merging.
991+ let outer_spaces = self . current_spaces ( ) ;
992+ let accumulated = self
993+ . comments_to_insert
994+ . take ( )
995+ . map ( |c| c. apply_spaces ( outer_spaces) ) ;
983996 self . comments_to_insert = saved_comments;
997+ if let Some ( acc) = accumulated {
998+ self . comments_to_insert . merge ( acc) ;
999+ }
9841000
9851001 self . push_target ( ConcreteLineTokenAndTargets :: ConditionalLayoutEntry ( cle) ) ;
9861002 }
0 commit comments