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#88578 - notriddle:notriddle/suggest-add-ref…
…erence-to-for-loop-iter, r=nagisa fix(rustc): suggest `items` be borrowed in `for i in items[x..]` Fixes rust-lang#87994
- Loading branch information
Showing
4 changed files
with
105 additions
and
6 deletions.
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
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,16 @@ | ||
fn main() { | ||
let v = vec![1i32, 2, 3]; | ||
for _ in v[1..] { | ||
//~^ ERROR [i32]` is not an iterator [E0277] | ||
//~^^ ERROR known at compilation time | ||
} | ||
struct K { | ||
n: i32, | ||
} | ||
let mut v2 = vec![K { n: 1 }, K { n: 1 }, K { n: 1 }]; | ||
for i2 in v2[1..] { | ||
//~^ ERROR [K]` is not an iterator [E0277] | ||
//~^^ ERROR known at compilation time | ||
i2.n = 2; | ||
} | ||
} |
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,71 @@ | ||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time | ||
--> $DIR/slice-issue-87994.rs:3:12 | ||
| | ||
LL | for _ in v[1..] { | ||
| ^^^^^^ | ||
| | | ||
| expected an implementor of trait `IntoIterator` | ||
| help: consider borrowing here: `&v[1..]` | ||
| | ||
= note: the trait bound `[i32]: IntoIterator` is not satisfied | ||
= note: required because of the requirements on the impl of `IntoIterator` for `[i32]` | ||
note: required by `into_iter` | ||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL | ||
| | ||
LL | fn into_iter(self) -> Self::IntoIter; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `[i32]` is not an iterator | ||
--> $DIR/slice-issue-87994.rs:3:12 | ||
| | ||
LL | for _ in v[1..] { | ||
| ^^^^^^ | ||
| | | ||
| expected an implementor of trait `IntoIterator` | ||
| help: consider borrowing here: `&v[1..]` | ||
| | ||
= note: the trait bound `[i32]: IntoIterator` is not satisfied | ||
= note: required because of the requirements on the impl of `IntoIterator` for `[i32]` | ||
note: required by `into_iter` | ||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL | ||
| | ||
LL | fn into_iter(self) -> Self::IntoIter; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: the size for values of type `[K]` cannot be known at compilation time | ||
--> $DIR/slice-issue-87994.rs:11:13 | ||
| | ||
LL | for i2 in v2[1..] { | ||
| ^^^^^^^ | ||
| | | ||
| expected an implementor of trait `IntoIterator` | ||
| help: consider borrowing here: `&v2[1..]` | ||
| | ||
= note: the trait bound `[K]: IntoIterator` is not satisfied | ||
= note: required because of the requirements on the impl of `IntoIterator` for `[K]` | ||
note: required by `into_iter` | ||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL | ||
| | ||
LL | fn into_iter(self) -> Self::IntoIter; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `[K]` is not an iterator | ||
--> $DIR/slice-issue-87994.rs:11:13 | ||
| | ||
LL | for i2 in v2[1..] { | ||
| ^^^^^^^ | ||
| | | ||
| expected an implementor of trait `IntoIterator` | ||
| help: consider borrowing here: `&v2[1..]` | ||
| | ||
= note: the trait bound `[K]: IntoIterator` is not satisfied | ||
= note: required because of the requirements on the impl of `IntoIterator` for `[K]` | ||
note: required by `into_iter` | ||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL | ||
| | ||
LL | fn into_iter(self) -> Self::IntoIter; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |