-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Hi,
I was recently defeated by rustc --cfg
.
rustc -h
says:
--cfg SPEC Configure the compilation environment
Hrm, well I know that stuff like --cfg var
should work, but that I should also be able to assign a value:
$ rustc --cfg key=val -
error: invalid `--cfg` argument: `key=val` (expected `key` or `key="value"`)
$ rustc --cfg key="val" -
error: invalid `--cfg` argument: `key=val` (expected `key` or `key="value"`)
Eh? I passed exactly what the error asked. And obviously the backticks can't form the solution, as they'd open a sub-shell.
The solution is to use: rustc --cfg 'key="val"'
The quoting is very specific.
Swapping the single and double quotes won't work:
$ rustc --cfg "key='val'" -
error: character literal may only contain one codepoint
--> <quote expansion>:1:5
|
1 | key='val'
| ^^^^^
help: if you meant to write a `str` literal, use double quotes
|
1 | key="val"
| ^^^^^
And oddly, quoting the value is ok, but not the key:
$ rustc --cfg '"key"="val"' -
error: invalid `--cfg` argument: `"key"="val"` (expected `key` or `key="value"`)
I find this wholly unexpected and I had to grep the source code to find out how to use the argument :(
So are the current limitations of the interface intentional?
If so, we should improve the -h
doc and error message.
If not, what do we want? Should --cfg
accept:
key=val
'key="val"
"key='val'"
'"key"="val"'
"key=val"
Thanks.
ptersilie, jacob-hughes, kleimkuhler, ninjasource and tgross35
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.