We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6b41bde commit 734439cCopy full SHA for 734439c
tests/ui/codegen/shift-right-operand-mutation.rs
@@ -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
+
8
//@ run-pass
9
-#![allow(unused_must_use)]
-// Regression test for issue #152.
10
pub fn main() {
- let mut b: usize = 1_usize;
11
+ let mut b: usize = 1;
12
while b < std::mem::size_of::<usize>() {
- 0_usize << b;
- b <<= 1_usize;
- println!("{}", b);
13
+ // This shift operation should not mutate `b`
14
+ let _ = 0_usize << b;
15
+ b <<= 1;
16
}
17
+ assert_eq!(8, b);
18
0 commit comments