Closed
Description
This code:
use rand::Rng;
use std::net::Ipv4Addr;
fn main() {
let rng = rand::thread_rng();
let ips: Vec<_> = (0..100_000).map(|_| Ipv4Addr::from(rng.gen())).collect();
}
Produces:
error[E0283]: type annotations needed for `Vec<Ipv4Addr>`
--> src/main.rs:6:44
|
6 | let ips: Vec<_> = (0..100_000).map(|_| Ipv4Addr::from(rng.gen())).collect();
| --- ^^^^^^^^^^^^^^ cannot infer type for struct `Ipv4Addr`
| |
| consider giving `ips` the explicit type `Vec<Ipv4Addr>`, where the type parameter `Ipv4Addr` is specified
|
= note: cannot satisfy `Ipv4Addr: From<_>`
= note: required by `from`
At least following the suggestion doesn't result in the error message going any farther off the rails, but it does look quite silly:
error[E0283]: type annotations needed for `Vec<Ipv4Addr>`
--> src/main.rs:6:51
|
6 | let ips: Vec<Ipv4Addr> = (0..100_000).map(|_| Ipv4Addr::from(rng.gen())).collect();
| --- ^^^^^^^^^^^^^^ cannot infer type for struct `Ipv4Addr`
| |
| consider giving `ips` the explicit type `Vec<Ipv4Addr>`, where the type parameter `Ipv4Addr` is specified
|
= note: cannot satisfy `Ipv4Addr: From<_>`
= note: required by `from`
Diagnostics pasted from rustc 1.49.0-nightly (e3051d8c2 2020-10-16)
, but same behavior on stable 1.47.0.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Type inferenceCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.