File tree 3 files changed +16
-5
lines changed
3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd {
190
190
}
191
191
} ,
192
192
ExprKind :: Index ( target, _idx, _) => {
193
- let e_ty = cx. typeck_results ( ) . expr_ty ( target) . peel_refs ( ) ;
193
+ let e_ty = cx. typeck_results ( ) . expr_ty_adjusted ( target) . peel_refs ( ) ;
194
194
if e_ty. is_str ( ) || is_type_lang_item ( cx, e_ty, LangItem :: String ) {
195
195
span_lint (
196
196
cx,
Original file line number Diff line number Diff line change
1
+ use std:: borrow:: Cow ;
2
+
1
3
#[ warn( clippy:: string_slice) ]
2
4
#[ allow( clippy:: no_effect) ]
3
5
@@ -11,4 +13,7 @@ fn main() {
11
13
let s = String :: from ( m) ;
12
14
& s[ 0 ..2 ] ;
13
15
//~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character
16
+ let a = Cow :: Borrowed ( "foo" ) ;
17
+ & a[ 0 ..3 ] ;
18
+ //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character
14
19
}
Original file line number Diff line number Diff line change 1
1
error: indexing into a string may panic if the index is within a UTF-8 character
2
- --> tests/ui/string_slice.rs:5 :6
2
+ --> tests/ui/string_slice.rs:7 :6
3
3
|
4
4
LL | &"Ölkanne"[1..];
5
5
| ^^^^^^^^^^^^^^
@@ -8,16 +8,22 @@ LL | &"Ölkanne"[1..];
8
8
= help: to override `-D warnings` add `#[allow(clippy::string_slice)]`
9
9
10
10
error: indexing into a string may panic if the index is within a UTF-8 character
11
- --> tests/ui/string_slice.rs:9 :6
11
+ --> tests/ui/string_slice.rs:11 :6
12
12
|
13
13
LL | &m[2..5];
14
14
| ^^^^^^^
15
15
16
16
error: indexing into a string may panic if the index is within a UTF-8 character
17
- --> tests/ui/string_slice.rs:12 :6
17
+ --> tests/ui/string_slice.rs:14 :6
18
18
|
19
19
LL | &s[0..2];
20
20
| ^^^^^^^
21
21
22
- error: aborting due to 3 previous errors
22
+ error: indexing into a string may panic if the index is within a UTF-8 character
23
+ --> tests/ui/string_slice.rs:17:6
24
+ |
25
+ LL | &a[0..3];
26
+ | ^^^^^^^
27
+
28
+ error: aborting due to 4 previous errors
23
29
You can’t perform that action at this time.
0 commit comments