Skip to content

Commit d29f2ee

Browse files
committed
Auto merge of rust-lang#12261 - Jarcho:issue_12257, r=dswij
Don't lint `incompatible_msrv` in test code fixes rust-lang#12257 changelog: `incompatible_msrv`: Don't lint in test code
2 parents 51c89a4 + 9012d55 commit d29f2ee

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clippy_lints/src/incompatible_msrv.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use clippy_config::msrvs::Msrv;
22
use clippy_utils::diagnostics::span_lint;
3+
use clippy_utils::is_in_test_function;
34
use rustc_attr::{StabilityLevel, StableSince};
45
use rustc_data_structures::fx::FxHashMap;
5-
use rustc_hir::{Expr, ExprKind};
6+
use rustc_hir::{Expr, ExprKind, HirId};
67
use rustc_lint::{LateContext, LateLintPass};
78
use rustc_middle::ty::TyCtxt;
89
use rustc_semver::RustcVersion;
@@ -81,13 +82,13 @@ impl IncompatibleMsrv {
8182
version
8283
}
8384

84-
fn emit_lint_if_under_msrv(&mut self, cx: &LateContext<'_>, def_id: DefId, span: Span) {
85+
fn emit_lint_if_under_msrv(&mut self, cx: &LateContext<'_>, def_id: DefId, node: HirId, span: Span) {
8586
if def_id.is_local() {
8687
// We don't check local items since their MSRV is supposed to always be valid.
8788
return;
8889
}
8990
let version = self.get_def_id_version(cx.tcx, def_id);
90-
if self.msrv.meets(version) {
91+
if self.msrv.meets(version) || is_in_test_function(cx.tcx, node) {
9192
return;
9293
}
9394
self.emit_lint_for(cx, span, version);
@@ -117,14 +118,14 @@ impl<'tcx> LateLintPass<'tcx> for IncompatibleMsrv {
117118
match expr.kind {
118119
ExprKind::MethodCall(_, _, _, span) => {
119120
if let Some(method_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {
120-
self.emit_lint_if_under_msrv(cx, method_did, span);
121+
self.emit_lint_if_under_msrv(cx, method_did, expr.hir_id, span);
121122
}
122123
},
123124
ExprKind::Call(call, [_]) => {
124125
if let ExprKind::Path(qpath) = call.kind
125126
&& let Some(path_def_id) = cx.qpath_res(&qpath, call.hir_id).opt_def_id()
126127
{
127-
self.emit_lint_if_under_msrv(cx, path_def_id, call.span);
128+
self.emit_lint_if_under_msrv(cx, path_def_id, expr.hir_id, call.span);
128129
}
129130
},
130131
_ => {},

tests/ui/incompatible_msrv.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ fn foo() {
2020
//~^ ERROR: is `1.3.0` but this item is stable since `1.4.0`
2121
}
2222

23+
#[test]
24+
fn test() {
25+
sleep(Duration::new(1, 0));
26+
}
27+
2328
fn main() {}

0 commit comments

Comments
 (0)