@@ -1138,7 +1138,16 @@ class PrintAST : public ASTVisitor<PrintAST> {
11381138 Printer.callPrintDeclPre (D, Options.BracketOptions );
11391139
11401140 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+
11421151 ASTVisitor::visit (D);
11431152 });
11441153 } else {
@@ -3123,9 +3132,12 @@ static void suppressingFeatureAssociatedTypeImplements(PrintOptions &options,
31233132static void suppressingFeatureNoncopyableGenerics (
31243133 PrintOptions &options,
31253134 llvm::function_ref<void ()> action) {
3135+ unsigned originalExcludeAttrCount = options.ExcludeAttrList .size ();
3136+ options.ExcludeAttrList .push_back (DeclAttrKind::PreInverseGenerics);
31263137 llvm::SaveAndRestore<bool > scope (
31273138 options.SuppressNoncopyableGenerics , true );
31283139 action ();
3140+ options.ExcludeAttrList .resize (originalExcludeAttrCount);
31293141}
31303142
31313143// / Suppress the printing of a particular feature.
@@ -3680,10 +3692,14 @@ static void printParameterFlags(ASTPrinter &printer,
36803692 printer.printKeyword (" inout" , options, " " );
36813693 break ;
36823694 case ParamSpecifier::Borrowing:
3683- printer.printKeyword (" borrowing" , options, " " );
3695+ if (!options.SuppressNoncopyableOwnershipModifiers ) {
3696+ printer.printKeyword (" borrowing" , options, " " );
3697+ }
36843698 break ;
36853699 case ParamSpecifier::Consuming:
3686- printer.printKeyword (" consuming" , options, " " );
3700+ if (!options.SuppressNoncopyableOwnershipModifiers ) {
3701+ printer.printKeyword (" consuming" , options, " " );
3702+ }
36873703 break ;
36883704 case ParamSpecifier::LegacyShared:
36893705 printer.printKeyword (" __shared" , options, " " );
0 commit comments