@@ -2194,25 +2194,23 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
21942194 unsigned numDiagnostics =
21952195 moveChecker.diagnosticEmitter .getDiagnosticCount ();
21962196
2197- // Before we do anything, run the borrow to destructure transform in case
2198- // we have a switch_enum user.
2199- if (!getASTContext ().LangOpts .hasFeature (Feature::BorrowingSwitch)) {
2200- BorrowToDestructureTransform borrowToDestructure (
2201- moveChecker.allocator , markedValue, li, moveChecker.diagnosticEmitter ,
2202- moveChecker.poa );
2203- if (!borrowToDestructure.transform ()) {
2204- assert (moveChecker.diagnosticEmitter
2205- .didEmitCheckerDoesntUnderstandDiagnostic ());
2206- LLVM_DEBUG (llvm::dbgs ()
2207- << " Failed to perform borrow to destructure transform!\n " );
2208- return false ;
2209- }
2210- // If we emitted an error diagnostic, do not transform further and instead
2211- // mark that we emitted an early diagnostic and return true.
2212- if (numDiagnostics != moveChecker.diagnosticEmitter .getDiagnosticCount ()) {
2213- LLVM_DEBUG (llvm::dbgs () << " Emitting borrow to destructure error!\n " );
2214- return true ;
2215- }
2197+ // Before we do anything, run the borrow to destructure transform to reduce
2198+ // copies through borrows.
2199+ BorrowToDestructureTransform borrowToDestructure (
2200+ moveChecker.allocator , markedValue, li, moveChecker.diagnosticEmitter ,
2201+ moveChecker.poa );
2202+ if (!borrowToDestructure.transform ()) {
2203+ assert (moveChecker.diagnosticEmitter
2204+ .didEmitCheckerDoesntUnderstandDiagnostic ());
2205+ LLVM_DEBUG (llvm::dbgs ()
2206+ << " Failed to perform borrow to destructure transform!\n " );
2207+ return false ;
2208+ }
2209+ // If we emitted an error diagnostic, do not transform further and instead
2210+ // mark that we emitted an early diagnostic and return true.
2211+ if (numDiagnostics != moveChecker.diagnosticEmitter .getDiagnosticCount ()) {
2212+ LLVM_DEBUG (llvm::dbgs () << " Emitting borrow to destructure error!\n " );
2213+ return true ;
22162214 }
22172215
22182216 // Now, validate that what we will transform into a take isn't a take that
0 commit comments