`global_asm!` in statement position has weird behavior with `Self`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
use std::marker::PhantomData;
use std::arch::global_asm;
struct S<T>(PhantomData<T>);
impl<T> S<T> {
fn meow(&self) {
global_asm!("/* {} */", sym Self::meow);
}
}
This code should be forbidden because it uses a generic in global_asm!, which isn't meaningful.
Instead, the compiler became confused and was reporting errors about Sized.
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> src/lib.rs:8:37
|
6 | impl<T> S<T> {
| - this type parameter needs to be `Sized`
7 | fn meow(&self) {
8 | global_asm!("/* {} */", sym Self::meow);
| ^^^^ doesn't have a size known at compile-time
|
note: required by an implicit `Sized` bound in `S`
--> src/lib.rs:4:10
|
4 | struct S<T>(PhantomData<T>);
| ^ required by the implicit `Sized` requirement on this type parameter in `S`
help: consider relaxing the implicit `Sized` restriction
|
4 | struct S<T: ?Sized>(PhantomData<T>);
| ++++++++
error[E0599]: the associated function or constant `meow` exists for struct `S<T>`, but its trait bounds were not satisfied
--> src/lib.rs:8:43
|
4 | struct S<T>(PhantomData<T>);
| ----------- associated function or constant `meow` not found for this struct
...
8 | global_asm!("/* {} */", sym Self::meow);
| ^^^^ associated function or constant cannot be called on `S<T>` due to unsatisfied trait bounds
|
note: trait bound `T: Sized` was not satisfied
--> src/lib.rs:6:6
|
6 | impl<T> S<T> {
| ^ ----
| |
| unsatisfied trait bound introduced here
help: consider relaxing the type parameter's implicit `Sized` bound
|
6 | impl<T: ?Sized> S<T> {
| ++++++++
Meta
rustc --version --verbose:
rustc 1.98.0-nightly (23a3312d9 2026-05-23)
binary: rustc
commit-hash: 23a3312d92a1c4ba0373f1e25277be20ba8bb28c
commit-date: 2026-05-23
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6
Caused by #156582 allowing this position
Potentially related to #156760, a variant that uses turbofish syntax instead
cc #156855 and #156884
@rustbot label +A-global-asm +T-compiler
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided generic global_asm! example with the nightly compiler version shown. Read the changes from #156582 and compare the related cases in #156760, #156855, and #156884. Done means this statement-position use is rejected specifically because generic arguments are not meaningful, rather than producing misleading Sized and trait-bound errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100