Skip to content

Instantly share code, notes, and snippets.

@folkertdev
Created August 2, 2024 08:36
Show Gist options
  • Save folkertdev/ac3e3b00fae68412419e4b728825b9bc to your computer and use it in GitHub Desktop.
Save folkertdev/ac3e3b00fae68412419e4b728825b9bc to your computer and use it in GitHub Desktop.
two files where one has inconsistent ordering of the generated error messages
//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv
#![feature(asm_const)]
use std::arch::{asm, global_asm};
// Const operands must be integers and must be constants.
global_asm!("{}", const 0);
global_asm!("{}", const 0i32);
global_asm!("{}", const 0i128);
global_asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
global_asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand
fn main() {
unsafe {
// Const operands must be integers and must be constants.
asm!("{}", const 0);
asm!("{}", const 0i32);
asm!("{}", const 0i128);
asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand
asm!("{}", const &0);
//~^ ERROR invalid type for `const` operand
// Constants must be... constant
let x = 0;
const fn const_foo(x: i32) -> i32 {
x
}
const fn const_bar<T>(x: T) -> T {
x
}
asm!("{}", const x);
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{}", const const_foo(0));
asm!("{}", const const_foo(x));
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{}", const const_bar(0));
asm!("{}", const const_bar(x));
//~^ ERROR attempt to use a non-constant value in a constant
}
}
//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv
#![feature(asm_const)]
use std::arch::{asm, global_asm};
fn main() {
unsafe {
// Const operands must be integers and must be constants.
asm!("{}", const 0);
asm!("{}", const 0i32);
asm!("{}", const 0i128);
asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand
asm!("{}", const &0);
//~^ ERROR invalid type for `const` operand
}
}
// Const operands must be integers and must be constants.
global_asm!("{}", const 0);
global_asm!("{}", const 0i32);
global_asm!("{}", const 0i128);
global_asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
global_asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment