Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
use clippy_utils::sugg::has_enclosing_paren;
use clippy_utils::ty::{adjust_derefs_manually_drop, implements_trait, is_manually_drop};
use clippy_utils::ty::{adjust_derefs_manually_drop, implements_trait, is_manually_drop, peel_and_count_ty_refs};
use clippy_utils::{
DefinedTy, ExprUseNode, expr_use_ctxt, get_parent_expr, is_block_like, is_lint_allowed, path_to_local,
peel_middle_ty_refs,
};
use rustc_ast::util::parser::ExprPrecedence;
use rustc_data_structures::fx::FxIndexMap;
Expand Down Expand Up @@ -942,7 +941,7 @@ fn report<'tcx>(
let (expr_str, expr_is_macro_call) =
snippet_with_context(cx, expr.span, data.first_expr.span.ctxt(), "..", &mut app);
let ty = typeck.expr_ty(expr);
let (_, ref_count) = peel_middle_ty_refs(ty);
let (_, ref_count, _) = peel_and_count_ty_refs(ty);
let deref_str = if ty_changed_count >= ref_count && ref_count != 0 {
// a deref call changing &T -> &U requires two deref operators the first time
// this occurs. One to remove the reference, a second to call the deref impl.
Expand Down Expand Up @@ -1045,7 +1044,7 @@ fn report<'tcx>(
if let ty::Ref(_, dst, _) = data.adjusted_ty.kind()
&& dst.is_slice()
{
let (src, n_src_refs) = peel_middle_ty_refs(ty);
let (src, n_src_refs, _) = peel_and_count_ty_refs(ty);
if n_src_refs >= 2 && src.is_array() {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_middle::ty;
use rustc_span::def_id::LocalDefId;

use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::type_is_unsafe_function;
use clippy_utils::ty::is_unsafe_fn;
use clippy_utils::visitors::for_each_expr;
use clippy_utils::{iter_input_pats, path_to_local};

Expand Down Expand Up @@ -51,7 +51,7 @@ fn check_raw_ptr<'tcx>(
let typeck = cx.tcx.typeck_body(body.id());
let _: Option<!> = for_each_expr(cx, body.value, |e| {
match e.kind {
hir::ExprKind::Call(f, args) if type_is_unsafe_function(cx, typeck.expr_ty(f)) => {
hir::ExprKind::Call(f, args) if is_unsafe_fn(cx, typeck.expr_ty(f)) => {
for arg in args {
check_arg(cx, &raw_ptrs, arg);
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/manual_abs_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use clippy_utils::higher::If;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::HasSession as _;
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{eq_expr_value, peel_blocks, peel_middle_ty_refs, span_contains_comment};
use clippy_utils::ty::{is_type_diagnostic_item, peel_and_count_ty_refs};
use clippy_utils::{eq_expr_value, peel_blocks, span_contains_comment};
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -107,7 +107,7 @@ impl ManualAbsDiff {
|ty| is_type_diagnostic_item(cx, ty, sym::Duration) && self.msrv.meets(cx, msrvs::DURATION_ABS_DIFF);

let a_ty = cx.typeck_results().expr_ty(a).peel_refs();
let (b_ty, b_n_refs) = peel_middle_ty_refs(cx.typeck_results().expr_ty(b));
let (b_ty, b_n_refs, _) = peel_and_count_ty_refs(cx.typeck_results().expr_ty(b));

(a_ty == b_ty && (is_int(a_ty) || is_duration(a_ty))).then_some((a_ty, b_n_refs))
}
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/manual_slice_size_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clippy_config::Conf;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::snippet_with_context;
use clippy_utils::ty::peel_and_count_ty_refs;
use clippy_utils::{expr_or_init, is_in_const_context, std_or_core};
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
Expand Down Expand Up @@ -102,7 +103,7 @@ fn simplify_half<'tcx>(
&& let ExprKind::MethodCall(method_path, receiver, [], _) = expr1.kind
&& method_path.ident.name == sym::len
&& let receiver_ty = cx.typeck_results().expr_ty(receiver)
&& let (receiver_ty, refs_count) = clippy_utils::ty::walk_ptrs_ty_depth(receiver_ty)
&& let (receiver_ty, refs_count, _) = peel_and_count_ty_refs(receiver_ty)
&& let ty::Slice(ty1) = receiver_ty.kind()
// expr2 is `size_of::<T2>()`?
&& let ExprKind::Call(func, []) = expr2.kind
Expand Down
16 changes: 6 additions & 10 deletions clippy_lints/src/matches/manual_ok_err.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::{indent_of, reindent_multiline};
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{option_arg_ty, peel_mid_ty_refs_is_mutable};
use clippy_utils::ty::{option_arg_ty, peel_and_count_ty_refs};
use clippy_utils::{get_parent_expr, is_res_lang_ctor, path_res, peel_blocks, span_contains_comment};
use rustc_ast::{BindingMode, Mutability};
use rustc_errors::Applicability;
Expand Down Expand Up @@ -135,15 +135,11 @@ fn apply_lint(cx: &LateContext<'_>, expr: &Expr<'_>, scrutinee: &Expr<'_>, is_ok
let scrut = Sugg::hir_with_applicability(cx, scrutinee, "..", &mut app).maybe_paren();

let scrutinee_ty = cx.typeck_results().expr_ty(scrutinee);
let (_, n_ref, mutability) = peel_mid_ty_refs_is_mutable(scrutinee_ty);
let prefix = if n_ref > 0 {
if mutability == Mutability::Mut {
".as_mut()"
} else {
".as_ref()"
}
} else {
""
let (_, _, mutability) = peel_and_count_ty_refs(scrutinee_ty);
let prefix = match mutability {
Some(Mutability::Mut) => ".as_mut()",
Some(Mutability::Not) => ".as_ref()",
None => "",
};

let sugg = format!("{scrut}{prefix}.{method}()");
Expand Down
9 changes: 5 additions & 4 deletions clippy_lints/src/matches/manual_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::map_unit_fn::OPTION_MAP_UNIT_FN;
use crate::matches::MATCH_AS_REF;
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{is_copy, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable, type_is_unsafe_function};
use clippy_utils::ty::{is_copy, is_type_diagnostic_item, is_unsafe_fn, peel_and_count_ty_refs};
use clippy_utils::{
CaptureKind, can_move_expr_to_closure, expr_requires_coercion, is_else_clause, is_lint_allowed, is_res_lang_ctor,
path_res, path_to_local_id, peel_blocks, peel_hir_expr_refs, peel_hir_expr_while,
Expand Down Expand Up @@ -30,8 +30,9 @@ pub(super) fn check_with<'tcx, F>(
where
F: Fn(&LateContext<'tcx>, &'tcx Pat<'_>, &'tcx Expr<'_>, SyntaxContext) -> Option<SomeExpr<'tcx>>,
{
let (scrutinee_ty, ty_ref_count, ty_mutability) =
peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
let (scrutinee_ty, ty_ref_count, ty_mutability) = peel_and_count_ty_refs(cx.typeck_results().expr_ty(scrutinee));
let ty_mutability = ty_mutability.unwrap_or(Mutability::Mut);

if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::Option)
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Option))
{
Expand Down Expand Up @@ -191,7 +192,7 @@ fn can_pass_as_func<'tcx>(cx: &LateContext<'tcx>, binding: HirId, expr: &'tcx Ex
ExprKind::Call(func, [arg])
if path_to_local_id(arg, binding)
&& cx.typeck_results().expr_adjustments(arg).is_empty()
&& !type_is_unsafe_function(cx, cx.typeck_results().expr_ty(func).peel_refs()) =>
&& !is_unsafe_fn(cx, cx.typeck_results().expr_ty(func).peel_refs()) =>
{
Some(func)
},
Expand Down
8 changes: 3 additions & 5 deletions clippy_lints/src/matches/single_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::{
SpanRangeExt, expr_block, snippet, snippet_block_with_context, snippet_with_applicability, snippet_with_context,
};
use clippy_utils::ty::implements_trait;
use clippy_utils::{
is_lint_allowed, is_unit_expr, peel_blocks, peel_hir_pat_refs, peel_middle_ty_refs, peel_n_hir_expr_refs,
};
use clippy_utils::ty::{implements_trait, peel_and_count_ty_refs};
use clippy_utils::{is_lint_allowed, is_unit_expr, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs};
use core::ops::ControlFlow;
use rustc_arena::DroplessArena;
use rustc_errors::{Applicability, Diag};
Expand Down Expand Up @@ -133,7 +131,7 @@ fn report_single_pattern(

let (pat, pat_ref_count) = peel_hir_pat_refs(arm.pat);
let (msg, sugg) = if let PatKind::Expr(_) = pat.kind
&& let (ty, ty_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(ex))
&& let (ty, ty_ref_count, _) = peel_and_count_ty_refs(cx.typeck_results().expr_ty(ex))
&& let Some(spe_trait_id) = cx.tcx.lang_items().structural_peq_trait()
&& let Some(pe_trait_id) = cx.tcx.lang_items().eq_trait()
&& (ty.is_integral()
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/implicit_clone.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_context;
use clippy_utils::ty::implements_trait;
use clippy_utils::{is_diag_item_method, is_diag_trait_item, peel_middle_ty_refs, sym};
use clippy_utils::ty::{implements_trait, peel_and_count_ty_refs};
use clippy_utils::{is_diag_item_method, is_diag_trait_item, sym};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
Expand All @@ -14,7 +14,7 @@ pub fn check(cx: &LateContext<'_>, method_name: Symbol, expr: &hir::Expr<'_>, re
&& is_clone_like(cx, method_name, method_def_id)
&& let return_type = cx.typeck_results().expr_ty(expr)
&& let input_type = cx.typeck_results().expr_ty(recv)
&& let (input_type, ref_count) = peel_middle_ty_refs(input_type)
&& let (input_type, ref_count, _) = peel_and_count_ty_refs(input_type)
&& !(ref_count > 0 && is_diag_trait_item(cx, method_def_id, sym::ToOwned))
&& let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did()))
&& return_type == input_type
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/inefficient_to_string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::{is_type_lang_item, walk_ptrs_ty_depth};
use clippy_utils::ty::{is_type_lang_item, peel_and_count_ty_refs};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
Expand All @@ -24,7 +24,7 @@ pub fn check(
&& let Some(args) = cx.typeck_results().node_args_opt(expr.hir_id)
&& let arg_ty = cx.typeck_results().expr_ty_adjusted(receiver)
&& let self_ty = args.type_at(0)
&& let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty)
&& let (deref_self_ty, deref_count, _) = peel_and_count_ty_refs(self_ty)
&& deref_count >= 1
&& specializes_tostring(cx, deref_self_ty)
{
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/methods/mut_mutex_lock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::expr_custom_deref_adjustment;
use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
use clippy_utils::ty::{is_type_diagnostic_item, peel_and_count_ty_refs};
use rustc_errors::Applicability;
use rustc_hir::{Expr, Mutability};
use rustc_lint::LateContext;
Expand All @@ -10,8 +10,7 @@ use super::MUT_MUTEX_LOCK;

pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>, recv: &'tcx Expr<'tcx>, name_span: Span) {
if matches!(expr_custom_deref_adjustment(cx, recv), None | Some(Mutability::Mut))
&& let (_, ref_depth, Mutability::Mut) = peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(recv))
&& ref_depth >= 1
&& let (_, _, Some(Mutability::Mut)) = peel_and_count_ty_refs(cx.typeck_results().expr_ty(recv))
&& let Some(method_id) = cx.typeck_results().type_dependent_def_id(ex.hir_id)
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Mutex)
Expand Down
13 changes: 7 additions & 6 deletions clippy_lints/src/methods/unnecessary_to_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use super::unnecessary_iter_cloned::{self, is_into_iter};
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::{SpanRangeExt, snippet};
use clippy_utils::ty::{get_iterator_item_ty, implements_trait, is_copy, is_type_diagnostic_item, is_type_lang_item};
use clippy_utils::ty::{
get_iterator_item_ty, implements_trait, is_copy, is_type_diagnostic_item, is_type_lang_item, peel_and_count_ty_refs,
};
use clippy_utils::visitors::find_all_ret_expressions;
use clippy_utils::{
fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, is_expr_temporary_value, peel_middle_ty_refs,
return_ty, sym,
fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, is_expr_temporary_value, return_ty, sym,
};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
Expand Down Expand Up @@ -119,8 +120,8 @@ fn check_addr_of_expr(
},
] = adjustments[..]
&& let receiver_ty = cx.typeck_results().expr_ty(receiver)
&& let (target_ty, n_target_refs) = peel_middle_ty_refs(*target_ty)
&& let (receiver_ty, n_receiver_refs) = peel_middle_ty_refs(receiver_ty)
&& let (target_ty, n_target_refs, _) = peel_and_count_ty_refs(*target_ty)
&& let (receiver_ty, n_receiver_refs, _) = peel_and_count_ty_refs(receiver_ty)
// Only flag cases satisfying at least one of the following three conditions:
// * the referent and receiver types are distinct
// * the referent/receiver type is a copyable array
Expand Down Expand Up @@ -385,7 +386,7 @@ fn check_other_call_arg<'tcx>(
&& let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder()
&& let Some(i) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == maybe_arg.hir_id)
&& let Some(input) = fn_sig.inputs().get(i)
&& let (input, n_refs) = peel_middle_ty_refs(*input)
&& let (input, n_refs, _) = peel_and_count_ty_refs(*input)
&& let (trait_predicates, _) = get_input_traits_and_projections(cx, callee_def_id, input)
&& let Some(sized_def_id) = cx.tcx.lang_items().sized_trait()
&& let Some(meta_sized_def_id) = cx.tcx.lang_items().meta_sized_trait()
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/useless_asref.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::{implements_trait, should_call_clone_as_function, walk_ptrs_ty_depth};
use clippy_utils::ty::{implements_trait, peel_and_count_ty_refs, should_call_clone_as_function};
use clippy_utils::{get_parent_expr, is_diag_trait_item, path_to_local_id, peel_blocks, strip_pat_refs};
use rustc_errors::Applicability;
use rustc_hir::{self as hir, LangItem};
Expand Down Expand Up @@ -50,8 +50,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: Symbo
// check if the type after `as_ref` or `as_mut` is the same as before
let rcv_ty = cx.typeck_results().expr_ty(recvr);
let res_ty = cx.typeck_results().expr_ty(expr);
let (base_res_ty, res_depth) = walk_ptrs_ty_depth(res_ty);
let (base_rcv_ty, rcv_depth) = walk_ptrs_ty_depth(rcv_ty);
let (base_res_ty, res_depth, _) = peel_and_count_ty_refs(res_ty);
let (base_rcv_ty, rcv_depth, _) = peel_and_count_ty_refs(rcv_ty);
if base_rcv_ty == base_res_ty && rcv_depth >= res_depth {
if let Some(parent) = get_parent_expr(cx, expr) {
// allow the `as_ref` or `as_mut` if it is followed by another method call
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/redundant_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
use clippy_utils::fn_has_unsatisfiable_preds;
use clippy_utils::mir::{LocalUsage, PossibleBorrowerMap, visit_local_usage};
use clippy_utils::source::SpanRangeExt;
use clippy_utils::ty::{has_drop, is_copy, is_type_lang_item, walk_ptrs_ty_depth};
use clippy_utils::ty::{has_drop, is_copy, is_type_lang_item, peel_and_count_ty_refs};
use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, FnDecl, LangItem, def_id};
Expand Down Expand Up @@ -263,7 +263,7 @@ fn is_call_with_ref_arg<'tcx>(
&& args.len() == 1
&& let mir::Operand::Move(mir::Place { local, .. }) = &args[0].node
&& let ty::FnDef(def_id, _) = *func.ty(mir, cx.tcx).kind()
&& let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].node.ty(mir, cx.tcx))
&& let (inner_ty, 1, _) = peel_and_count_ty_refs(args[0].node.ty(mir, cx.tcx))
&& !is_copy(cx, inner_ty)
{
Some((def_id, *local, inner_ty, destination.as_local()?))
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/redundant_slicing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::get_parent_expr;
use clippy_utils::source::snippet_with_context;
use clippy_utils::ty::is_type_lang_item;
use clippy_utils::{get_parent_expr, peel_middle_ty_refs};
use clippy_utils::ty::{is_type_lang_item, peel_and_count_ty_refs};
use rustc_ast::util::parser::ExprPrecedence;
use rustc_errors::Applicability;
use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
Expand Down Expand Up @@ -82,8 +82,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
&& let ExprKind::Index(indexed, range, _) = addressee.kind
&& is_type_lang_item(cx, cx.typeck_results().expr_ty_adjusted(range), LangItem::RangeFull)
{
let (expr_ty, expr_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(expr));
let (indexed_ty, indexed_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(indexed));
let (expr_ty, expr_ref_count, _) = peel_and_count_ty_refs(cx.typeck_results().expr_ty(expr));
let (indexed_ty, indexed_ref_count, _) = peel_and_count_ty_refs(cx.typeck_results().expr_ty(indexed));
let parent_expr = get_parent_expr(cx, expr);
let needs_parens_for_prefix =
parent_expr.is_some_and(|parent| cx.precedence(parent) > ExprPrecedence::Prefix);
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/size_of_ref.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::{path_def_id, peel_middle_ty_refs};
use clippy_utils::path_def_id;
use clippy_utils::ty::peel_and_count_ty_refs;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
Expand Down Expand Up @@ -59,7 +60,7 @@ impl LateLintPass<'_> for SizeOfRef {
&& let Some(def_id) = path_def_id(cx, path)
&& cx.tcx.is_diagnostic_item(sym::mem_size_of_val, def_id)
&& let arg_ty = cx.typeck_results().expr_ty(arg)
&& peel_middle_ty_refs(arg_ty).1 > 1
&& peel_and_count_ty_refs(arg_ty).1 > 1
{
span_lint_and_help(
cx,
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/unused_peekable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
use clippy_utils::ty::{is_type_diagnostic_item, peel_and_count_ty_refs};
use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators, sym};
use rustc_ast::Mutability;
use rustc_hir::intravisit::{Visitor, walk_expr};
Expand Down Expand Up @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedPeekable {
&& let Some(init) = local.init
&& !init.span.from_expansion()
&& let Some(ty) = cx.typeck_results().expr_ty_opt(init)
&& let (ty, _, Mutability::Mut) = peel_mid_ty_refs_is_mutable(ty)
&& let (ty, _, None | Some(Mutability::Mut)) = peel_and_count_ty_refs(ty)
&& is_type_diagnostic_item(cx, ty, sym::IterPeekable)
{
let mut vis = PeekableVisitor::new(cx, binding);
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {

fn arg_is_mut_peekable(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
if let Some(ty) = cx.typeck_results().expr_ty_opt(arg)
&& let (ty, _, Mutability::Mut) = peel_mid_ty_refs_is_mutable(ty)
&& let (ty, _, None | Some(Mutability::Mut)) = peel_and_count_ty_refs(ty)
&& is_type_diagnostic_item(cx, ty, sym::IterPeekable)
{
true
Expand Down
Loading