Skip to content

Problem with type inference resolution #51223

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

Open
Lapz opened this issue May 30, 2018 · 2 comments
Open

Problem with type inference resolution #51223

Lapz opened this issue May 30, 2018 · 2 comments
Labels
A-inference Area: Type inference A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@Lapz
Copy link

Lapz commented May 30, 2018

A problem was found with the type inference resoultion when the env_logger crate was imported. The issue was reported on reddit and errors on the latest stable and nightly.

// Uncomment this and it breaks...
extern crate env_logger;

fn main() {
    let string = String::new();
    let str = <&str>::from(&string);

    println!("{:?}", str);
}
@cuviper
Copy link
Member

cuviper commented May 30, 2018

Normally, <&str>::from(&string) will auto-deref that &String to &str, so we're using the identity impl From<T> for T here. If env_logger or its dependencies add a new impl From<X> for &str, then the type resolution is ambiguous, and auto-deref isn't used.

I had a somewhat similar issue in #49062 using Sum, but not involving auto-deref.

@leoyvens leoyvens added A-trait-system Area: Trait system A-inference Area: Type inference labels Jun 1, 2018
@steveklabnik
Copy link
Member

Triage: here's the error message today:

error[E0277]: the trait bound `&str: std::convert::From<&std::string::String>` is not satisfied
 --> src/main.rs:6:15
  |
6 |     let str = <&str>::from(&string);
  |               ^^^^^^^^^^^^ the trait `std::convert::From<&std::string::String>` is not implemented for `&str`
  |
  = help: the following implementations were found:
            <&'t str as std::convert::From<regex::re_unicode::Match<'t>>>
  = note: required by `std::convert::From::from`

@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants