Avatar
@swift-5.7.3 protocol RethrowsIterator { associatedtype Failure: Error func next() -> Result<Int?, Failure> } struct NonfailableIter: RethrowsIterator { func next() -> Result<Int?, Never> { return .success(1) } } struct FailableIter: RethrowsIterator { func next() -> Result<Int?, Error> { return .success(1) } } func callNextRethrows<T: RethrowsIterator>(_ iter: inout T) -> Result<Int?, T.Failure> { iter.next() } var it = NonfailableIter() let _: Result<Int?, Never> = callNextRethrows(&it) var it2 = FailableIter() _ = try callNextRethrows(&it2).get() (edited)