]> git.lizzy.rs Git - rust.git/blob - src/test/ui/const-generics/issues/issue-68977.rs
Rustdoc render public underscore_imports as Re-exports
[rust.git] / src / test / ui / const-generics / issues / issue-68977.rs
1 // revisions: full min
2 #![cfg_attr(full, feature(const_generics))]
3 #![cfg_attr(full, allow(incomplete_features))]
4 #![cfg_attr(min, feature(min_const_generics))]
5
6 struct PhantomU8<const X: u8>;
7
8 trait FxpStorage {
9     type SInt; // Add arithmetic traits as needed.
10 }
11
12 macro_rules! fxp_storage_impls {
13     ($($($n:literal)|+ => $sint:ty),* $(,)?) => {
14         $($(impl FxpStorage for PhantomU8<$n> {
15             type SInt = $sint;
16         })*)*
17     }
18 }
19
20 fxp_storage_impls! {
21     1 => i8,
22     2 => i16,
23     3 | 4 => i32,
24     5 | 6 | 7 | 8 => i64,
25     9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 => i128,
26 }
27
28 type FxpStorageHelper<const INT_BITS: u8, const FRAC_BITS: u8> =
29     PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
30     //[min]~^ ERROR generic parameters may not be used in const operations
31     //[min]~| ERROR generic parameters may not be used in const operations
32
33 struct Fxp<const INT_BITS: u8, const FRAC_BITS: u8>
34 where
35     FxpStorageHelper<INT_BITS, FRAC_BITS>: FxpStorage,
36     //[full]~^ ERROR constant expression depends on a generic parameter
37 {
38     storage: <FxpStorageHelper<INT_BITS, FRAC_BITS> as FxpStorage>::SInt,
39 }
40
41 fn main() {
42     Fxp::<1, 15> { storage: 0i16 };
43     Fxp::<2, 15> { storage: 0i32 };
44 }