Skip to content

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

Closed
@A1-Triard

Description

@A1-Triard

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    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