File tree 5 files changed +110
-18
lines changed
5 files changed +110
-18
lines changed Original file line number Diff line number Diff line change 1
1
error: this arithmetic operation will overflow
2
- --> $DIR/issue-69020.rs:15:20
2
+ --> $DIR/issue-69020.rs:21:22
3
3
|
4
- LL | const N : i32 = -i32::MIN + T::N ;
5
- | ^^^^^^^^^ attempt to negate with overflow
4
+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5
+ | ^^^^^^^^^ attempt to negate with overflow
6
6
|
7
7
= note: `#[deny(overflow)]` on by default
8
8
9
- error: aborting due to previous error
9
+ error: this arithmetic operation will overflow
10
+ --> $DIR/issue-69020.rs:23:22
11
+ |
12
+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13
+ | ^^^^^^^^^^^^ attempt to add with overflow
14
+
15
+ error: this operation will panic at runtime
16
+ --> $DIR/issue-69020.rs:25:22
17
+ |
18
+ LL | const DIV: i32 = (1/0) + T::DIV;
19
+ | ^^^^^ attempt to divide by zero
20
+ |
21
+ = note: `#[deny(panic)]` on by default
22
+
23
+ error: this operation will panic at runtime
24
+ --> $DIR/issue-69020.rs:27:22
25
+ |
26
+ LL | const OOB: i32 = [1][1] + T::OOB;
27
+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28
+
29
+ error: aborting due to 4 previous errors
10
30
Original file line number Diff line number Diff line change 1
1
error: this arithmetic operation will overflow
2
- --> $DIR/issue-69020.rs:15:20
2
+ --> $DIR/issue-69020.rs:21:22
3
3
|
4
- LL | const N : i32 = -i32::MIN + T::N ;
5
- | ^^^^^^^^^ attempt to negate with overflow
4
+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5
+ | ^^^^^^^^^ attempt to negate with overflow
6
6
|
7
7
= note: `#[deny(overflow)]` on by default
8
8
9
- error: aborting due to previous error
9
+ error: this arithmetic operation will overflow
10
+ --> $DIR/issue-69020.rs:23:22
11
+ |
12
+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13
+ | ^^^^^^^^^^^^ attempt to add with overflow
14
+
15
+ error: this operation will panic at runtime
16
+ --> $DIR/issue-69020.rs:25:22
17
+ |
18
+ LL | const DIV: i32 = (1/0) + T::DIV;
19
+ | ^^^^^ attempt to divide by zero
20
+ |
21
+ = note: `#[deny(panic)]` on by default
22
+
23
+ error: this operation will panic at runtime
24
+ --> $DIR/issue-69020.rs:27:22
25
+ |
26
+ LL | const OOB: i32 = [1][1] + T::OOB;
27
+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28
+
29
+ error: aborting due to 4 previous errors
10
30
Original file line number Diff line number Diff line change 1
1
error: this arithmetic operation will overflow
2
- --> $DIR/issue-69020.rs:15:20
2
+ --> $DIR/issue-69020.rs:21:22
3
3
|
4
- LL | const N : i32 = -i32::MIN + T::N ;
5
- | ^^^^^^^^^ attempt to negate with overflow
4
+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5
+ | ^^^^^^^^^ attempt to negate with overflow
6
6
|
7
7
= note: `#[deny(overflow)]` on by default
8
8
9
- error: aborting due to previous error
9
+ error: this arithmetic operation will overflow
10
+ --> $DIR/issue-69020.rs:23:22
11
+ |
12
+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13
+ | ^^^^^^^^^^^^ attempt to add with overflow
14
+
15
+ error: this operation will panic at runtime
16
+ --> $DIR/issue-69020.rs:25:22
17
+ |
18
+ LL | const DIV: i32 = (1/0) + T::DIV;
19
+ | ^^^^^ attempt to divide by zero
20
+ |
21
+ = note: `#[deny(panic)]` on by default
22
+
23
+ error: this operation will panic at runtime
24
+ --> $DIR/issue-69020.rs:27:22
25
+ |
26
+ LL | const OOB: i32 = [1][1] + T::OOB;
27
+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28
+
29
+ error: aborting due to 4 previous errors
10
30
Original file line number Diff line number Diff line change 1
1
error: this arithmetic operation will overflow
2
- --> $DIR/issue-69020.rs:15:20
2
+ --> $DIR/issue-69020.rs:21:22
3
3
|
4
- LL | const N : i32 = -i32::MIN + T::N ;
5
- | ^^^^^^^^^ attempt to negate with overflow
4
+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5
+ | ^^^^^^^^^ attempt to negate with overflow
6
6
|
7
7
= note: `#[deny(overflow)]` on by default
8
8
9
- error: aborting due to previous error
9
+ error: this arithmetic operation will overflow
10
+ --> $DIR/issue-69020.rs:23:22
11
+ |
12
+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13
+ | ^^^^^^^^^^^^ attempt to add with overflow
14
+
15
+ error: this operation will panic at runtime
16
+ --> $DIR/issue-69020.rs:25:22
17
+ |
18
+ LL | const DIV: i32 = (1/0) + T::DIV;
19
+ | ^^^^^ attempt to divide by zero
20
+ |
21
+ = note: `#[deny(panic)]` on by default
22
+
23
+ error: this operation will panic at runtime
24
+ --> $DIR/issue-69020.rs:27:22
25
+ |
26
+ LL | const OOB: i32 = [1][1] + T::OOB;
27
+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28
+
29
+ error: aborting due to 4 previous errors
10
30
Original file line number Diff line number Diff line change 8
8
use std:: i32;
9
9
10
10
pub trait Foo {
11
- const N : i32 ;
11
+ const NEG : i32 ;
12
+ const ADD : i32 ;
13
+ const DIV : i32 ;
14
+ const OOB : i32 ;
12
15
}
13
16
17
+ // These constants cannot be evaluated already (they depend on `T::N`), so
18
+ // they can just be linted like normal run-time code. But codegen works
19
+ // a bit different in const context, so this test makes sure that we still catch overflow.
14
20
impl < T : Foo > Foo for Vec < T > {
15
- const N : i32 = -i32:: MIN + T :: N ;
21
+ const NEG : i32 = -i32:: MIN + T :: NEG ;
16
22
//~^ ERROR arithmetic operation will overflow
23
+ const ADD : i32 = ( i32:: MAX +1 ) + T :: ADD ;
24
+ //~^ ERROR arithmetic operation will overflow
25
+ const DIV : i32 = ( 1 /0 ) + T :: DIV ;
26
+ //~^ ERROR operation will panic
27
+ const OOB : i32 = [ 1 ] [ 1 ] + T :: OOB ;
28
+ //~^ ERROR operation will panic
17
29
}
You can’t perform that action at this time.
0 commit comments