Closed
Description
fn main() {
let array = [1, 2, 3];
test(array.len());
}
fn test(length: u32) {
println!("{}", length);
}
Gives the following compile time error on rustc 1.22.1 (stable):
Compiling playground v0.0.1 (file:///playground)
error[E0308]: mismatched types
--> src/main.rs:3:10
|
3 | test(array.len());
| ^^^^^^^^^^^ expected u32, found usize
|
= help: here are some functions which might fulfill your needs:
- .count_ones()
- .count_zeros()
- .leading_zeros()
- .trailing_zeros()
error: aborting due to previous error
error: Could not compile `playground`.
I'm assuming there's a lot of nuance in the engine that gives suggestion so I don't know how I would personally codify the rules (and even if casting as a u32 is always appropriate since I guess it could overflow) but I do know that the suggestions definitely do not point me in the right direction.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Working group: Diagnostics