Skip to content

Commit 6f99c15

Browse files
authored
Merge pull request #2006 from Abhinav-ranish/fix/1982-iter-find-comments
fix: correct iter/into_iter type comments in iter_find example
2 parents 321dc45 + 8e15148 commit 6f99c15

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/fn/closures/closure_examples/iter_find.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ fn main() {
4242
let array1 = [1, 2, 3];
4343
let array2 = [4, 5, 6];
4444
45-
// `array1.iter()` yields `&i32`
45+
// `array1.iter()` yields `&i32`, and `find` passes `&Item` to the
46+
// predicate. Since `Item = &i32`, the closure argument has type `&&i32`.
4647
println!("Find 2 in array1: {:?}", array1.iter().find(|&&x| x == 2));
47-
// `array2.into_iter()` yields `i32`
48+
// `array2.into_iter()` yields `i32` (since Rust 2021 edition), and
49+
// `find` passes `&Item` to the predicate. Since `Item = i32`, the
50+
// closure argument has type `&i32`.
4851
println!("Find 2 in array2: {:?}", array2.into_iter().find(|&x| x == 2));
4952
}
5053
```

0 commit comments

Comments
 (0)