Skip to content

Compilation error with nightly: the trait ~const Deref is not implemented for String #103677

Closed
@ogoffart

Description

@ogoffart

Code

const _: fn(&String) = |s| { &*s as &str; };

Compiles in stable rust (1.64) as well as in beta.
But in nightly, we get this compilation error:

error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): the trait bound `String: Deref` is not satisfied
 --> src/lib.rs:4:30
  |
4 | const _: fn(&String) = |s| { &*s as &str; };
  |                              ^^^ the trait `~const Deref` is not implemented for `String`
  |
note: the trait `Deref` is implemented for `String`, but that implementation is not `const`
 --> src/lib.rs:4:30
  |
4 | const _: fn(&String) = |s| { &*s as &str; };
  |                              ^^^

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c4decfd8064f4074814df6e0d4e0859c

Version it worked on

1.64, and beta

Version with regression

current nightly

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions