-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
I tried this code (playground]:
#![feature(const_trait_impl, const_fn_trait_bound)]
pub trait ConstableTrait {
fn foo(&self) -> u32;
}
pub trait ExTrait {
type Assoc: ~const ConstableTrait;
}
struct ShouldBeInferred<T: ExTrait> {
a: T::Assoc
}
impl<T: ExTrait> ShouldBeInferred<T> {
pub const fn should_infer(&self) -> u32 {
self.a.foo()
}
}
I expected to see this happen:
ShouldBeInferred::should_infer
should understand that T::AssocTrait: ~const ConstableTrait
and self.a.foo()
is a const-fn.
Instead, this happened:
The compiler doesn't seem to infer the T::AssocTrait: ~const ConstableTrait
bound gives an error self.a.foo()
is not callable in a constant context.
I might be misunderstanding the purpose of ~const
bounds on associated types. Please correct me if I am :)
Also great work so far on const fn
. It's really starting to shine :)
Meta
rustc --version --verbose
:
rustc 1.56.0-nightly (b7404c898 2021-09-03)
binary: rustc
commit-hash: b7404c898a1a6933b71c72428a6dce551bcc1be7
commit-date: 2021-09-03
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.