@@ -396,7 +396,7 @@ void swift::conformToCxxSequenceIfNeeded(
396
396
if (!cxxIteratorProto || !cxxSequenceProto)
397
397
return ;
398
398
399
- // Check if present: `mutating func __beginUnsafe() -> RawIterator`
399
+ // Check if present: `func __beginUnsafe() -> RawIterator`
400
400
auto beginId = ctx.getIdentifier (" __beginUnsafe" );
401
401
auto begins = lookupDirectWithoutExtensions (decl, beginId);
402
402
if (begins.size () != 1 )
@@ -406,7 +406,7 @@ void swift::conformToCxxSequenceIfNeeded(
406
406
return ;
407
407
auto rawIteratorTy = begin->getResultInterfaceType ();
408
408
409
- // Check if present: `mutating func __endUnsafe() -> RawIterator`
409
+ // Check if present: `func __endUnsafe() -> RawIterator`
410
410
auto endId = ctx.getIdentifier (" __endUnsafe" );
411
411
auto ends = lookupDirectWithoutExtensions (decl, endId);
412
412
if (ends.size () != 1 )
@@ -415,6 +415,10 @@ void swift::conformToCxxSequenceIfNeeded(
415
415
if (!end)
416
416
return ;
417
417
418
+ // Check if `begin()` and `end()` are non-mutating.
419
+ if (begin->isMutating () || end->isMutating ())
420
+ return ;
421
+
418
422
// Check if `__beginUnsafe` and `__endUnsafe` have the same return type.
419
423
auto endTy = end->getResultInterfaceType ();
420
424
if (!endTy || endTy->getCanonicalType () != rawIteratorTy->getCanonicalType ())
@@ -468,10 +472,6 @@ void swift::conformToCxxSequenceIfNeeded(
468
472
!ctx.getProtocol (KnownProtocolKind::CxxRandomAccessCollection))
469
473
return false ;
470
474
471
- // Check if `begin()` and `end()` are non-mutating.
472
- if (begin->isMutating () || end->isMutating ())
473
- return false ;
474
-
475
475
// Check if RawIterator conforms to UnsafeCxxRandomAccessIterator.
476
476
auto rawIteratorRAConformanceRef =
477
477
decl->getModuleContext ()->lookupConformance (rawIteratorTy,
0 commit comments