Skip to content

Type inference regression in Rust 1.28.0 #55129

Description

@ruuda

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions