Skip to content

nightly-2021-10-01: the trait From<&str> is not implemented for std::string::String #89432

Closed
@npmccallum

Description

@npmccallum

I tried this code:

pub struct Datum {
    /// The name of this datum.
    pub name: String,

    /// Whether the datum indicates support for the platform or not.
    pub pass: bool,

    /// Short additional information to display to the user.
    pub info: Option<String>,

    /// Longer explanatory message on how to resolve problems.
    pub mesg: Option<String>,
}
fn dev_kvm() -> super::Datum {
    let dev_kvm = std::path::Path::new("/dev/kvm");

    super::Datum {
        name: "Driver".into(),
        pass: dev_kvm.exists(),
        info: Some("/dev/kvm".into()),
        mesg: None,
    }
}

I expected to see this happen:

Successful compilation. This has compiled and worked for years until nightly-2021-10-01. Reverting to nightly-2021-09-30 produces a successful compilation.

Instead, this happened:

error[E0277]: the trait bound `std::string::String: From<&str>` is not satisfied
  --> src/backend/kvm/mod.rs:23:24
   |
23 |         name: "Driver".into(),
   |                        ^^^^ the trait `From<&str>` is not implemented for `std::string::String`
   |
   = note: required because of the requirements on the impl of `Into<std::string::String>` for `&str`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
   |
19 | fn dev_kvm() -> super::Datum where std::string::String: From<&str> {
   |                              +++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `std::string::String: From<&str>` is not satisfied
  --> src/backend/kvm/mod.rs:25:20
   |
25 |         info: Some("/dev/kvm".into()),
   |               ---- ^^^^^^^^^^^^^^^^^ the trait `From<&str>` is not implemented for `std::string::String`
   |               |
   |               required by a bound introduced by this call
   |
   = note: required because of the requirements on the impl of `Into<std::string::String>` for `&str`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
   |
19 | fn dev_kvm() -> super::Datum where std::string::String: From<&str> {
   |                              +++++++++++++++++++++++++++++++++++++

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (aa7aca3b9 2021-09-30)
binary: rustc
commit-hash: aa7aca3b954131720df725e70d12e902eb3be1de
commit-date: 2021-09-30
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

cc @haraldh @wgwoods

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions