@@ -12,34 +12,35 @@ use super::STRING_EXTEND_CHARS;
12
12
13
13
pub ( super ) fn check ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , args : & [ hir:: Expr < ' _ > ] ) {
14
14
let obj_ty = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) . peel_refs ( ) ;
15
- if is_type_diagnostic_item ( cx, obj_ty, sym:: string_type) {
16
- let arg = & args[ 1 ] ;
17
- if let Some ( arglists) = method_chain_args ( arg, & [ "chars" ] ) {
18
- let target = & arglists[ 0 ] [ 0 ] ;
19
- let self_ty = cx. typeck_results ( ) . expr_ty ( target) . peel_refs ( ) ;
20
- let ref_str = if * self_ty. kind ( ) == ty:: Str {
21
- ""
22
- } else if is_type_diagnostic_item ( cx, self_ty, sym:: string_type) {
23
- "&"
24
- } else {
25
- return ;
26
- } ;
15
+ if !is_type_diagnostic_item ( cx, obj_ty, sym:: string_type) {
16
+ return ;
17
+ }
18
+ let arg = & args[ 1 ] ;
19
+ if let Some ( arglists) = method_chain_args ( arg, & [ "chars" ] ) {
20
+ let target = & arglists[ 0 ] [ 0 ] ;
21
+ let self_ty = cx. typeck_results ( ) . expr_ty ( target) . peel_refs ( ) ;
22
+ let ref_str = if * self_ty. kind ( ) == ty:: Str {
23
+ ""
24
+ } else if is_type_diagnostic_item ( cx, self_ty, sym:: string_type) {
25
+ "&"
26
+ } else {
27
+ return ;
28
+ } ;
27
29
28
- let mut applicability = Applicability :: MachineApplicable ;
29
- span_lint_and_sugg (
30
- cx,
31
- STRING_EXTEND_CHARS ,
32
- expr. span ,
33
- "calling `.extend(_.chars())`" ,
34
- "try this" ,
35
- format ! (
36
- "{}.push_str({}{})" ,
37
- snippet_with_applicability( cx, args[ 0 ] . span, ".." , & mut applicability) ,
38
- ref_str,
39
- snippet_with_applicability( cx, target. span, ".." , & mut applicability)
40
- ) ,
41
- applicability,
42
- ) ;
43
- }
30
+ let mut applicability = Applicability :: MachineApplicable ;
31
+ span_lint_and_sugg (
32
+ cx,
33
+ STRING_EXTEND_CHARS ,
34
+ expr. span ,
35
+ "calling `.extend(_.chars())`" ,
36
+ "try this" ,
37
+ format ! (
38
+ "{}.push_str({}{})" ,
39
+ snippet_with_applicability( cx, args[ 0 ] . span, ".." , & mut applicability) ,
40
+ ref_str,
41
+ snippet_with_applicability( cx, target. span, ".." , & mut applicability)
42
+ ) ,
43
+ applicability,
44
+ ) ;
44
45
}
45
46
}
0 commit comments