@@ -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
3939declare_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
21442144fn 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
22032203fn 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
25892589fn 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
26172617fn 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 ;
0 commit comments