Repository navigation
nightly-2021-10-01: the trait From<&str> is not implemented for std::string::String #89432
Copy link
Copy link
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
npmccallum commentedon Oct 1, 2021
This also appears to impact the use of major Rust libraries such as
clap:ehuss commentedon Oct 1, 2021
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.
npmccallum commentedon Oct 1, 2021
@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...
Pin to nightly-2021-09-30
ehuss commentedon Oct 1, 2021
The playground appears to have the latest version to me:
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.
npmccallum commentedon Oct 1, 2021
@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.
usbalbin commentedon Oct 1, 2021
@oli-obk or @fee1-dead , any thoughts?
cuviper commentedon Oct 1, 2021
Minimized:
I guess it's forcing
consttrait evaluation within the closure that isn't really needed.cuviper commentedon Oct 1, 2021
Well, mine can't be all of it, because not all of the errors are from
constfunctions, and my reproducer doesn't even work if you change to|| String::new()becauseimpl Traitandfnpointers aren't allowed. But maybe this is still a useful breadcrumb.cuviper commentedon Oct 1, 2021
Here's a better one, which does work on beta:
The presence of
FOOcreates errors in both, thoughbar()alone works fine.Urgau commentedon Oct 1, 2021
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
oli-obk commentedon Oct 1, 2021
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
12 remaining items
rust-toolchain: pin to nightly-2021-09-30
rust-toolchain: pin to nightly-2021-09-30
fee1-dead commentedon Dec 3, 2021
Here is another MCVE which is what seems to cause the error: playground
Auto merge of rust-lang#91549 - fee1-dead:const_env, r=spastorino