Skip to main content

## ASM_SUB_REGISTER

# Static ASM_SUB_REGISTER

Source

    pub static ASM_SUB_REGISTER: &'static Lint

Expand description

The `asm_sub_register` lint detects using only a subset of a register for inline asm inputs.

#### §Example

ⓘ

    #[cfg(target_arch="x86_64")]
    use std::arch::asm;

    fn main() {
        #[cfg(target_arch="x86_64")]
        unsafe {
            asm!("mov {0}, {0}", in(reg) 0i16);
        }
    }

This will produce:

    warning: formatting may not be suitable for sub-register argument
     --> src/main.rs:7:19
      |
    7 |         asm!("mov {0}, {0}", in(reg) 0i16);
      |                   ^^^  ^^^           ---- for this argument
      |
      = note: `#[warn(asm_sub_register)]` on by default
      = help: use the `x` modifier to have the register formatted as `ax`
      = help: or use the `r` modifier to keep the default formatting of `rax`

#### §Explanation

Registers on some architectures can use different names to refer to a subset of the register. By default, the compiler will use the name for the full register size. To explicitly use a subset of the register, you can override the default by using a modifier on the template string operand to specify when subregister to use. This lint is issued if you pass in a value with a smaller data type than the default register size, to alert you of possibly using the incorrect width. To fix this, add the suggested modifier to the template, or cast the value to the correct size.

See register template modifiers in the reference for more details.