Open
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.