-
Notifications
You must be signed in to change notification settings - Fork 557
document cfg conditions on inline assembly templates and operands
#2063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/inline-assembly.md
Outdated
| r[asm.ts-args.attributes] | ||
| Only the [`cfg`] and [`cfg_attr`] attributes are accepted on inline assembly template strings and operands. Other attributes are parsed, but rejected when the assembly macro is expanded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I said to put it here, I had momentarily forgotten that this applied to operands as well.
Given that, probably it shouldn't go here. There's not really another obvious section for it, though. Probably syntax is the closest, but maybe it'd be better to just create a new asm.attributes section, even just for this one purpose, as we're describing particularly what is semantically accepted, so it's not a great fit for syntax.
Probably too, we'll want to use the phrase "accepted semantically" in this sentence to be more clear upfront about the distinction we're making.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also please describe the rule imposed in rust-lang/rust#147736 (comment):
operand before template
The current implementation expects at least one template string before any operands. In the example below, if the
cfgcondition evaluates to true, the assembly block is ill-formed. But even when it evaluates tofalsethis 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.
// This is rejected because `a = out(reg) x` does not parse as an expresion. asm!( #[cfg(false)] a = out(reg) x, //~ ERROR expected token: `,` "", );
Let's include the example in the text.
| * [Function][functions], [closure] and [function pointer] | ||
| parameters accept outer attributes. This includes attributes on variadic parameters | ||
| denoted with `...` in function pointers and [external blocks][variadic functions]. | ||
| * [Inline assembly] template strings and operands accept outer attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, it may be a mostly theoretical concern, but attributes are not supported here.
asm! rather have an attribute-like syntax in its DSL - rust-lang/rust#147736 (comment).
The "only cfg and cfg_attr" restriction is unique to all attribute positions and is a direct consequence of the above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list is about allowed positions, and with asm_cfg attributes are parsed on template strings and operands, so saying that they are a valid position for attributes feels right.
But yeah they aren't really supported like in the other places listed here.
ab6234f to
8fc2f56
Compare
Reference PR for:
asm_cfgrust#147736