rust/tests/ui/const-generics/invalid-enum.rs

36 lines
970 B
Rust
Raw Normal View History

2021-10-23 10:57:49 -05:00
#![feature(adt_const_params)]
2020-08-21 22:32:07 -05:00
#![allow(incomplete_features)]
#[derive(PartialEq, Eq)]
enum CompileFlag {
2021-02-13 22:35:18 -06:00
A,
B,
2020-08-21 22:32:07 -05:00
}
pub fn test_1<const CF: CompileFlag>() {}
pub fn test_2<T, const CF: CompileFlag>(x: T) {}
pub struct Example<const CF: CompileFlag, T=u32>{
2021-02-13 22:35:18 -06:00
x: T,
}
impl<const CF: CompileFlag, T> Example<CF, T> {
const ASSOC_FLAG: CompileFlag = CompileFlag::A;
}
2020-08-21 22:32:07 -05:00
pub fn main() {
test_1::<CompileFlag::A>();
//~^ ERROR: expected type, found variant
2021-02-13 22:35:18 -06:00
//~| ERROR: unresolved item provided when a constant was expected
test_2::<_, CompileFlag::A>(0);
2020-08-21 22:32:07 -05:00
//~^ ERROR: expected type, found variant
2021-02-13 22:35:18 -06:00
//~| ERROR: unresolved item provided when a constant was expected
let _: Example<CompileFlag::A, _> = Example { x: 0 };
//~^ ERROR: expected type, found variant
2021-02-13 22:35:18 -06:00
//~| ERROR: unresolved item provided when a constant was expected
let _: Example<Example::ASSOC_FLAG, _> = Example { x: 0 };
//~^ ERROR: type provided when a constant was expected
2020-08-21 22:32:07 -05:00
}