2019-12-13 21:28:32 -06:00
|
|
|
// build-fail
|
|
|
|
|
2018-06-02 19:04:20 -05:00
|
|
|
trait C {
|
|
|
|
const BOO: usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Foo<T> {
|
|
|
|
const BAR: usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A<T>(T);
|
|
|
|
|
|
|
|
impl<T: C> Foo<T> for A<T> {
|
2022-09-21 06:05:20 -05:00
|
|
|
const BAR: usize = [5, 6, 7][T::BOO]; //~ ERROR evaluation of `<A<()> as Foo<()>>::BAR` failed
|
2018-06-02 19:04:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo<T: C>() -> &'static usize {
|
2022-11-15 05:06:20 -06:00
|
|
|
&<A<T> as Foo<T>>::BAR //~ constant
|
2018-06-02 19:04:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl C for () {
|
|
|
|
const BOO: usize = 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl C for u32 {
|
|
|
|
const BOO: usize = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("{:x}", foo::<()>() as *const usize as usize);
|
|
|
|
println!("{:x}", foo::<u32>() as *const usize as usize);
|
|
|
|
println!("{:x}", foo::<()>());
|
|
|
|
println!("{:x}", foo::<u32>());
|
2018-06-02 20:39:26 -05:00
|
|
|
}
|