forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#116717 - estebank:issue-9082, r=oli-obk
Special case iterator chain checks for suggestion When encountering method call chains of `Iterator`, check for trailing `;` in the body of closures passed into `Iterator::map`, as well as calls to `<T as Clone>::clone` when `T` is a type param and `T: !Clone`. Fix rust-lang#9082.
- Loading branch information
Showing
5 changed files
with
393 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// run-rustfix | ||
use std::collections::hash_set::Iter; | ||
use std::collections::HashSet; | ||
|
||
fn iter_to_vec<'b, X>(i: Iter<'b, X>) -> Vec<X> where X: Clone { | ||
let i = i.map(|x| x.clone()); | ||
i.collect() //~ ERROR E0277 | ||
} | ||
|
||
fn main() { | ||
let v = vec![(0, 0)]; | ||
let scores = v | ||
.iter() | ||
.map(|(a, b)| { | ||
a + b | ||
}); | ||
println!("{}", scores.sum::<i32>()); //~ ERROR E0277 | ||
println!( | ||
"{}", | ||
vec![0, 1] | ||
.iter() | ||
.map(|x| x * 2) | ||
.map(|x| { x }) | ||
.map(|x| { x }) | ||
.sum::<i32>(), //~ ERROR E0277 | ||
); | ||
println!("{}", vec![0, 1].iter().map(|x| { x }).sum::<i32>()); //~ ERROR E0277 | ||
let a = vec![0]; | ||
let b = a.into_iter(); | ||
let c = b.map(|x| x + 1); | ||
let d = c.filter(|x| *x > 10 ); | ||
let e = d.map(|x| { | ||
x + 1 | ||
}); | ||
let f = e.filter(|_| false); | ||
let g: Vec<i32> = f.collect(); //~ ERROR E0277 | ||
println!("{g:?}"); | ||
|
||
let mut s = HashSet::new(); | ||
s.insert(1u8); | ||
println!("{:?}", iter_to_vec(s.iter())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// run-rustfix | ||
use std::collections::hash_set::Iter; | ||
use std::collections::HashSet; | ||
|
||
fn iter_to_vec<'b, X>(i: Iter<'b, X>) -> Vec<X> { | ||
let i = i.map(|x| x.clone()); | ||
i.collect() //~ ERROR E0277 | ||
} | ||
|
||
fn main() { | ||
let v = vec![(0, 0)]; | ||
let scores = v | ||
.iter() | ||
.map(|(a, b)| { | ||
a + b; | ||
}); | ||
println!("{}", scores.sum::<i32>()); //~ ERROR E0277 | ||
println!( | ||
"{}", | ||
vec![0, 1] | ||
.iter() | ||
.map(|x| x * 2) | ||
.map(|x| { x; }) | ||
.map(|x| { x }) | ||
.sum::<i32>(), //~ ERROR E0277 | ||
); | ||
println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); //~ ERROR E0277 | ||
let a = vec![0]; | ||
let b = a.into_iter(); | ||
let c = b.map(|x| x + 1); | ||
let d = c.filter(|x| *x > 10 ); | ||
let e = d.map(|x| { | ||
x + 1; | ||
}); | ||
let f = e.filter(|_| false); | ||
let g: Vec<i32> = f.collect(); //~ ERROR E0277 | ||
println!("{g:?}"); | ||
|
||
let mut s = HashSet::new(); | ||
s.insert(1u8); | ||
println!("{:?}", iter_to_vec(s.iter())); | ||
} |
Oops, something went wrong.