This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Expand file tree Collapse file tree 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 {
190190 }
191191 } ,
192192 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 ( ) ;
194194 if e_ty. is_str ( ) || is_type_lang_item ( cx, e_ty, LangItem :: String ) {
195195 span_lint (
196196 cx,
Original file line number Diff line number Diff line change 1+ use std:: borrow:: Cow ;
2+
13#[ warn( clippy:: string_slice) ]
24#[ allow( clippy:: no_effect) ]
35
@@ -11,4 +13,7 @@ fn main() {
1113 let s = String :: from ( m) ;
1214 & s[ 0 ..2 ] ;
1315 //~^ 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
1419}
Original file line number Diff line number Diff line change 11error: 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
33 |
44LL | &"Ölkanne"[1..];
55 | ^^^^^^^^^^^^^^
@@ -8,16 +8,22 @@ LL | &"Ölkanne"[1..];
88 = help: to override `-D warnings` add `#[allow(clippy::string_slice)]`
99
1010error: 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
1212 |
1313LL | &m[2..5];
1414 | ^^^^^^^
1515
1616error: 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
1818 |
1919LL | &s[0..2];
2020 | ^^^^^^^
2121
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
2329
You can’t perform that action at this time.
0 commit comments