Skip to content

cannot resolve std::borrow::Cow<'_, str>: std::borrow::Borrow<_> #50954

Closed
@jebrosen

Description

@jebrosen

This code fails to compile on nightly 2018-05-20 (playground):

use std::borrow::{Borrow, Cow};

fn takes_into_cow<'a, T: Into<Cow<'a, str>>>(x: T) {
    let s = x.into();
    println!("{}", s);
}

fn forward_cow<'a>(x: Cow<'a, str>) {
    takes_into_cow(x.borrow())
}

fn main() {
    forward_cow("test".into());
}

With this error:

error[E0283]: type annotations required: cannot resolve `std::borrow::Cow<'_, str>: std::borrow::Borrow<_>`
 --> src/main.rs:9:22
  |
9 |     takes_into_cow(x.borrow())
  |                      ^^^^^^

This compiles fine on stable and beta, and probably on nightly as well until some time in the last week or so.

This is a simplified version of the code involved in rwf2/Rocket#643.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions