Skip to content

Commit 5af88e3

Browse files
committed
Auto merge of rust-lang#6034 - rail-rain:fix_fp_in_indexing_slicing, r=flip1995
Treat refs to arrays the same as owned arrays in `indexing_slicing` and `out_of_bounds_indexing` Fixes rust-lang#6021 ...and remove `walk_ptrs_ty` in favour of `peel_refs`, which came in 2019. --- changelog: Fix a false positive in `indexing_slicing` and `out_of_bounds_indexing` where references to arrays weren't treated as arrays.
2 parents 06f1902 + ce06472 commit 5af88e3

24 files changed

+67
-99
lines changed

clippy_lints/src/bytecount.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::utils::{
2-
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
3-
span_lint_and_sugg, walk_ptrs_ty,
2+
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg,
43
};
54
use if_chain::if_chain;
65
use rustc_ast::ast::UintTy;
@@ -53,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
5352
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
5453
if op.node == BinOpKind::Eq;
5554
if match_type(cx,
56-
walk_ptrs_ty(cx.typeck_results().expr_ty(&filter_args[0])),
55+
cx.typeck_results().expr_ty(&filter_args[0]).peel_refs(),
5756
&paths::SLICE_ITER);
5857
then {
5958
let needle = match get_path_name(l) {
@@ -63,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
6362
_ => { return; }
6463
}
6564
};
66-
if ty::Uint(UintTy::U8) != *walk_ptrs_ty(cx.typeck_results().expr_ty(needle)).kind() {
65+
if ty::Uint(UintTy::U8) != *cx.typeck_results().expr_ty(needle).peel_refs().kind() {
6766
return;
6867
}
6968
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =

clippy_lints/src/duration_subsec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::source_map::Spanned;
77

88
use crate::consts::{constant, Constant};
99
use crate::utils::paths;
10-
use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg, walk_ptrs_ty};
10+
use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg};
1111

1212
declare_clippy_lint! {
1313
/// **What it does:** Checks for calculation of subsecond microseconds or milliseconds
@@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
4343
if_chain! {
4444
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind;
4545
if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind;
46-
if match_type(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])), &paths::DURATION);
46+
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION);
4747
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
4848
then {
4949
let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) {

clippy_lints/src/entry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::SpanlessEq;
22
use crate::utils::{get_item_name, higher, is_type_diagnostic_item, match_type, paths, snippet, snippet_opt};
3-
use crate::utils::{snippet_with_applicability, span_lint_and_then, walk_ptrs_ty};
3+
use crate::utils::{snippet_with_applicability, span_lint_and_then};
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
66
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
@@ -106,7 +106,7 @@ fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static
106106
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind;
107107
then {
108108
let map = &params[0];
109-
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(map));
109+
let obj_ty = cx.typeck_results().expr_ty(map).peel_refs();
110110

111111
return if match_type(cx, obj_ty, &paths::BTREEMAP) {
112112
Some(("BTreeMap", map, key))

clippy_lints/src/fallible_impl_from.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT};
2-
use crate::utils::{
3-
is_expn_of, is_type_diagnostic_item, match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty,
4-
};
2+
use crate::utils::{is_expn_of, is_type_diagnostic_item, match_def_path, method_chain_args, span_lint_and_then};
53
use if_chain::if_chain;
64
use rustc_hir as hir;
75
use rustc_lint::{LateContext, LateLintPass};
@@ -96,7 +94,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
9694

9795
// check for `unwrap`
9896
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
99-
let reciever_ty = walk_ptrs_ty(self.typeck_results.expr_ty(&arglists[0][0]));
97+
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
10098
if is_type_diagnostic_item(self.lcx, reciever_ty, sym!(option_type))
10199
|| is_type_diagnostic_item(self.lcx, reciever_ty, sym!(result_type))
102100
{

clippy_lints/src/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::paths;
22
use crate::utils::{
33
is_expn_of, is_type_diagnostic_item, last_path_segment, match_def_path, match_function_call, snippet,
4-
span_lint_and_then, walk_ptrs_ty,
4+
span_lint_and_then,
55
};
66
use if_chain::if_chain;
77
use rustc_ast::ast::LitKind;
@@ -90,7 +90,7 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: &
9090
if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind;
9191
if pats.len() == 1;
9292
then {
93-
let ty = walk_ptrs_ty(cx.typeck_results().pat_ty(&pats[0]));
93+
let ty = cx.typeck_results().pat_ty(&pats[0]).peel_refs();
9494
if *ty.kind() != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) {
9595
return None;
9696
}

clippy_lints/src/indexing_slicing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]
8888
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
8989
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
9090
if let ExprKind::Index(ref array, ref index) = &expr.kind {
91-
let ty = cx.typeck_results().expr_ty(array);
91+
let ty = cx.typeck_results().expr_ty(array).peel_refs();
9292
if let Some(range) = higher::range(index) {
9393
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
9494
if let ty::Array(_, s) = ty.kind() {

clippy_lints/src/inherent_to_string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
55

66
use crate::utils::{
77
get_trait_def_id, implements_trait, is_type_diagnostic_item, paths, return_ty, span_lint_and_help,
8-
trait_ref_of_method, walk_ptrs_ty,
8+
trait_ref_of_method,
99
};
1010

1111
declare_clippy_lint! {
@@ -125,7 +125,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
125125
// Get the real type of 'self'
126126
let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id);
127127
let self_type = cx.tcx.fn_sig(fn_def_id).input(0);
128-
let self_type = walk_ptrs_ty(self_type.skip_binder());
128+
let self_type = self_type.skip_binder().peel_refs();
129129

130130
// Emit either a warning or an error
131131
if implements_trait(cx, self_type, display_trait_id, &[]) {

clippy_lints/src/len_zero.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{get_item_name, snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty};
1+
use crate::utils::{get_item_name, snippet_with_applicability, span_lint, span_lint_and_sugg};
22
use rustc_ast::ast::LitKind;
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_errors::Applicability;
@@ -285,7 +285,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
285285
})
286286
}
287287

288-
let ty = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr));
288+
let ty = &cx.typeck_results().expr_ty(expr).peel_refs();
289289
match ty.kind() {
290290
ty::Dynamic(ref tt, ..) => tt.principal().map_or(false, |principal| {
291291
cx.tcx

clippy_lints/src/match_on_vec_items.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::utils::walk_ptrs_ty;
21
use crate::utils::{is_type_diagnostic_item, is_type_lang_item, snippet, span_lint_and_sugg};
32
use if_chain::if_chain;
43
use rustc_errors::Applicability;
@@ -90,12 +89,12 @@ fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opti
9089

9190
fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
9291
let ty = cx.typeck_results().expr_ty(expr);
93-
let ty = walk_ptrs_ty(ty);
92+
let ty = ty.peel_refs();
9493
is_type_diagnostic_item(cx, ty, sym!(vec_type))
9594
}
9695

9796
fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
9897
let ty = cx.typeck_results().expr_ty(expr);
99-
let ty = walk_ptrs_ty(ty);
98+
let ty = ty.peel_refs();
10099
is_type_lang_item(cx, ty, LangItem::RangeFull)
101100
}

clippy_lints/src/matches.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::utils::{
66
expr_block, get_arg_name, get_parent_expr, in_macro, indent_of, is_allowed, is_expn_of, is_refutable,
77
is_type_diagnostic_item, is_wild, match_qpath, match_type, match_var, multispan_sugg, remove_blocks, snippet,
88
snippet_block, snippet_with_applicability, span_lint_and_help, span_lint_and_note, span_lint_and_sugg,
9-
span_lint_and_then, walk_ptrs_ty,
9+
span_lint_and_then,
1010
};
1111
use if_chain::if_chain;
1212
use rustc_ast::ast::LitKind;
@@ -794,7 +794,7 @@ fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms
794794
}
795795

796796
fn check_wild_err_arm(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
797-
let ex_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(ex));
797+
let ex_ty = cx.typeck_results().expr_ty(ex).peel_refs();
798798
if is_type_diagnostic_item(cx, ex_ty, sym!(result_type)) {
799799
for arm in arms {
800800
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {

clippy_lints/src/methods/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use crate::utils::{
3232
is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, match_qpath,
3333
match_trait_method, match_type, match_var, method_calls, method_chain_args, paths, remove_blocks, return_ty,
3434
single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint,
35-
span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, sugg, walk_ptrs_ty,
36-
walk_ptrs_ty_depth, SpanlessEq,
35+
span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, sugg, walk_ptrs_ty_depth,
36+
SpanlessEq,
3737
};
3838

3939
declare_clippy_lint! {
@@ -1774,7 +1774,7 @@ fn lint_or_fun_call<'tcx>(
17741774
) {
17751775
if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind {
17761776
if path.ident.as_str() == "len" {
1777-
let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0]));
1777+
let ty = cx.typeck_results().expr_ty(&args[0]).peel_refs();
17781778

17791779
match ty.kind() {
17801780
ty::Slice(_) | ty::Array(_, _) => return,
@@ -1881,7 +1881,7 @@ fn lint_expect_fun_call(
18811881
&& (method_name.ident.name == sym!(as_str) || method_name.ident.name == sym!(as_ref))
18821882
&& {
18831883
let arg_type = cx.typeck_results().expr_ty(&call_args[0]);
1884-
let base_type = walk_ptrs_ty(arg_type);
1884+
let base_type = arg_type.peel_refs();
18851885
*base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type))
18861886
}
18871887
{
@@ -2142,7 +2142,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
21422142
}
21432143

21442144
fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
2145-
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(arg));
2145+
let obj_ty = cx.typeck_results().expr_ty(arg).peel_refs();
21462146

21472147
if let ty::Adt(_, subst) = obj_ty.kind() {
21482148
let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) {
@@ -2173,7 +2173,7 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E
21732173
let arg = &args[1];
21742174
if let Some(arglists) = method_chain_args(arg, &["chars"]) {
21752175
let target = &arglists[0][0];
2176-
let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(target));
2176+
let self_ty = cx.typeck_results().expr_ty(target).peel_refs();
21772177
let ref_str = if *self_ty.kind() == ty::Str {
21782178
""
21792179
} else if is_type_diagnostic_item(cx, self_ty, sym!(string_type)) {
@@ -2201,7 +2201,7 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E
22012201
}
22022202

22032203
fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
2204-
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0]));
2204+
let obj_ty = cx.typeck_results().expr_ty(&args[0]).peel_refs();
22052205
if is_type_diagnostic_item(cx, obj_ty, sym!(string_type)) {
22062206
lint_string_extend(cx, expr, args);
22072207
}
@@ -2384,7 +2384,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_
23842384
}
23852385
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(caller_expr), sym!(vec_type))
23862386
|| matches!(
2387-
&walk_ptrs_ty(cx.typeck_results().expr_ty(caller_expr)).kind(),
2387+
&cx.typeck_results().expr_ty(caller_expr).peel_refs().kind(),
23882388
ty::Array(_, _)
23892389
)
23902390
{
@@ -2587,7 +2587,7 @@ fn derefs_to_slice<'tcx>(
25872587

25882588
/// lint use of `unwrap()` for `Option`s and `Result`s
25892589
fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) {
2590-
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&unwrap_args[0]));
2590+
let obj_ty = cx.typeck_results().expr_ty(&unwrap_args[0]).peel_refs();
25912591

25922592
let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) {
25932593
Some((UNWRAP_USED, "an Option", "None"))
@@ -2615,7 +2615,7 @@ fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::E
26152615

26162616
/// lint use of `expect()` for `Option`s and `Result`s
26172617
fn lint_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) {
2618-
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&expect_args[0]));
2618+
let obj_ty = cx.typeck_results().expr_ty(&expect_args[0]).peel_refs();
26192619

26202620
let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) {
26212621
Some((EXPECT_USED, "an Option", "None"))
@@ -3134,7 +3134,7 @@ fn lint_chars_cmp(
31343134
if segment.ident.name == sym!(Some);
31353135
then {
31363136
let mut applicability = Applicability::MachineApplicable;
3137-
let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty_adjusted(&args[0][0]));
3137+
let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0][0]).peel_refs();
31383138

31393139
if *self_ty.kind() != ty::Str {
31403140
return false;

clippy_lints/src/misc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::utils::sugg::Sugg;
1717
use crate::utils::{
1818
get_item_name, get_parent_expr, higher, implements_trait, in_constant, is_integer_const, iter_input_pats,
1919
last_path_segment, match_qpath, match_trait_method, paths, snippet, snippet_opt, span_lint, span_lint_and_sugg,
20-
span_lint_and_then, span_lint_hir_and_then, walk_ptrs_ty, SpanlessEq,
20+
span_lint_and_then, span_lint_hir_and_then, SpanlessEq,
2121
};
2222

2323
declare_clippy_lint! {
@@ -561,7 +561,7 @@ fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
561561
}
562562

563563
fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
564-
let value = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind();
564+
let value = &cx.typeck_results().expr_ty(expr).peel_refs().kind();
565565

566566
if let ty::Array(arr_ty, _) = value {
567567
return matches!(arr_ty.kind(), ty::Float(_));
@@ -571,7 +571,7 @@ fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
571571
}
572572

573573
fn is_array(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
574-
matches!(&walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind(), ty::Array(_, _))
574+
matches!(&cx.typeck_results().expr_ty(expr).peel_refs().kind(), ty::Array(_, _))
575575
}
576576

577577
fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) {

clippy_lints/src/mut_key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_def_path, paths, span_lint, trait_ref_of_method, walk_ptrs_ty};
1+
use crate::utils::{match_def_path, paths, span_lint, trait_ref_of_method};
22
use rustc_hir as hir;
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_middle::ty::{Adt, Array, RawPtr, Ref, Slice, Tuple, Ty, TypeAndMut};
@@ -98,7 +98,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::
9898
// We want to lint 1. sets or maps with 2. not immutable key types and 3. no unerased
9999
// generics (because the compiler cannot ensure immutability for unknown types).
100100
fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
101-
let ty = walk_ptrs_ty(ty);
101+
let ty = ty.peel_refs();
102102
if let Adt(def, substs) = ty.kind() {
103103
if [&paths::HASHMAP, &paths::BTREEMAP, &paths::HASHSET, &paths::BTREESET]
104104
.iter()

clippy_lints/src/open_options.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_type, paths, span_lint, walk_ptrs_ty};
1+
use crate::utils::{match_type, paths, span_lint};
22
use rustc_ast::ast::LitKind;
33
use rustc_hir::{Expr, ExprKind};
44
use rustc_lint::{LateContext, LateLintPass};
@@ -30,7 +30,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]);
3030
impl<'tcx> LateLintPass<'tcx> for OpenOptions {
3131
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
3232
if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind {
33-
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&arguments[0]));
33+
let obj_ty = cx.typeck_results().expr_ty(&arguments[0]).peel_refs();
3434
if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) {
3535
let mut options = Vec::new();
3636
get_open_options(cx, &arguments[0], &mut options);
@@ -58,7 +58,7 @@ enum OpenOption {
5858

5959
fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) {
6060
if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind {
61-
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&arguments[0]));
61+
let obj_ty = cx.typeck_results().expr_ty(&arguments[0]).peel_refs();
6262

6363
// Only proceed if this is a call on some object of type std::fs::OpenOptions
6464
if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 2 {

clippy_lints/src/path_buf_push_overwrite.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_type, paths, span_lint_and_sugg, walk_ptrs_ty};
1+
use crate::utils::{match_type, paths, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_ast::ast::LitKind;
44
use rustc_errors::Applicability;
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite {
4646
if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind;
4747
if path.ident.name == sym!(push);
4848
if args.len() == 2;
49-
if match_type(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])), &paths::PATH_BUF);
49+
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::PATH_BUF);
5050
if let Some(get_index_arg) = args.get(1);
5151
if let ExprKind::Lit(ref lit) = get_index_arg.kind;
5252
if let LitKind::Str(ref path_lit, _) = lit.node;

clippy_lints/src/repeat_once.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::consts::{constant_context, Constant};
2-
use crate::utils::{in_macro, is_type_diagnostic_item, snippet, span_lint_and_sugg, walk_ptrs_ty};
2+
use crate::utils::{in_macro, is_type_diagnostic_item, snippet, span_lint_and_sugg};
33
use if_chain::if_chain;
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind};
@@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce {
4444
if let Some(Constant::Int(1)) = constant_context(cx, cx.typeck_results()).expr(&count);
4545
if !in_macro(receiver.span);
4646
then {
47-
let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&receiver));
47+
let ty = cx.typeck_results().expr_ty(&receiver).peel_refs();
4848
if ty.is_str() {
4949
span_lint_and_sugg(
5050
cx,

clippy_lints/src/strings.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::source_map::Spanned;
88
use if_chain::if_chain;
99

1010
use crate::utils::SpanlessEq;
11-
use crate::utils::{get_parent_expr, is_allowed, is_type_diagnostic_item, span_lint, span_lint_and_sugg, walk_ptrs_ty};
11+
use crate::utils::{get_parent_expr, is_allowed, is_type_diagnostic_item, span_lint, span_lint_and_sugg};
1212

1313
declare_clippy_lint! {
1414
/// **What it does:** Checks for string appends of the form `x = x + y` (without
@@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd {
134134
}
135135

136136
fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
137-
is_type_diagnostic_item(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(e)), sym!(string_type))
137+
is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), sym!(string_type))
138138
}
139139

140140
fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool {

0 commit comments

Comments
 (0)