Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type annotation warning involving completely unrelated scopes #72616

Closed
matthiaskrgr opened this issue May 26, 2020 · 1 comment · Fixed by #78265
Closed

type annotation warning involving completely unrelated scopes #72616

matthiaskrgr opened this issue May 26, 2020 · 1 comment · Fixed by #78265
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

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)
@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label May 26, 2020
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 29, 2020
@lcnr
Copy link
Contributor

lcnr commented Oct 20, 2020

This should have been fixed by #78111, marking as E-needs-test.

@lcnr lcnr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 20, 2020
@bors bors closed this as completed in b5d2ff0 Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants