SHARE
TWEET

Untitled

a guest May 21st, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![allow(dead_code, unused_variables)]
  2. #![feature(const_generics)]
  3.  
  4. // overflow lints are inconsistent with lints that
  5. // are triggered in a normal const like const FOO: T = overflowing value;
  6.  
  7. // note: we are using an u8
  8. struct S<const N: u8>;
  9.  
  10. // compiles and can be called S::<0>::foo();
  11. impl S<0> { fn foo() {} }
  12. // compiles and can be called S::<255>::foo();
  13. impl S<255> { fn foo() {} }
  14. // both of the above were expected to work ^^
  15.  
  16.  
  17. // now, uncomment the following
  18. // impl S<256> { fn foo() {} }
  19.  
  20. // expected: overflowing literals error
  21.  
  22. // error[E0592]: duplicate definitions with name `foo`
  23. //  --> src/lib.rs:6:13
  24. //   |
  25. // 6 | impl S<0> { fn foo() {} }
  26. //   |             ^^^^^^^^^^^ duplicate definitions for `foo`
  27. // 7 |
  28. // 8 | impl S<256> { fn foo() {} }
  29. //   |               ----------- other definition for `foo`
  30.  
  31. // acts as if it overflowed to 0 and now conflicts
  32. // however, const X: u8 = 256; does warn about overflow.
  33.  
  34.  
  35.  
  36. // uncomment the following
  37. //impl S<300000> { fn foo() {} }
  38.  
  39. // expected: the error that is returned
  40.  
  41. // error: literal out of range for `u8`
  42. //   --> src/lib.rs:23:8
  43. //   |
  44. // 23 | impl S<300000> { fn foo() {} }
  45. //   |        ^^^^^^
  46. //   |
  47. //   = note: #[deny(overflowing_literals)] on by default
  48.  
  49. // if we add, #![allow(overflowing_literals)], it compiles.
  50. // noting if overflow is undesired at const generic level.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top