-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.S-needs-discussionStatus: Needs further discussion before merging or work can be startedStatus: Needs further discussion before merging or work can be startedT-middleType: Probably requires verifiying typesType: Probably requires verifiying types
Description
For the snippet below, clippy suggests changing while let Some(i) = self.s.next()
into for i in self.s { .. }
, but that results in a "cannot move out of borrowed content" error. In this case, for i in &mut self.s { .. }
would work.
pub struct S {
i: i32,
}
impl Iterator for S {
type Item = i32;
fn next(&mut self) -> Option<i32> {
if self.i > 0 {
self.i -= 1;
Some(self.i)
} else {
None
}
}
}
pub struct T {
s: S,
}
impl Iterator for T {
type Item = i32;
fn next(&mut self) -> Option<i32> {
while let Some(i) = self.s.next() {
if i < 3 || i > 7 {
return Some(i);
}
}
None
}
}
#[test]
fn test() {
let s = S { i: 9 };
let mut t = T { s };
assert_eq!(t.next(), Some(8));
assert_eq!(t.next(), Some(2));
assert_eq!(t.next(), Some(1));
assert_eq!(t.next(), Some(0));
assert_eq!(t.next(), None);
}
marcusklaas and shaleh
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.S-needs-discussionStatus: Needs further discussion before merging or work can be startedStatus: Needs further discussion before merging or work can be startedT-middleType: Probably requires verifiying typesType: Probably requires verifiying types