Skip to content

Commit 32ef5e0

Browse files
committed
Check MSRV for any entity, not just function and method calls
New Rust releases also stabilize enum variants, constants, and so on. Lint them as well.
1 parent e6d1816 commit 32ef5e0

6 files changed

+23
-14
lines changed

clippy_lints/src/incompatible_msrv.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,12 @@ impl<'tcx> LateLintPass<'tcx> for IncompatibleMsrv {
174174
self.emit_lint_if_under_msrv(cx, method_did, expr.hir_id, span);
175175
}
176176
},
177-
ExprKind::Call(call, _) => {
178-
// Desugaring into function calls by the compiler will use `QPath::LangItem` variants. Those should
179-
// not be linted as they will not be generated in older compilers if the function is not available,
180-
// and the compiler is allowed to call unstable functions.
181-
if let ExprKind::Path(qpath @ (QPath::Resolved(..) | QPath::TypeRelative(..))) = call.kind
182-
&& let Some(path_def_id) = cx.qpath_res(&qpath, call.hir_id).opt_def_id()
183-
{
184-
self.emit_lint_if_under_msrv(cx, path_def_id, expr.hir_id, call.span);
177+
// Desugaring into function calls by the compiler will use `QPath::LangItem` variants. Those should
178+
// not be linted as they will not be generated in older compilers if the function is not available,
179+
// and the compiler is allowed to call unstable functions.
180+
ExprKind::Path(qpath @ (QPath::Resolved(..) | QPath::TypeRelative(..))) => {
181+
if let Some(path_def_id) = cx.qpath_res(&qpath, expr.hir_id).opt_def_id() {
182+
self.emit_lint_if_under_msrv(cx, path_def_id, expr.hir_id, expr.span);
185183
}
186184
},
187185
_ => {},

tests/ui/checked_conversions.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub const fn issue_8898(i: u32) -> bool {
9595
#[clippy::msrv = "1.33"]
9696
fn msrv_1_33() {
9797
let value: i64 = 33;
98-
let _ = value <= (u32::MAX as i64) && value >= 0;
98+
let _ = value <= (u32::max_value() as i64) && value >= 0;
9999
}
100100

101101
#[clippy::msrv = "1.34"]

tests/ui/checked_conversions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ pub const fn issue_8898(i: u32) -> bool {
9595
#[clippy::msrv = "1.33"]
9696
fn msrv_1_33() {
9797
let value: i64 = 33;
98-
let _ = value <= (u32::MAX as i64) && value >= 0;
98+
let _ = value <= (u32::max_value() as i64) && value >= 0;
9999
}
100100

101101
#[clippy::msrv = "1.34"]
102102
fn msrv_1_34() {
103103
let value: i64 = 34;
104-
let _ = value <= (u32::MAX as i64) && value >= 0;
104+
let _ = value <= (u32::max_value() as i64) && value >= 0;
105105
//~^ checked_conversions
106106
}
107107

tests/ui/checked_conversions.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ LL | let _ = value <= u16::MAX as u32 && value as i32 == 5;
100100
error: checked cast can be simplified
101101
--> tests/ui/checked_conversions.rs:104:13
102102
|
103-
LL | let _ = value <= (u32::MAX as i64) && value >= 0;
104-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
103+
LL | let _ = value <= (u32::max_value() as i64) && value >= 0;
104+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
105105

106106
error: aborting due to 17 previous errors
107107

tests/ui/incompatible_msrv.rs

+5
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,9 @@ fn feature_enable_14425(ptr: *const u8) -> usize {
105105
//~^ incompatible_msrv
106106
}
107107

108+
fn non_fn_items() {
109+
let _ = std::io::ErrorKind::CrossesDevices;
110+
//~^ incompatible_msrv
111+
}
112+
108113
fn main() {}

tests/ui/incompatible_msrv.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,11 @@ error: current MSRV (Minimum Supported Rust Version) is `1.78.0` but this item i
7474
LL | r.isqrt()
7575
| ^^^^^^^
7676

77-
error: aborting due to 11 previous errors
77+
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.85.0`
78+
--> tests/ui/incompatible_msrv.rs:109:13
79+
|
80+
LL | let _ = std::io::ErrorKind::CrossesDevices;
81+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
83+
error: aborting due to 12 previous errors
7884

0 commit comments

Comments
 (0)