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#107173 - clubby789:suggest-array-length, r=…
…compiler-errors Suggest the correct array length on mismatch Fixes rust-lang#107156 I wasn't able to find a way to get the `Span` for the actual array size unfortunately, so this suggestion can't be applied automatically. `@rustbot` label +A-diagnostics
- Loading branch information
Showing
6 changed files
with
119 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const NUMBERS: [u8; 3] = [10, 20]; | ||
//~^ ERROR mismatched types | ||
//~^^ HELP consider specifying the actual array length | ||
fn main() {} |
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,11 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/array-literal-len-mismatch.rs:1:26 | ||
| | ||
LL | const NUMBERS: [u8; 3] = [10, 20]; | ||
| - ^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements | ||
| | | ||
| help: consider specifying the actual array length: `2` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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,12 @@ | ||
fn returns_arr() -> [u8; 2] { | ||
[1, 2] | ||
} | ||
|
||
fn main() { | ||
let wrong: [u8; 3] = [10, 20]; | ||
//~^ ERROR mismatched types | ||
//~^^ HELP consider specifying the actual array length | ||
let wrong: [u8; 3] = returns_arr(); | ||
//~^ ERROR mismatched types | ||
//~^^ HELP consider specifying the actual array length | ||
} |
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,21 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/array-len-mismatch.rs:6:26 | ||
| | ||
LL | let wrong: [u8; 3] = [10, 20]; | ||
| ------- ^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements | ||
| | | | ||
| | help: consider specifying the actual array length: `2` | ||
| expected due to this | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/array-len-mismatch.rs:9:26 | ||
| | ||
LL | let wrong: [u8; 3] = returns_arr(); | ||
| ------- ^^^^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements | ||
| | | | ||
| | help: consider specifying the actual array length: `2` | ||
| expected due to this | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |