|
| 1 | +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// ignore-s390x |
| 12 | +// ignore-emscripten |
| 13 | +// ignore-powerpc |
| 14 | +// ignore-sparc |
| 15 | + |
| 16 | +// revisions: ast mir |
| 17 | +//[mir]compile-flags: -Z borrowck=mir -Z nll |
| 18 | + |
| 19 | +#![feature(asm)] |
| 20 | + |
| 21 | +#[cfg(any(target_arch = "x86", |
| 22 | + target_arch = "x86_64", |
| 23 | + target_arch = "arm", |
| 24 | + target_arch = "aarch64"))] |
| 25 | +mod test_cases { |
| 26 | + fn is_move() { |
| 27 | + let y: &mut isize; |
| 28 | + let x = &mut 0isize; |
| 29 | + unsafe { |
| 30 | + asm!("nop" : : "r"(x)); |
| 31 | + } |
| 32 | + let z = x; //[ast]~ ERROR use of moved value: `x` |
| 33 | + //[mir]~^ ERROR use of moved value: `x` |
| 34 | + } |
| 35 | + |
| 36 | + fn in_is_read() { |
| 37 | + let mut x = 3; |
| 38 | + let y = &mut x; |
| 39 | + unsafe { |
| 40 | + asm!("nop" : : "r"(x)); //[ast]~ ERROR cannot use |
| 41 | + //[mir]~^ ERROR cannot use |
| 42 | + } |
| 43 | + let z = y; |
| 44 | + } |
| 45 | + |
| 46 | + fn out_is_assign() { |
| 47 | + let x = 3; |
| 48 | + unsafe { |
| 49 | + asm!("nop" : "=r"(x)); //[ast]~ ERROR cannot assign twice |
| 50 | + //[mir]~^ ERROR cannot assign twice |
| 51 | + } |
| 52 | + let mut a = &mut 3; |
| 53 | + let b = &*a; |
| 54 | + unsafe { |
| 55 | + asm!("nop" : "=r"(a)); //[ast]~ ERROR cannot assign to `a` because it is borrowed |
| 56 | + // No MIR error, this is a shallow write. |
| 57 | + } |
| 58 | + let c = b; |
| 59 | + let d = *a; |
| 60 | + } |
| 61 | + |
| 62 | + fn rw_is_assign() { |
| 63 | + let x = 3; |
| 64 | + unsafe { |
| 65 | + asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign twice |
| 66 | + //[mir]~^ ERROR cannot assign twice |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + fn indirect_is_not_init() { |
| 71 | + let x: i32; |
| 72 | + unsafe { |
| 73 | + asm!("nop" : "=*r"(x)); //[ast]~ ERROR use of possibly uninitialized variable |
| 74 | + //[mir]~^ ERROR use of possibly uninitialized variable |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + fn rw_is_read() { |
| 79 | + let mut x = &mut 3; |
| 80 | + let y = &*x; |
| 81 | + unsafe { |
| 82 | + asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign to `x` because it is borrowed |
| 83 | + //[mir]~^ ERROR cannot assign to `x` because it is borrowed |
| 84 | + } |
| 85 | + let z = y; |
| 86 | + } |
| 87 | + |
| 88 | + fn two_moves() { |
| 89 | + let x = &mut 2; |
| 90 | + unsafe { |
| 91 | + asm!("nop" : : "r"(x), "r"(x) ); //[ast]~ ERROR use of moved value |
| 92 | + //[mir]~^ ERROR use of moved value |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +fn main() {} |
0 commit comments