|
| 1 | +error[E0277]: a value of type `Vec<X>` cannot be built from an iterator over elements of type `&X` |
| 2 | + --> $DIR/invalid-iterator-chain-fixable.rs:7:7 |
| 3 | + | |
| 4 | +LL | let i = i.map(|x| x.clone()); |
| 5 | + | ------- this method call is cloning the reference `&X`, not `X` which doesn't implement `Clone` |
| 6 | +LL | i.collect() |
| 7 | + | ^^^^^^^ value of type `Vec<X>` cannot be built from `std::iter::Iterator<Item=&X>` |
| 8 | + | |
| 9 | + = help: the trait `FromIterator<&X>` is not implemented for `Vec<X>` |
| 10 | + = help: the trait `FromIterator<X>` is implemented for `Vec<X>` |
| 11 | + = help: for that trait implementation, expected `X`, found `&X` |
| 12 | +note: the method call chain might not have had the expected associated types |
| 13 | + --> $DIR/invalid-iterator-chain-fixable.rs:5:26 |
| 14 | + | |
| 15 | +LL | fn iter_to_vec<'b, X>(i: Iter<'b, X>) -> Vec<X> { |
| 16 | + | ^^^^^^^^^^^ `Iterator::Item` is `&X` here |
| 17 | +LL | let i = i.map(|x| x.clone()); |
| 18 | + | ------------------ `Iterator::Item` remains `&X` here |
| 19 | +note: required by a bound in `collect` |
| 20 | + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL |
| 21 | +help: consider further restricting type parameter `X` |
| 22 | + | |
| 23 | +LL | fn iter_to_vec<'b, X>(i: Iter<'b, X>) -> Vec<X> where X: Clone { |
| 24 | + | ++++++++++++++ |
| 25 | + |
| 26 | +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` |
| 27 | + --> $DIR/invalid-iterator-chain-fixable.rs:17:33 |
| 28 | + | |
| 29 | +LL | println!("{}", scores.sum::<i32>()); |
| 30 | + | --- ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` |
| 31 | + | | |
| 32 | + | required by a bound introduced by this call |
| 33 | + | |
| 34 | + = help: the trait `Sum<()>` is not implemented for `i32` |
| 35 | + = help: the following other types implement trait `Sum<A>`: |
| 36 | + <i32 as Sum> |
| 37 | + <i32 as Sum<&'a i32>> |
| 38 | +note: the method call chain might not have had the expected associated types |
| 39 | + --> $DIR/invalid-iterator-chain-fixable.rs:14:10 |
| 40 | + | |
| 41 | +LL | let v = vec![(0, 0)]; |
| 42 | + | ------------ this expression has type `Vec<({integer}, {integer})>` |
| 43 | +LL | let scores = v |
| 44 | +LL | .iter() |
| 45 | + | ------ `Iterator::Item` is `&({integer}, {integer})` here |
| 46 | +LL | .map(|(a, b)| { |
| 47 | + | __________^ |
| 48 | +LL | | a + b; |
| 49 | +LL | | }); |
| 50 | + | |__________^ `Iterator::Item` changed to `()` here |
| 51 | +note: required by a bound in `std::iter::Iterator::sum` |
| 52 | + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL |
| 53 | +help: consider removing this semicolon |
| 54 | + | |
| 55 | +LL - a + b; |
| 56 | +LL + a + b |
| 57 | + | |
| 58 | + |
| 59 | +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` |
| 60 | + --> $DIR/invalid-iterator-chain-fixable.rs:25:20 |
| 61 | + | |
| 62 | +LL | .sum::<i32>(), |
| 63 | + | --- ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` |
| 64 | + | | |
| 65 | + | required by a bound introduced by this call |
| 66 | + | |
| 67 | + = help: the trait `Sum<()>` is not implemented for `i32` |
| 68 | + = help: the following other types implement trait `Sum<A>`: |
| 69 | + <i32 as Sum> |
| 70 | + <i32 as Sum<&'a i32>> |
| 71 | +note: the method call chain might not have had the expected associated types |
| 72 | + --> $DIR/invalid-iterator-chain-fixable.rs:23:14 |
| 73 | + | |
| 74 | +LL | vec![0, 1] |
| 75 | + | ---------- this expression has type `Vec<{integer}>` |
| 76 | +LL | .iter() |
| 77 | + | ------ `Iterator::Item` is `&{integer}` here |
| 78 | +LL | .map(|x| x * 2) |
| 79 | + | -------------- `Iterator::Item` changed to `{integer}` here |
| 80 | +LL | .map(|x| { x; }) |
| 81 | + | ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here |
| 82 | +LL | .map(|x| { x }) |
| 83 | + | -------------- `Iterator::Item` remains `()` here |
| 84 | +note: required by a bound in `std::iter::Iterator::sum` |
| 85 | + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL |
| 86 | +help: consider removing this semicolon |
| 87 | + | |
| 88 | +LL - .map(|x| { x; }) |
| 89 | +LL + .map(|x| { x }) |
| 90 | + | |
| 91 | + |
| 92 | +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` |
| 93 | + --> $DIR/invalid-iterator-chain-fixable.rs:27:60 |
| 94 | + | |
| 95 | +LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); |
| 96 | + | --- ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` |
| 97 | + | | |
| 98 | + | required by a bound introduced by this call |
| 99 | + | |
| 100 | + = help: the trait `Sum<()>` is not implemented for `i32` |
| 101 | + = help: the following other types implement trait `Sum<A>`: |
| 102 | + <i32 as Sum> |
| 103 | + <i32 as Sum<&'a i32>> |
| 104 | +note: the method call chain might not have had the expected associated types |
| 105 | + --> $DIR/invalid-iterator-chain-fixable.rs:27:38 |
| 106 | + | |
| 107 | +LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); |
| 108 | + | ---------- ------ ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here |
| 109 | + | | | |
| 110 | + | | `Iterator::Item` is `&{integer}` here |
| 111 | + | this expression has type `Vec<{integer}>` |
| 112 | +note: required by a bound in `std::iter::Iterator::sum` |
| 113 | + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL |
| 114 | +help: consider removing this semicolon |
| 115 | + | |
| 116 | +LL - println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); |
| 117 | +LL + println!("{}", vec![0, 1].iter().map(|x| { x }).sum::<i32>()); |
| 118 | + | |
| 119 | + |
| 120 | +error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over elements of type `()` |
| 121 | + --> $DIR/invalid-iterator-chain-fixable.rs:36:25 |
| 122 | + | |
| 123 | +LL | let g: Vec<i32> = f.collect(); |
| 124 | + | ^^^^^^^ value of type `Vec<i32>` cannot be built from `std::iter::Iterator<Item=()>` |
| 125 | + | |
| 126 | + = help: the trait `FromIterator<()>` is not implemented for `Vec<i32>` |
| 127 | + = help: the trait `FromIterator<i32>` is implemented for `Vec<i32>` |
| 128 | + = help: for that trait implementation, expected `i32`, found `()` |
| 129 | +note: the method call chain might not have had the expected associated types |
| 130 | + --> $DIR/invalid-iterator-chain-fixable.rs:32:15 |
| 131 | + | |
| 132 | +LL | let a = vec![0]; |
| 133 | + | ------- this expression has type `Vec<{integer}>` |
| 134 | +LL | let b = a.into_iter(); |
| 135 | + | ----------- `Iterator::Item` is `{integer}` here |
| 136 | +LL | let c = b.map(|x| x + 1); |
| 137 | + | -------------- `Iterator::Item` remains `{integer}` here |
| 138 | +LL | let d = c.filter(|x| *x > 10 ); |
| 139 | + | -------------------- `Iterator::Item` remains `{integer}` here |
| 140 | +LL | let e = d.map(|x| { |
| 141 | + | _______________^ |
| 142 | +LL | | x + 1; |
| 143 | +LL | | }); |
| 144 | + | |______^ `Iterator::Item` changed to `()` here |
| 145 | +LL | let f = e.filter(|_| false); |
| 146 | + | ----------------- `Iterator::Item` remains `()` here |
| 147 | +note: required by a bound in `collect` |
| 148 | + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL |
| 149 | +help: consider removing this semicolon |
| 150 | + | |
| 151 | +LL - x + 1; |
| 152 | +LL + x + 1 |
| 153 | + | |
| 154 | + |
| 155 | +error: aborting due to 5 previous errors |
| 156 | + |
| 157 | +For more information about this error, try `rustc --explain E0277`. |
0 commit comments