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

Constant trait implementations are not considered as constant function sometimes. (const_trait_impl feature) #114677

Closed
A1-Triard opened this issue Aug 10, 2023 · 1 comment
Labels
C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@A1-Triard
Copy link

I tried this code:

#![feature(const_trait_impl)]

#[const_trait]
pub trait Aaa {
    fn x() -> u8;
}

struct Impl;

impl const Aaa for Impl {
    fn x() -> u8 { 0 }
}

pub const fn y() -> u8 { Impl::x() }

I expected to see this happen: it compiles without an error.

Instead, this happened:

error[E0015]: cannot call non-const fn `<Impl as Aaa>::x` in constant functions
  --> src/lib.rs:14:26
   |
14 | pub const fn y() -> u8 { Impl::x() }
   |                          ^^^^^^^^^
   |
   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

rustc --version --verbose:

rustc 1.73.0-nightly (f88a8b71c 2023-08-08)
binary: rustc
commit-hash: f88a8b71cebb730cbd5058c45ebcae1d4d9be377
commit-date: 2023-08-08
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 17.0.0
@A1-Triard A1-Triard added the C-bug Category: This is a bug. label Aug 10, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 10, 2023
@fmease
Copy link
Member

fmease commented Aug 10, 2023

const_trait_impl is currently being reworked, see #110395 and #114202. The feature is expected to be slightly broken at the moment. Note that your code will compile if you add #![feature(effects)] (which is work in progress).

@rustbot label -needs-triage T-compiler F-const_trait_impl

@rustbot rustbot added F-const_trait_impl `#![feature(const_trait_impl)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 10, 2023
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. F-const_trait_impl `#![feature(const_trait_impl)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants