Skip to content

Commit 73d9ce6

Browse files
committed
fix(or_fun_call): respect MSRV for unwrap_or_default suggestion
The `unwrap_or_default()` method was introduced in Rust 1.16, but the lint was suggesting it even when the MSRV was set to 1.15 or lower. This change adds an MSRV check to ensure we only suggest `unwrap_or_default()` when the MSRV is at least 1.16. The fix: 1. Adds MSRV check in `check_unwrap_or_default` using `msrvs::STR_REPEAT` (Rust 1.16) 2. Adds MSRV parameter to the `check` function signature 3. Updates the call site to pass the MSRV parameter 4. Adds `#[allow(clippy::too_many_arguments)]` to handle the linter warning Fixes #14876 (unwrap_or_default MSRV issue)
1 parent 56df855 commit 73d9ce6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

clippy_lints/src/methods/or_fun_call.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(super) fn check<'tcx>(
3333
/// `or_insert(T::new())` or `or_insert(T::default())`.
3434
/// Similarly checks for `unwrap_or_else(T::new)`, `unwrap_or_else(T::default)`,
3535
/// `or_insert_with(T::new)` or `or_insert_with(T::default)`.
36+
#[allow(clippy::too_many_arguments)]
3637
fn check_unwrap_or_default(
3738
cx: &LateContext<'_>,
3839
name: Symbol,
@@ -63,8 +64,8 @@ pub(super) fn check<'tcx>(
6364

6465
let output_type_implements_default = |fun| {
6566
let fun_ty = cx.typeck_results().expr_ty(fun);
66-
if let ty::FnDef(def_id, args) = fun_ty.kind() {
67-
let output_ty = cx.tcx.fn_sig(def_id).instantiate(cx.tcx, args).skip_binder().output();
67+
if let ty::FnDef(def_id, substs) = fun_ty.kind() {
68+
let output_ty = cx.tcx.fn_sig(def_id).instantiate(cx.tcx, substs).skip_binder().output();
6869
cx.tcx
6970
.get_diagnostic_item(sym::Default)
7071
.is_some_and(|default_trait_id| implements_trait(cx, output_ty, default_trait_id, &[]))

0 commit comments

Comments
 (0)