Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(dead_code, unused_variables)]
- #![feature(const_generics)]
- // note: we are using an u8
- struct S<const N: u8>;
- // compiles and can be called S::<0>::foo();
- impl S<0> { fn foo() {} }
- // compiles and can be called S::<255>::foo();
- impl S<255> { fn foo() {} }
- // both of the above were expected to work ^^
- // now, uncomment the following
- // impl S<256> { fn foo() {} }
- // expected: overflowing literals error
- // error[E0592]: duplicate definitions with name `foo`
- // --> src/lib.rs:6:13
- // |
- // 6 | impl S<0> { fn foo() {} }
- // | ^^^^^^^^^^^ duplicate definitions for `foo`
- // 7 |
- // 8 | impl S<256> { fn foo() {} }
- // | ----------- other definition for `foo`
- // acts as if it overflowed to 0 and now conflicts
- // however, const X: u8 = 256; does warn about overflow.
- // uncomment the following
- //impl S<300000> { fn foo() {} }
- // expected: the error that is returned
- // error: literal out of range for `u8`
- // --> src/lib.rs:23:8
- // |
- // 23 | impl S<300000> { fn foo() {} }
- // | ^^^^^^
- // |
- // = note: #[deny(overflowing_literals)] on by default
- // if we add, #![allow(overflowing_literals)], it compiles.
- // noting if overflow is undesired at const generic level.
- // uncomment the following
- // impl S<300000000> { fn foo() {} }
- // or
- // impl S<299999999> { fn foo() {} }
- // etc
- // expected: overflowing literals
- // error[E0592]: duplicate definitions with name `foo`
- // --> src/lib.rs:6:13
- // |
- // 6 | impl S<0> { fn foo() {} }
- // | ^^^^^^^^^^^ duplicate definitions for `foo`
- // ...
- // 10 | impl S<300000000> { fn foo() {} }
- // | ----------- other definition for `foo`
- // 300000001 warns about overflow. the lint/error reports inconsistently.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement