Skip to content

Commit a90592a

Browse files
committed
cargo: add --check-cfg cfg(test) unconditionally
It should be added even if unexpected_cfgs is not part of Cargo.toml. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 054fd1e commit a90592a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

mesonbuild/cargo/interpreter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def get_lint_args(self, rustc: RustCompiler) -> T.List[str]:
144144
args.extend(lint.to_arguments(has_check_cfg))
145145

146146
if has_check_cfg:
147+
args.append('--check-cfg')
148+
args.append('cfg(test)')
147149
for feature in self.manifest.features:
148150
if feature != 'default':
149151
args.append('--check-cfg')

mesonbuild/cargo/manifest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ def from_raw(cls, r: T.Union[raw.FromWorkspace, T.Dict[str, T.Dict[str, raw.Lint
442442
settings = T.cast('raw.Lint', {'level': settings})
443443
check_cfg = None
444444
if name == 'unexpected_cfgs':
445-
# 'cfg(test)' is added automatically by cargo
446-
check_cfg = ['cfg(test)'] + settings.get('check-cfg', [])
445+
check_cfg = settings.get('check-cfg', [])
447446
lints[name] = Lint(name=name,
448447
level=settings['level'],
449448
priority=settings.get('priority', 0),

unittests/cargotests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def test_cargo_toml_lints(self) -> None:
428428
self.assertEqual(manifest.lints[2].name, 'unexpected_cfgs')
429429
self.assertEqual(manifest.lints[2].level, 'deny')
430430
self.assertEqual(manifest.lints[2].priority, 0)
431-
self.assertEqual(manifest.lints[2].check_cfg, ['cfg(test)', 'cfg(MESON)'])
431+
self.assertEqual(manifest.lints[2].check_cfg, ['cfg(MESON)'])
432432

433433
def test_cargo_toml_lints_to_args(self) -> None:
434434
with tempfile.TemporaryDirectory() as tmpdir:
@@ -444,8 +444,7 @@ def test_cargo_toml_lints_to_args(self) -> None:
444444
self.assertEqual(manifest.lints[1].to_arguments(True), ['-A', 'unknown_lints'])
445445
self.assertEqual(manifest.lints[2].to_arguments(False), ['-D', 'unexpected_cfgs'])
446446
self.assertEqual(manifest.lints[2].to_arguments(True),
447-
['-D', 'unexpected_cfgs', '--check-cfg', 'cfg(test)',
448-
'--check-cfg', 'cfg(MESON)'])
447+
['-D', 'unexpected_cfgs', '--check-cfg', 'cfg(MESON)'])
449448

450449
def test_cargo_toml_dependencies(self) -> None:
451450
with tempfile.TemporaryDirectory() as tmpdir:

0 commit comments

Comments
 (0)