Skip to content

Commit 980afaa

Browse files
committed
Move malformatted check-cfg config warning to error
since it's always backwards compatible to go from error to warn, but not the inverse.
1 parent 3335a6d commit 980afaa

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/cargo/core/compiler/build_runner/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
246246
let mut args = compiler::extern_args(&self, unit, &mut unstable_opts)?;
247247
args.extend(compiler::lto_args(&self, unit));
248248
args.extend(compiler::features_args(unit));
249-
args.extend(compiler::check_cfg_args(&self, unit));
249+
args.extend(compiler::check_cfg_args(&self, unit)?);
250250

251251
let script_meta = self.find_build_script_metadata(unit);
252252
if let Some(meta) = script_meta {

src/cargo/core/compiler/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use std::io::{BufRead, Write};
6363
use std::path::{Path, PathBuf};
6464
use std::sync::Arc;
6565

66-
use anyhow::{Context as _, Error};
66+
use anyhow::{bail, Context as _, Error};
6767
use lazycell::LazyCell;
6868
use tracing::{debug, trace};
6969

@@ -732,7 +732,7 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
732732
let doc_dir = build_runner.files().out_dir(unit);
733733
rustdoc.arg("-o").arg(&doc_dir);
734734
rustdoc.args(&features_args(unit));
735-
rustdoc.args(&check_cfg_args(build_runner, unit));
735+
rustdoc.args(&check_cfg_args(build_runner, unit)?);
736736

737737
add_error_format_and_color(build_runner, &mut rustdoc);
738738
add_allow_features(build_runner, &mut rustdoc);
@@ -1125,7 +1125,7 @@ fn build_base_args(
11251125
}
11261126

11271127
cmd.args(&features_args(unit));
1128-
cmd.args(&check_cfg_args(build_runner, unit));
1128+
cmd.args(&check_cfg_args(build_runner, unit)?);
11291129

11301130
let meta = build_runner.files().metadata(unit);
11311131
cmd.arg("-C").arg(&format!("metadata={}", meta));
@@ -1310,7 +1310,7 @@ fn trim_paths_args(
13101310
}
13111311

13121312
/// Generates the `--check-cfg` arguments for the `unit`.
1313-
fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> Vec<OsString> {
1313+
fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<Vec<OsString>> {
13141314
if build_runner
13151315
.bcx
13161316
.target_data
@@ -1373,19 +1373,19 @@ fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> Vec<OsStri
13731373
args.push(OsString::from("--check-cfg"));
13741374
args.push(OsString::from(check_cfg));
13751375
}
1376-
// warn (if wise) about `check-cfg` not being a list-of-string
1377-
} else if unit.show_warnings(&build_runner.bcx.gctx) {
1378-
let _ = build_runner.bcx.gctx.shell().warn("`lints.rust.unexpected_cfgs.check-cfg` must be a list of string");
1376+
// error about `check-cfg` not being a list-of-string
1377+
} else {
1378+
bail!("`lints.rust.unexpected_cfgs.check-cfg` must be a list of string");
13791379
}
13801380
}
13811381
}
13821382
}
13831383
}
13841384
}
13851385

1386-
args
1386+
Ok(args)
13871387
} else {
1388-
Vec::new()
1388+
Ok(Vec::new())
13891389
}
13901390
}
13911391

tests/testsuite/check_cfg.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,9 @@ fn config_invalid_not_list() {
653653
.build();
654654

655655
p.cargo("check")
656+
.with_status(101)
656657
.with_stderr_contains(
657-
"[..]`lints.rust.unexpected_cfgs.check-cfg` must be a list of string[..]",
658+
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
658659
)
659660
.run();
660661
}
@@ -678,8 +679,9 @@ fn config_invalid_not_list_string() {
678679
.build();
679680

680681
p.cargo("check")
682+
.with_status(101)
681683
.with_stderr_contains(
682-
"[..]`lints.rust.unexpected_cfgs.check-cfg` must be a list of string[..]",
684+
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
683685
)
684686
.run();
685687
}

0 commit comments

Comments
 (0)