Skip to content

String::as_ref() Into<String> type inference regression #60958

Closed
@oherrala

Description

@oherrala

The following code has been working with stable compiler (rustc 1.34.2), but doesn't compile with nightly (rustc 1.36.0-nightly (963184b 2019-05-18)).

fn takes_string<S: Into<String>>(input: S) {
    let s = input.into();
    println!("{}", s);
}

fn main() {
    let foo = String::from("Hello world");
    takes_string(foo.as_ref());
}

code in playground

Error the nightly compiler is given:

error[E0283]: type annotations required: cannot resolve `std::string::String: std::convert::AsRef<_>`
  --> src/main.rs:10:22
   |
10 |     takes_string(foo.as_ref());
   |                      ^^^^^^

error: aborting due to previous error

However, stable compiler is happy with the code and prints the expected hello world.

Stable compiler:

rustc 1.34.2 (6c2484dc3 2019-05-13)
binary: rustc
commit-hash: 6c2484dc3c532c052f159264e970278d8b77cdc9
commit-date: 2019-05-13
host: x86_64-apple-darwin
release: 1.34.2
LLVM version: 8.0

Nightly compiler:

rustc 1.36.0-nightly (963184bbb 2019-05-18)
binary: rustc
commit-hash: 963184bbb670c1ffa97fc28a98cd5e8473118859
commit-date: 2019-05-18
host: x86_64-apple-darwin
release: 1.36.0-nightly
LLVM version: 8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions