Skip to content

Commit 734439c

Browse files
committed
over-constrained-vregs
1 parent 6b41bde commit 734439c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
//! Ensure shift operations don't mutate their right operand.
2+
//!
3+
//! This test checks that expressions like `0 << b` don't accidentally
4+
//! modify the variable `b` due to codegen issues with virtual registers.
5+
//!
6+
//! Regression test for <https://github.com/rust-lang/rust/issues/152>.
7+
18
//@ run-pass
29

3-
#![allow(unused_must_use)]
4-
// Regression test for issue #152.
510
pub fn main() {
6-
let mut b: usize = 1_usize;
11+
let mut b: usize = 1;
712
while b < std::mem::size_of::<usize>() {
8-
0_usize << b;
9-
b <<= 1_usize;
10-
println!("{}", b);
13+
// This shift operation should not mutate `b`
14+
let _ = 0_usize << b;
15+
b <<= 1;
1116
}
17+
assert_eq!(8, b);
1218
}

0 commit comments

Comments
 (0)