2022-10-18 09:31:56 -05:00
|
|
|
// compile-flags: -Zdeduplicate-diagnostics=yes
|
2020-10-22 03:32:41 -05:00
|
|
|
use std::mem::size_of;
|
|
|
|
|
2020-07-28 08:55:42 -05:00
|
|
|
fn test<const N: usize>() {}
|
|
|
|
|
|
|
|
fn ok<const M: usize>() -> [u8; M] {
|
|
|
|
[0; { M }]
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Break0<const N: usize>([u8; { N + 1 }]);
|
2020-10-12 16:27:59 -05:00
|
|
|
//~^ ERROR generic parameters may not be used in const operations
|
2020-07-28 08:55:42 -05:00
|
|
|
|
|
|
|
struct Break1<const N: usize>([u8; { { N } }]);
|
2020-10-12 16:27:59 -05:00
|
|
|
//~^ ERROR generic parameters may not be used in const operations
|
2020-07-28 08:55:42 -05:00
|
|
|
|
|
|
|
fn break2<const N: usize>() {
|
|
|
|
let _: [u8; N + 1];
|
2020-10-12 16:27:59 -05:00
|
|
|
//~^ ERROR generic parameters may not be used in const operations
|
2020-07-28 08:55:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn break3<const N: usize>() {
|
|
|
|
let _ = [0; N + 1];
|
2020-10-12 16:27:59 -05:00
|
|
|
//~^ ERROR generic parameters may not be used in const operations
|
2020-07-28 08:55:42 -05:00
|
|
|
}
|
|
|
|
|
2020-10-22 03:32:41 -05:00
|
|
|
struct BreakTy0<T>(T, [u8; { size_of::<*mut T>() }]);
|
|
|
|
//~^ ERROR generic parameters may not be used in const operations
|
|
|
|
|
|
|
|
struct BreakTy1<T>(T, [u8; { { size_of::<*mut T>() } }]);
|
|
|
|
//~^ ERROR generic parameters may not be used in const operations
|
|
|
|
|
|
|
|
fn break_ty2<T>() {
|
|
|
|
let _: [u8; size_of::<*mut T>() + 1];
|
|
|
|
//~^ ERROR generic parameters may not be used in const operations
|
|
|
|
}
|
|
|
|
|
|
|
|
fn break_ty3<T>() {
|
|
|
|
let _ = [0; size_of::<*mut T>() + 1];
|
|
|
|
//~^ WARN cannot use constants which depend on generic parameters in types
|
|
|
|
//~| WARN this was previously accepted by the compiler but is being phased out
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-28 08:55:42 -05:00
|
|
|
trait Foo {
|
|
|
|
const ASSOC: usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|