@@ -396,7 +396,7 @@ void swift::conformToCxxSequenceIfNeeded(
396396 if (!cxxIteratorProto || !cxxSequenceProto)
397397 return ;
398398
399- // Check if present: `mutating func __beginUnsafe() -> RawIterator`
399+ // Check if present: `func __beginUnsafe() -> RawIterator`
400400 auto beginId = ctx.getIdentifier (" __beginUnsafe" );
401401 auto begins = lookupDirectWithoutExtensions (decl, beginId);
402402 if (begins.size () != 1 )
@@ -406,7 +406,7 @@ void swift::conformToCxxSequenceIfNeeded(
406406 return ;
407407 auto rawIteratorTy = begin->getResultInterfaceType ();
408408
409- // Check if present: `mutating func __endUnsafe() -> RawIterator`
409+ // Check if present: `func __endUnsafe() -> RawIterator`
410410 auto endId = ctx.getIdentifier (" __endUnsafe" );
411411 auto ends = lookupDirectWithoutExtensions (decl, endId);
412412 if (ends.size () != 1 )
@@ -415,6 +415,10 @@ void swift::conformToCxxSequenceIfNeeded(
415415 if (!end)
416416 return ;
417417
418+ // Check if `begin()` and `end()` are non-mutating.
419+ if (begin->isMutating () || end->isMutating ())
420+ return ;
421+
418422 // Check if `__beginUnsafe` and `__endUnsafe` have the same return type.
419423 auto endTy = end->getResultInterfaceType ();
420424 if (!endTy || endTy->getCanonicalType () != rawIteratorTy->getCanonicalType ())
@@ -468,10 +472,6 @@ void swift::conformToCxxSequenceIfNeeded(
468472 !ctx.getProtocol (KnownProtocolKind::CxxRandomAccessCollection))
469473 return false ;
470474
471- // Check if `begin()` and `end()` are non-mutating.
472- if (begin->isMutating () || end->isMutating ())
473- return false ;
474-
475475 // Check if RawIterator conforms to UnsafeCxxRandomAccessIterator.
476476 auto rawIteratorRAConformanceRef =
477477 decl->getModuleContext ()->lookupConformance (rawIteratorTy,
0 commit comments