Permit asm_const and asm_sym to reference outer generic params
This commit is contained in:
parent
d93b03793d
commit
b1c6c0648e
6 changed files with 60 additions and 47 deletions
30
src/test/ui/asm/generic-const.rs
Normal file
30
src/test/ui/asm/generic-const.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// needs-asm-support
|
||||
// build-pass
|
||||
|
||||
#![feature(asm_const, asm_sym)]
|
||||
|
||||
use std::arch::asm;
|
||||
|
||||
fn foofoo<const N: usize>() {}
|
||||
|
||||
unsafe fn foo<const N: usize>() {
|
||||
asm!("/* {0} */", const N);
|
||||
asm!("/* {0} */", const N + 1);
|
||||
asm!("/* {0} */", sym foofoo::<N>);
|
||||
}
|
||||
|
||||
fn barbar<T>() {}
|
||||
|
||||
unsafe fn bar<T>() {
|
||||
asm!("/* {0} */", const std::mem::size_of::<T>());
|
||||
asm!("/* {0} */", const std::mem::size_of::<(T, T)>());
|
||||
asm!("/* {0} */", sym barbar::<T>);
|
||||
asm!("/* {0} */", sym barbar::<(T, T)>);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
foo::<0>();
|
||||
bar::<usize>();
|
||||
}
|
||||
}
|
||||
|
|
@ -63,7 +63,6 @@ fn main() {
|
|||
|
||||
unsafe fn generic<T>() {
|
||||
asm!("{}", sym generic::<T>);
|
||||
//~^ generic parameters may not be used in const operations
|
||||
}
|
||||
|
||||
// Const operands must be integers and must be constants.
|
||||
|
|
|
|||
|
|
@ -33,15 +33,6 @@ LL | asm!("{}", sym x);
|
|||
|
|
||||
= help: `sym` operands must refer to either a function or a static
|
||||
|
||||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/type-check-1.rs:65:30
|
||||
|
|
||||
LL | asm!("{}", sym generic::<T>);
|
||||
| ^ cannot perform const operation using `T`
|
||||
|
|
||||
= note: type parameters may not be used in const expressions
|
||||
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type-check-1.rs:55:26
|
||||
|
|
||||
|
|
@ -109,13 +100,13 @@ LL | asm!("{}", inout(reg) v[..]);
|
|||
= note: all inline asm arguments must have a statically known size
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type-check-1.rs:74:25
|
||||
--> $DIR/type-check-1.rs:73:25
|
||||
|
|
||||
LL | global_asm!("{}", const 0f32);
|
||||
| ^^^^ expected integer, found `f32`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type-check-1.rs:76:25
|
||||
--> $DIR/type-check-1.rs:75:25
|
||||
|
|
||||
LL | global_asm!("{}", const 0 as *mut u8);
|
||||
| ^^^^^^^^^^^^ expected integer, found *-ptr
|
||||
|
|
@ -123,7 +114,7 @@ LL | global_asm!("{}", const 0 as *mut u8);
|
|||
= note: expected type `{integer}`
|
||||
found raw pointer `*mut u8`
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0308, E0435.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue