]> git.lizzy.rs Git - rust.git/blob - tests/ui/iterators/iter-cloned-type-inference.rs
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
[rust.git] / tests / ui / iterators / iter-cloned-type-inference.rs
1 // run-pass
2 #![allow(stable_features)]
3
4 // Test to see that the element type of .cloned() can be inferred
5 // properly. Previously this would fail to deduce the type of `sum`.
6
7 #![feature(iter_arith)]
8
9 fn square_sum(v: &[i64]) -> i64 {
10     let sum: i64 = v.iter().cloned().sum();
11     sum * sum
12 }
13
14 fn main() {
15     assert_eq!(36, square_sum(&[1,2,3]));
16 }