@@ -84,6 +84,9 @@ fn check_index_usage<'tcx>(
84
84
let is_string_like = |ty : Ty < ' _ > | ty. is_str ( ) || is_type_lang_item ( cx, ty, LangItem :: String ) ;
85
85
let message = match parent_expr. kind {
86
86
ExprKind :: MethodCall ( segment, recv, ..)
87
+ // We currently only lint `str` methods (which `String` can deref to), so a `.is_str()` check is sufficient here
88
+ // (contrary to the `ExprKind::Index` case which needs to handle both with `is_string_like` because `String` implements
89
+ // `Index` directly and no deref to `str` would happen in that case).
87
90
if cx. typeck_results ( ) . expr_ty_adjusted ( recv) . peel_refs ( ) . is_str ( )
88
91
&& BYTE_INDEX_METHODS . contains ( & segment. ident . name . as_str ( ) )
89
92
&& eq_expr_value ( cx, chars_recv, recv) =>
@@ -126,7 +129,7 @@ fn check_index_usage<'tcx>(
126
129
/// but for `.get(..idx)` we want to consider the method call the consuming expression,
127
130
/// which requires skipping past the range expression.
128
131
fn index_consumed_at < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) -> Option < & ' tcx Expr < ' tcx > > {
129
- for ( _, node) in cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) {
132
+ for ( _, node) in cx. tcx . hir_parent_iter ( expr. hir_id ) {
130
133
match node {
131
134
Node :: Expr ( expr) if higher:: Range :: hir ( expr) . is_some ( ) => { } ,
132
135
Node :: ExprField ( _) => { } ,
0 commit comments