menu
redundant-iter-cloned
Disallow cloning iterator elements that are only borrowed afterward
Cloning iterator elements is unnecessary when the following operation only observes them through readonly borrows. Instead, you SHOULD operate on the borrowed elements directly.
Reported
1import { Iterator } from "destack:iter";2 3struct Label {4 values: ^int32[];5}6 7function lengths(values: Iterator<&readonly Label>): Iterator<isize> {8 return values.cloned().map((value) => value.values.length);9}Accepted
1import { Iterator } from "destack:iter";2 3struct Label {4 values: ^int32[];5}6 7function lengths(values: Iterator<&readonly Label>): Iterator<isize> {8 return values.map((value) => value.values.length);9}