Closed
Description
I tried this code:
use std::convert::{TryFrom, TryInto};
pub fn main() {
{
let _: String = "".to_owned().try_into().unwrap();
}
{
if String::from("a") == "a".try_into().unwrap() {}
}
{
let _: String = match "_".try_into() {
Ok(a) => a,
Err(_) => "".into(),
};
}
}
This caused an error
error[E0283]: type annotations needed for `std::string::String`
--> src/main.rs:8:30
|
5 | let _: String = "".to_owned().try_into().unwrap();
| - consider giving this pattern a type
...
8 | if String::from("a") == "a".try_into().unwrap() {}
| ^^ cannot infer type for struct `std::string::String`
|
= note: cannot satisfy `std::string::String: std::cmp::PartialEq<_>`
however there is not relation between lines 5 and lines 8 as far as I understand which makes this weird.
The lines are not even in the same scope.
Meta
rustc --version --verbose
:
1.45.0-nightly
(2020-05-25 f93bb2a50b37bc8bafe4)
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Type inferenceCategory: This is a bug.Diagnostics: A diagnostic that is giving misleading or incorrect information.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Relevant to the compiler team, which will review and decide on the PR/issue.