forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#96800 - nbdd0121:const, r=nagisa
Permit `asm_const` and `asm_sym` to reference generic params Related rust-lang#96557 These constructs will be allowed: ```rust 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)>); } ``` `@Amanieu,` I didn't switch inline asms to use `DefKind::InlineAsm`, as I see little value doing that; given that no type inference is needed, it will only make typecking slower and more complex but will have no real gains. I did switch them to follow the same code path as inline asm during symbol resolution, though. The `error: unconstrained generic constant` you mentioned in rust-lang#76001 is due to the fact that `to_const` will actually add a wfness obligation to the constant, which we don't need for `asm_const`, so I have that removed. `@rustbot` label: +A-inline-assembly +F-asm
- Loading branch information
Showing
12 changed files
with
116 additions
and
58 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,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>(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
error[E0658]: const operands for inline assembly are unstable | ||
--> $DIR/feature-gate-asm_const.rs:7:29 | ||
--> $DIR/feature-gate-asm_const.rs:6:25 | ||
| | ||
LL | asm!("mov eax, {}", const N + 1); | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information | ||
= help: add `#![feature(asm_const)]` to the crate attributes to enable | ||
|
||
error[E0658]: const operands for inline assembly are unstable | ||
--> $DIR/feature-gate-asm_const.rs:13:29 | ||
| | ||
LL | asm!("mov eax, {}", const 123); | ||
| ^^^^^^^^^ | ||
| | ||
= note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information | ||
= help: add `#![feature(asm_const)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
error[E0658]: sym operands for inline assembly are unstable | ||
--> $DIR/feature-gate-asm_sym.rs:7:29 | ||
--> $DIR/feature-gate-asm_sym.rs:9:29 | ||
| | ||
LL | asm!("mov eax, {}", sym main); | ||
| ^^^^^^^^ | ||
LL | asm!("mov eax, {}", sym bar::<N>); | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: see issue #93333 <https://github.com/rust-lang/rust/issues/93333> for more information | ||
= help: add `#![feature(asm_sym)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
error[E0658]: sym operands for inline assembly are unstable | ||
--> $DIR/feature-gate-asm_sym.rs:16:29 | ||
| | ||
LL | asm!("mov eax, {}", sym foo::<0>); | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: see issue #93333 <https://github.com/rust-lang/rust/issues/93333> for more information | ||
= help: add `#![feature(asm_sym)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |