Skip to content

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

Closed

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

Activity

  1. npmccallum commented on Oct 1, 2021

    @npmccallum
    ContributorAuthor

    This also appears to impact the use of major Rust libraries such as clap:

    error[E0277]: the trait bound `std::string::String: From<&str>` is not satisfied
      --> src/main.rs:74:10
       |
    74 | #[derive(StructOpt)]
       |          ^^^^^^^^^ 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`
    note: required by a bound in `App::<'a, 'b>::new`
      --> /home/npmccallum/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/app/mod.rs:80:19
       |
    80 |     pub fn new<S: Into<String>>(n: S) -> Self {
       |                   ^^^^^^^^^^^^ required by this bound in `App::<'a, 'b>::new`
       = note: this error originates in the derive macro `StructOpt` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
       |
    75 | struct Info where std::string::String: From<&str> {}
       |             +++++++++++++++++++++++++++++++++++++
    
    error[E0277]: the trait bound `std::string::String: From<&str>` is not satisfied
      --> src/main.rs:78:10
       |
    78 | #[derive(StructOpt)]
       |          ^^^^^^^^^ 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`
    note: required by a bound in `App::<'a, 'b>::new`
      --> /home/npmccallum/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/app/mod.rs:80:19
       |
    80 |     pub fn new<S: Into<String>>(n: S) -> Self {
       |                   ^^^^^^^^^^^^ required by this bound in `App::<'a, 'b>::new`
       = note: this error originates in the derive macro `StructOpt` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
       |
    79 | struct Exec where std::string::String: From<&str> {
       |             +++++++++++++++++++++++++++++++++++++
    
    error[E0277]: the trait bound `std::string::String: From<&str>` is not satisfied
      --> src/main.rs:84:10
       |
    84 | #[derive(StructOpt)]
       |          ^^^^^^^^^ 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`
    note: required by a bound in `App::<'a, 'b>::new`
      --> /home/npmccallum/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/app/mod.rs:80:19
       |
    80 |     pub fn new<S: Into<String>>(n: S) -> Self {
       |                   ^^^^^^^^^^^^ required by this bound in `App::<'a, 'b>::new`
       = note: this error originates in the derive macro `StructOpt` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
       |
    86 | enum Options where std::string::String: From<&str> {
       |              +++++++++++++++++++++++++++++++++++++
    
    For more information about this error, try `rustc --explain E0277`.
    error: could not compile `enarx-keepldr` due to 12 previous errors
    
  2. ehuss commented on Oct 1, 2021

    @ehuss
    Contributor

    Thanks for the report! Unfortunately I am unable to reproduce with the given example. As written, it doesn't compile with the super:: path, but even with that removed, it seems to compile fine. Can you put together an example that fails to compile, perhaps linked to https://play.rust-lang.org/?

    @npmccallum Or maybe you can put something together? I tried running the testsuite for structopt itself without any problems.

  3. npmccallum commented on Oct 1, 2021

    @npmccallum
    ContributorAuthor

    @ehuss I tried to do the same and compilation succeeded. play.rust-lang.org doesn't have the affected nightly build. However, our open source code is failing to build. I'm not dismissing the possibility that rust may be catching some bad code on our part. But the compiler recommended fixes seem very odd...

  4. added a commit that references this issue on Oct 1, 2021
  5. ehuss commented on Oct 1, 2021

    @ehuss
    Contributor

    The playground appears to have the latest version to me:

    image

    I was able to bisect to #86853. cc @usbalbin

    I might try to reduce it later today, but if someone could make a minimal reproduction beforehand, that would be very helpful.

  6. npmccallum commented on Oct 1, 2021

    @npmccallum
    ContributorAuthor

    @ehuss @usbalbin I spent some time trying to come up with a minimal reproduction, but I failed. I don't know exactly what is triggering this new compiler failure.

  7. usbalbin commented on Oct 1, 2021

    @usbalbin
    Contributor

    @oli-obk or @fee1-dead , any thoughts?

  8. cuviper commented on Oct 1, 2021

    @cuviper
    Member

    Minimized:

    pub const fn foo() -> impl FnOnce() -> String {
        || "foo".into()
    }

    I guess it's forcing const trait evaluation within the closure that isn't really needed.

  9. cuviper commented on Oct 1, 2021

    @cuviper
    Member

    Well, mine can't be all of it, because not all of the errors are from const functions, and my reproducer doesn't even work if you change to || String::new() because impl Trait and fn pointers aren't allowed. But maybe this is still a useful breadcrumb.

  10. cuviper commented on Oct 1, 2021

    @cuviper
    Member

    Here's a better one, which does work on beta:

    const FOO: fn() -> String = || "foo".into();
    
    pub fn bar() -> fn() -> String {
        || "bar".into()
    }

    The presence of FOO creates errors in both, though bar() alone works fine.

    error[E0277]: the trait bound `String: From<&str>` is not satisfied
     --> src/lib.rs:1:38
      |
    1 | const FOO: fn() -> String = || "foo".into();
      |                                      ^^^^ the trait `From<&str>` is not implemented for `String`
      |
      = note: required because of the requirements on the impl of `Into<String>` for `&str`
    
    error[E0277]: the trait bound `String: From<&str>` is not satisfied
     --> src/lib.rs:4:14
      |
    4 |     || "bar".into()
      |              ^^^^ the trait `From<&str>` is not implemented for `String`
      |
      = note: required because of the requirements on the impl of `Into<String>` for `&str`
    help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
      |
    3 | pub fn bar() -> fn() -> String where String: From<&str> {
      |                                ++++++++++++++++++++++++
    
  11. Urgau commented on Oct 1, 2021

    @Urgau
    Member

    Here is a godbolt for the first minimized code that produce the same error describe in this issue but doesn't work on stable or beta.
    And here is the second godbolt for the second minimized code that's works on stable and beta but not on nightly.

    @rustbot label +regression-from-stable-to-nightly

  12. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 1, 2021
  13. oli-obk commented on Oct 1, 2021

    @oli-obk
    Contributor

    Short term we should revert #86853.

    Longer term I believe this is due to global caching of predicate evaluations. We'll need to think about how const traits play into that, since their successful evaluation depends on the context's constness, which is obviously not global

  14. 12 remaining items

  15. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 12, 2021
  16. fee1-dead commented on Dec 3, 2021

    @fee1-dead
    Member

    Here is another MCVE which is what seems to cause the error: playground

    #![feature(const_trait_impl)]
    #![feature(const_fn_trait_bounds)]
    
    trait Convert<T> {
        fn to(self) -> T;
    }
    
    impl<A, B> const Convert<B> for A where B: ~const From<A> {
        fn to(self) -> B {
            B::from(self)
        }
    }
    
    const FOO: fn() -> String = || "foo".to();
  17. added a commit that references this issue on Dec 17, 2021
    41c48bd
  18. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Dec 1, 2024
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

    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