summary refs log tree commit diff
path: root/src/test/ui/const-generics/issues/issue-68977.rs
blob: 02e634efec3e7198b4d2c1070c447f28f6cd358c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

struct PhantomU8<const X: u8>;

trait FxpStorage {
    type SInt; // Add arithmetic traits as needed.
}

macro_rules! fxp_storage_impls {
    ($($($n:literal)|+ => $sint:ty),* $(,)?) => {
        $($(impl FxpStorage for PhantomU8<$n> {
            type SInt = $sint;
        })*)*
    }
}

fxp_storage_impls! {
    1 => i8,
    2 => i16,
    3 | 4 => i32,
    5 | 6 | 7 | 8 => i64,
    9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 => i128,
}

type FxpStorageHelper<const INT_BITS: u8, const FRAC_BITS: u8> =
    PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
    //[min]~^ ERROR generic parameters must not be used inside of non trivial constant values
    //[min]~| ERROR generic parameters must not be used inside of non trivial constant values

struct Fxp<const INT_BITS: u8, const FRAC_BITS: u8>
where
    FxpStorageHelper<INT_BITS, FRAC_BITS>: FxpStorage,
    //[full]~^ ERROR constant expression depends on a generic parameter
{
    storage: <FxpStorageHelper<INT_BITS, FRAC_BITS> as FxpStorage>::SInt,
}

fn main() {
    Fxp::<1, 15> { storage: 0i16 };
    Fxp::<2, 15> { storage: 0i32 };
}