@@ -32,8 +32,8 @@ use crate::utils::{
32
32
is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, match_qpath,
33
33
match_trait_method, match_type, match_var, method_calls, method_chain_args, paths, remove_blocks, return_ty,
34
34
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 ,
37
37
} ;
38
38
39
39
declare_clippy_lint ! {
@@ -1774,7 +1774,7 @@ fn lint_or_fun_call<'tcx>(
1774
1774
) {
1775
1775
if let hir:: ExprKind :: MethodCall ( ref path, _, ref args, _) = & arg. kind {
1776
1776
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 ( ) ;
1778
1778
1779
1779
match ty. kind ( ) {
1780
1780
ty:: Slice ( _) | ty:: Array ( _, _) => return ,
@@ -1881,7 +1881,7 @@ fn lint_expect_fun_call(
1881
1881
&& ( method_name. ident . name == sym ! ( as_str) || method_name. ident . name == sym ! ( as_ref) )
1882
1882
&& {
1883
1883
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 ( ) ;
1885
1885
* base_type. kind ( ) == ty:: Str || is_type_diagnostic_item ( cx, base_type, sym ! ( string_type) )
1886
1886
}
1887
1887
{
@@ -2142,7 +2142,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
2142
2142
}
2143
2143
2144
2144
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 ( ) ;
2146
2146
2147
2147
if let ty:: Adt ( _, subst) = obj_ty. kind ( ) {
2148
2148
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
2173
2173
let arg = & args[ 1 ] ;
2174
2174
if let Some ( arglists) = method_chain_args ( arg, & [ "chars" ] ) {
2175
2175
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 ( ) ;
2177
2177
let ref_str = if * self_ty. kind ( ) == ty:: Str {
2178
2178
""
2179
2179
} 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
2201
2201
}
2202
2202
2203
2203
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 ( ) ;
2205
2205
if is_type_diagnostic_item ( cx, obj_ty, sym ! ( string_type) ) {
2206
2206
lint_string_extend ( cx, expr, args) ;
2207
2207
}
@@ -2384,7 +2384,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_
2384
2384
}
2385
2385
} else if is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( caller_expr) , sym ! ( vec_type) )
2386
2386
|| matches ! (
2387
- & walk_ptrs_ty ( cx. typeck_results( ) . expr_ty( caller_expr) ) . kind( ) ,
2387
+ & cx. typeck_results( ) . expr_ty( caller_expr) . peel_refs ( ) . kind( ) ,
2388
2388
ty:: Array ( _, _)
2389
2389
)
2390
2390
{
@@ -2587,7 +2587,7 @@ fn derefs_to_slice<'tcx>(
2587
2587
2588
2588
/// lint use of `unwrap()` for `Option`s and `Result`s
2589
2589
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 ( ) ;
2591
2591
2592
2592
let mess = if is_type_diagnostic_item ( cx, obj_ty, sym ! ( option_type) ) {
2593
2593
Some ( ( UNWRAP_USED , "an Option" , "None" ) )
@@ -2615,7 +2615,7 @@ fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::E
2615
2615
2616
2616
/// lint use of `expect()` for `Option`s and `Result`s
2617
2617
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 ( ) ;
2619
2619
2620
2620
let mess = if is_type_diagnostic_item ( cx, obj_ty, sym ! ( option_type) ) {
2621
2621
Some ( ( EXPECT_USED , "an Option" , "None" ) )
@@ -3134,7 +3134,7 @@ fn lint_chars_cmp(
3134
3134
if segment. ident. name == sym!( Some ) ;
3135
3135
then {
3136
3136
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 ( ) ;
3138
3138
3139
3139
if * self_ty. kind( ) != ty:: Str {
3140
3140
return false ;
0 commit comments