Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ogoffart opened this issue Oct 28, 2022 · 3 comments · Fixed by #103683
Closed
Assignees
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ogoffart
Copy link
Contributor

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

@ogoffart ogoffart added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Oct 28, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 28, 2022
@Noratrieb
Copy link
Member

searched nightlies: from nightly-2022-08-01 to nightly-2022-10-24
regressed nightly: nightly-2022-09-23
searched commit range: 9062b78...e7119a0
regressed commit: 7a8636c

bisected with cargo-bisect-rustc v0.6.4

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc 2022-08-01 --regress error --access github

@Noratrieb
Copy link
Member

@fee1-dead @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Oct 28, 2022

Seems like closures pick the constness of their parent when they should always be notconst

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 28, 2022
@fee1-dead fee1-dead self-assigned this Oct 28, 2022
@fee1-dead fee1-dead changed the title Compilation error with nightly: `the trait ~const Deref is not implemented for String ` Compilation error with nightly: ``the trait ~const Deref is not implemented for String `` Oct 28, 2022
@fee1-dead fee1-dead changed the title Compilation error with nightly: ``the trait ~const Deref is not implemented for String `` Compilation error with nightly: the trait \~const Deref\ is not implemented for \String\ Oct 28, 2022
@fee1-dead fee1-dead changed the title Compilation error with nightly: the trait \~const Deref\ is not implemented for \String\ Compilation error with nightly: the trait ~const Deref is not implemented for String Oct 28, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 28, 2022
…checks-constness, r=oli-obk

Retain ParamEnv constness when running deferred cast checks

Fixes rust-lang#103677.
@bors bors closed this as completed in a990b4c Oct 28, 2022
@inquisitivecrystal inquisitivecrystal removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 31, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants