-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Disallow setting some built-in cfg via the command-line #126158
Conversation
4b6c448
to
4ebdd5c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
e63e8f7
to
30480ad
Compare
I've changed the error from a hard-error to a deny-by-default lint as asked and included all the possible cfgs that wouldn't break the world (and added some links for the one that we can't lint on them). @rustbot ready |
Addressed or replied to all the review comments. @rustbot ready |
Ok, let's try landing this. |
Another case of a But just to be sure, and to not waste more CI-merge time. Let's do a big try build across many different targets. |
Disallow setting some built-in cfg via set the command-line This PR disallow users from setting some built-in cfg via set the command-line in order to prevent incoherent state, eg. `windows` cfg active but target is Linux based. This implements MCP rust-lang/compiler-team#610, with the caveat that we disallow cfgs no matter if they make sense or not, since I don't think it's useful to allow users to set a cfg that will be set anyway. It also complicates the implementation. ------ The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag. *(deny-by-default)* ### Example ```text rustc --cfg unix ``` ```rust,ignore (needs command line option) fn main() {} ``` This will produce: ```text error: unexpected `--cfg unix` flag | = note: config `unix` is only supposed to be controlled by `--target` = note: manually setting a built-in cfg can and does create incoherent behaviours = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default ``` ### Explanation Setting builtin cfgs can and does produce incoherent behaviour, it's better to the use the appropriate `rustc` flag that controls the config. For example setting the `windows` cfg but on Linux based target. ----- r? `@petrochenkov` cc `@jyn514` try-job: aarch64-apple try-job: test-various try-job: armhf-gnu try-job: x86_64-msvc try-job: x86_64-mingw try-job: i686-msvc try-job: i686-mingw try-job: x86_64-gnu-llvm-17 try-job: dist-various-1
r=me after CI is green. |
@bors r=petrochenkov |
Wait, try isn't finishing yet, and bors doesn't like r and try at the same time. |
☀️ Try build successful - checks-actions |
@bors r=petrochenkov |
☀️ Test successful - checks-actions |
Finished benchmarking commit (ce20e15): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -2.6%, secondary -1.9%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 760.558s -> 760.891s (0.04%) |
This PR disallow users from setting some built-in cfg via set the command-line in order to prevent incoherent state, eg.
windows
cfg active but target is Linux based.This implements MCP rust-lang/compiler-team#610, with the caveat that we disallow cfgs no matter if they make sense or not, since I don't think it's useful to allow users to set a cfg that will be set anyway. It also complicates the implementation.
The
explicit_builtin_cfgs_in_flags
lint detects builtin cfgs set via the--cfg
flag.(deny-by-default)
Example
This will produce:
Explanation
Setting builtin cfgs can and does produce incoherent behaviour, it's better to the use the appropriate
rustc
flag that controls the config. For example setting thewindows
cfg but on Linux based target.r? @petrochenkov
cc @jyn514
try-job: aarch64-apple
try-job: test-various
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: x86_64-mingw
try-job: i686-msvc
try-job: i686-mingw
try-job: x86_64-gnu-llvm-17
try-job: dist-various-1