configuration option to lint incompatible_msrv in test code

This commit is contained in:
Bryce Berger 2025-02-22 18:53:25 -05:00
parent d92da0fb32
commit 325bfef88d
No known key found for this signature in database
GPG key ID: 58CA4F9FEF8F4296
10 changed files with 87 additions and 1 deletions

View file

@ -42,6 +42,7 @@ declare_clippy_lint! {
pub struct IncompatibleMsrv {
msrv: Msrv,
is_above_msrv: FxHashMap<DefId, RustcVersion>,
check_in_tests: bool,
}
impl_lint_pass!(IncompatibleMsrv => [INCOMPATIBLE_MSRV]);
@ -51,6 +52,7 @@ impl IncompatibleMsrv {
Self {
msrv: conf.msrv.clone(),
is_above_msrv: FxHashMap::default(),
check_in_tests: conf.check_incompatible_msrv_in_tests,
}
}
@ -87,7 +89,7 @@ impl IncompatibleMsrv {
return;
}
let version = self.get_def_id_version(cx.tcx, def_id);
if self.msrv.meets(version) || is_in_test(cx.tcx, node) {
if self.msrv.meets(version) || (!self.check_in_tests && is_in_test(cx.tcx, node)) {
return;
}
if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind {