Skip to content

Commit a105875

Browse files
committed
Set up test cases which demonstrate the issue.
1 parent 7762131 commit a105875

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

src/test/ui/lint/lint-exceeding-bitshifts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait Foo {
1515
}
1616

1717
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
1919
}
2020

2121
pub fn foo(x: i32) {

0 commit comments

Comments
 (0)