Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce20e15

Browse files
committedAug 7, 2024·
Auto merge of rust-lang#126158 - Urgau:disallow-cfgs, r=petrochenkov
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
2 parents 8d00669 + c0c57b3 commit ce20e15

File tree

45 files changed

+467
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+467
-80
lines changed
 

‎compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ fn make_format_args(
555555
};
556556
let arg_name = args.explicit_args()[index].kind.ident().unwrap();
557557
ecx.buffered_early_lint.push(BufferedEarlyLint {
558-
span: arg_name.span.into(),
558+
span: Some(arg_name.span.into()),
559559
node_id: rustc_ast::CRATE_NODE_ID,
560560
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
561561
diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally {

‎compiler/rustc_lint/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::Manual
775775
.label = argument has type `{$arg_ty}`
776776
.suggestion = use `std::mem::ManuallyDrop::into_inner` to get the inner value
777777
778+
lint_unexpected_builtin_cfg = unexpected `--cfg {$cfg}` flag
779+
.controlled_by = config `{$cfg_name}` is only supposed to be controlled by `{$controlled_by}`
780+
.incoherent = manually setting a built-in cfg can and does create incoherent behaviors
781+
778782
lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_println}` to the top of the `build.rs`
779783
lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
780784
lint_unexpected_cfg_add_cargo_toml_lint_cfg = or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}

0 commit comments

Comments
 (0)
This repository has been archived.