File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change
1
+ // Tests that associated constants are checked whether they are used or not.
2
+ //
3
+ // revisions: used unused
4
+ // compile-flags: -Copt-level=2 --emit link
5
+
6
+ #![ cfg_attr( unused, allow( dead_code) ) ]
7
+ #![ deny( arithmetic_overflow) ]
8
+
9
+ pub trait Foo {
10
+ const N : i32 ;
11
+ }
12
+
13
+ struct S ;
14
+
15
+ impl Foo for S {
16
+ const N : i32 = 1 << 42 ;
17
+ //~^ ERROR this arithmetic operation will overflow
18
+ }
19
+
20
+ impl < T : Foo > Foo for Vec < T > {
21
+ const N : i32 = --T :: N + ( -i32:: MIN ) ; //~ ERROR this arithmetic operation will overflow
22
+ }
23
+
24
+ fn main ( ) {
25
+ #[ cfg( used) ]
26
+ let _ = S :: N ; //[used]~ ERROR erroneous constant used
27
+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ pub trait Foo {
15
15
}
16
16
17
17
impl < T : Foo > Foo for Vec < T > {
18
- const N : i32 = T :: N << 42 ; // FIXME this should warn
18
+ const N : i32 = T :: N << 42 ; // ERROR: arithmetic operation will overflow
19
19
}
20
20
21
21
pub fn foo ( x : i32 ) {
You can’t perform that action at this time.
0 commit comments