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 inference regression in Rust 1.28.0 #55129

Closed
ruuda opened this issue Oct 16, 2018 · 2 comments
Closed

Type inference regression in Rust 1.28.0 #55129

ruuda opened this issue Oct 16, 2018 · 2 comments

Comments

@ruuda
Copy link
Contributor

ruuda commented Oct 16, 2018

The following file compiles on Rust 1.27.0:

use std::borrow::Cow;

struct Widget<'a> {
    handle: &'a u32,
}

impl<'a> Widget<'a> {
    pub fn new<S>(host: S) -> Result<Widget<'a>, String> where S: Into<Cow<'a, str>> {
        unimplemented!();
    }
}

pub fn main() {
    let host: String = "localhost".to_string();
    Widget::new(host.as_ref()).unwrap();
}

On 1.28.0, it fails with the following message:

error[E0283]: type annotations required: cannot resolve `std::string::String: std::convert::AsRef<_>`
  --> example.rs:15:22
   |
15 |     Widget::new(host.as_ref()).unwrap();
   |                      ^^^^^^

error: aborting due to previous error

I found #48668 which looks related, but it happened around 1.25.0.

The regression is still present in Rust 1.29.2.

ruuda added a commit to ruuda/musium that referenced this issue Oct 16, 2018
It looks like this is a regression in type inference in Rust 1.28; on
1.27 this code compiled fine. 1.28 complains about an ambiguity.
Using string slicing rather than as_ref resolved the issue.

I filed a bug at rust-lang/rust#55129.
@jonas-schievink
Copy link
Contributor

Caused by #50170 - also see this list of other regressions caused by it: #51844

@pietroalbini
Copy link
Member

Closing as a duplicate of #51844.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants