Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
tracking issue: #140364
closes #140364
Request for Stabilization
Summary
The
cfg_asm
feature allows#[cfg(...)]
and#[cfg_attr(...)]
on the arguments of the assembly macros, for instance:Semantics
Templates, operands,
options
andclobber_abi
in the assembly macros (asm!
,naked_asm!
andglobal_asm!
) can be annotated with#[cfg(...)]
and#[cfg_attr(...)]
. When the condition evaluates to true, the annotated argument has no effect, and is completely ignored when expanding the assembly macro.Documentation
reference PR: forthcoming (though maybe none is needed?)
Tests
cfg
'd arguments where the condition evaluates to false have no effectHistory
#[cfg(...)]
withinasm!
#140279asm_cfg
:#[cfg(...)]
withinasm!
#140367Resolved questions
how are other attributes handled
Other attributes are parsed, but explicitly rejected.
unresolved questions
operand before template
The current implementation expects at least one template string before any operands. In the example below, if the
cfg
condition evaluates to true, the assembly block is ill-formed. But even when it evaluates tofalse
this block is rejected, because the parser still expects just a template (a template is parsed as an expression and then validated to ensure that it is or expands to a string literal).Changing how this works is difficult.
lint on positional arguments?
Adding a lint to warn on the definition or use of positional arguments being
cfg
'd out was discussed in #140279 (comment) and subsequent comments. Such a lint is not currently implemented, but that may not be a blocker based on the comments there.r? @traviscross (I'm assuming you'll reassign as needed)