Foo<T>: Trait
bounds (T
is a type param) are allowed in const fn
s · Issue #83452 · rust-lang/rust (original) (raw)
I tried this code:
pub trait Const { const C: u8; }
impl Const for u8 { const C: u8 = 3; } pub struct Wrapper(T); impl<T: Const> Const for Wrapper { const C: u8 = T::C; }
const fn foo() -> u8 where Wrapper: Const, { <Wrapper>::C }
fn main(){ const D: u8 = foo::(); dbg!(D); }
I expected to see this code not compile, because it bounds types by non-auto traits in const fn
s.
Instead, this happened: The code compiles without errors, and prints 3
This does error with T: Const
bounds as expected.
Meta
rustc --version --verbose
:
rustc 1.53.0-nightly (673d0db5e 2021-03-23)
binary: rustc
commit-hash: 673d0db5e393e9c64897005b470bfeb6d5aec61b
commit-date: 2021-03-23
host: i686-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0