@@ -1138,7 +1138,16 @@ class PrintAST : public ASTVisitor<PrintAST> {
1138
1138
Printer.callPrintDeclPre (D, Options.BracketOptions );
1139
1139
1140
1140
if (Options.PrintCompatibilityFeatureChecks ) {
1141
- printWithCompatibilityFeatureChecks (Printer, Options, D, [&]{
1141
+ printWithCompatibilityFeatureChecks (Printer, Options, D, [&] {
1142
+ // If we are in a scope where non-copyable generics are being suppressed
1143
+ // and we are also printing a decl that has @_preInverseGenerics, make
1144
+ // sure we also suppress printing ownership modifiers that were added
1145
+ // to satisfy the requirements of non-copyability.
1146
+ llvm::SaveAndRestore<bool > scope (
1147
+ Options.SuppressNoncopyableOwnershipModifiers ,
1148
+ Options.SuppressNoncopyableGenerics &&
1149
+ D->getAttrs ().hasAttribute <PreInverseGenericsAttr>());
1150
+
1142
1151
ASTVisitor::visit (D);
1143
1152
});
1144
1153
} else {
@@ -3123,9 +3132,12 @@ static void suppressingFeatureAssociatedTypeImplements(PrintOptions &options,
3123
3132
static void suppressingFeatureNoncopyableGenerics (
3124
3133
PrintOptions &options,
3125
3134
llvm::function_ref<void ()> action) {
3135
+ unsigned originalExcludeAttrCount = options.ExcludeAttrList .size ();
3136
+ options.ExcludeAttrList .push_back (DeclAttrKind::PreInverseGenerics);
3126
3137
llvm::SaveAndRestore<bool > scope (
3127
3138
options.SuppressNoncopyableGenerics , true );
3128
3139
action ();
3140
+ options.ExcludeAttrList .resize (originalExcludeAttrCount);
3129
3141
}
3130
3142
3131
3143
// / Suppress the printing of a particular feature.
@@ -3680,10 +3692,14 @@ static void printParameterFlags(ASTPrinter &printer,
3680
3692
printer.printKeyword (" inout" , options, " " );
3681
3693
break ;
3682
3694
case ParamSpecifier::Borrowing:
3683
- printer.printKeyword (" borrowing" , options, " " );
3695
+ if (!options.SuppressNoncopyableOwnershipModifiers ) {
3696
+ printer.printKeyword (" borrowing" , options, " " );
3697
+ }
3684
3698
break ;
3685
3699
case ParamSpecifier::Consuming:
3686
- printer.printKeyword (" consuming" , options, " " );
3700
+ if (!options.SuppressNoncopyableOwnershipModifiers ) {
3701
+ printer.printKeyword (" consuming" , options, " " );
3702
+ }
3687
3703
break ;
3688
3704
case ParamSpecifier::LegacyShared:
3689
3705
printer.printKeyword (" __shared" , options, " " );
0 commit comments