Skip to content

const_trait_impls cannot be utilized with a trait_alias #106405

Open
@AZMCode

Description

@AZMCode

const_trait_impl cannot utilize const traits when satisfying const bounds using a trait alias trait_alias

#![feature(trait_alias)]
#![feature(const_trait_impl)]

#[const_trait]
trait Default {
    fn default() -> Self;
}

#[const_trait]
trait TraitAlias = ~const Default + Sized;

#[const_trait]
trait OwnTrait: ~const Default + Sized {
    const INTERESTING_CONSTANT: Self;
}

impl<T: ~const TraitAlias + Sized> const OwnTrait for T {
    const INTERESTING_CONSTANT: Self = T::default();
}

Link to Playground

There is not way to specify const-ness using trait bounds. The compile error does specify adding a #[const_trait] attribute, but this is not possible for trait aliases;

rustc --version --verbose:

rustc 1.68.0-nightly (d6f99e535 2023-01-02)
binary: rustc
commit-hash: d6f99e535a301a421dfee52a7c25bb4bdf420344
commit-date: 2023-01-02
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]`fixed-by-effectsThe effect system based scheme for const fns resolves this.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions