Closed
Description
This compiles just fine:
fn main() {
// vec!["hello"]
// .iter_mut()
// .map(|x| String::from(x.as_ref()))
// .collect::<Vec<String>>();
vec![String::from("First"), String::from("Second")]
.iter()
.find(|s| *s == "Second");
}
But this gives a compiler error:
fn main() {
vec!["hello"]
.iter_mut()
.map(|x| String::from(x.as_ref()))
.collect::<Vec<String>>();
vec![String::from("First"), String::from("Second")]
.iter()
.find(|s| *s == "Second");
}
error[E0283]: type annotations needed for `&&std::string::String`
--> src/main.rs:9:16
|
9 | .find(|s| *s == "Second");
| ^ consider giving this closure parameter the explicit type `&&std::string::String`, where the type parameter `std::string::String` is specified
|
= note: cannot resolve `std::string::String: std::convert::From<&_>`
= note: required by `std::convert::From::from`
error: aborting due to previous error
error: could not compile `programname`.
To learn more, run the command again with --verbose.
It seems really weird that the second statement is affected like this?
Meta
$ rustc --version --verbose
rustc 1.43.1 (8d69840ab 2020-05-04)
binary: rustc
commit-hash: 8d69840ab92ea7f4d323420088dd8c9775f180cd
commit-date: 2020-05-04
host: x86_64-unknown-linux-gnu
release: 1.43.1
LLVM version: 9.0
Empty project (created with cargo new
), unmodified Cargo.toml (so no extra dependencies):
[package]
name = "programname"
version = "0.1.0"
authors = ["..."]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
This issue has been assigned to @doctorn via this comment.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Type inferenceCategory: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: A diagnostic that is giving misleading or incorrect information.Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcHigh priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.