about summary refs log tree commit diff
path: root/tests/ui/consts/const-eval/issue-50814.rs
blob: 011f065ad814b32a4edb05ac051cae8adab3afb0 (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
//@ build-fail
//@ dont-require-annotations: NOTE

trait Unsigned {
    const MAX: u8;
}

struct U8(u8);
impl Unsigned for U8 {
    const MAX: u8 = 0xff;
}

struct Sum<A, B>(A, B);

impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A, B> {
    const MAX: u8 = A::MAX + B::MAX;
    //~^ ERROR attempt to compute `u8::MAX + u8::MAX`, which would overflow
    //~| ERROR attempt to compute `u8::MAX + u8::MAX`, which would overflow
}

fn foo<T>(_: T) -> &'static u8 {
    &Sum::<U8, U8>::MAX
    //~^ NOTE constant
}

fn main() {
    foo(0);
}