forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#125558 - Amanieu:const-asm-type, r=lcnr
Tweak type inference for `const` operands in inline asm Previously these would be treated like integer literals and default to `i32` if a type could not be determined. To allow for forward-compatibility with `str` constants in the future, this PR changes type inference to use an unbound type variable instead. The actual type checking is deferred until after typeck where we still ensure that the final type for the `const` operand is an integer type. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
- Loading branch information
Showing
13 changed files
with
295 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//@ 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 | ||
} | ||
} |
Oops, something went wrong.