@@ -10,21 +10,20 @@ use super::SLICED_STRING_AS_BYTES;
10
10
pub ( super ) fn check ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , recv : & Expr < ' _ > ) {
11
11
if let ExprKind :: Index ( indexed, index, _) = recv. kind
12
12
&& is_range_literal ( index)
13
+ && let ty = cx. typeck_results ( ) . expr_ty ( indexed) . peel_refs ( )
14
+ && ( ty. is_str ( ) || is_type_lang_item ( cx, ty, LangItem :: String ) )
13
15
{
14
- let ty = cx. typeck_results ( ) . expr_ty ( indexed) . peel_refs ( ) ;
15
- if ty. is_str ( ) || is_type_lang_item ( cx, ty, LangItem :: String ) {
16
- let mut applicability = Applicability :: MaybeIncorrect ;
17
- let stringish = snippet_with_applicability ( cx, indexed. span , ".." , & mut applicability) ;
18
- let range = snippet_with_applicability ( cx, index. span , ".." , & mut applicability) ;
19
- span_lint_and_sugg (
20
- cx,
21
- SLICED_STRING_AS_BYTES ,
22
- expr. span ,
23
- "calling `as_bytes` after slicing a string" ,
24
- "try" ,
25
- format ! ( "&{stringish}.as_bytes()[{range}]" ) ,
26
- applicability,
27
- ) ;
28
- }
16
+ let mut applicability = Applicability :: MaybeIncorrect ;
17
+ let stringish = snippet_with_applicability ( cx, indexed. span , ".." , & mut applicability) ;
18
+ let range = snippet_with_applicability ( cx, index. span , ".." , & mut applicability) ;
19
+ span_lint_and_sugg (
20
+ cx,
21
+ SLICED_STRING_AS_BYTES ,
22
+ expr. span ,
23
+ "calling `as_bytes` after slicing a string" ,
24
+ "try" ,
25
+ format ! ( "&{stringish}.as_bytes()[{range}]" ) ,
26
+ applicability,
27
+ ) ;
29
28
}
30
29
}
0 commit comments