@@ -101,21 +101,25 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
101
101
return ControlFlow :: Continue ( ( ) ) ;
102
102
}
103
103
104
- // Method call on `id` in a statement ignores any return value, so it's not a read access:
104
+ // Look for method call with receiver `id`. It might be a non- read access:
105
105
//
106
- // id.foo(...); // Not reading `id`.
106
+ // id.foo(args)
107
107
//
108
108
// Only assuming this for "official" methods defined on the type. For methods defined in extension
109
109
// traits (identified as local, based on the orphan rule), pessimistically assume that they might
110
110
// have side effects, so consider them a read.
111
111
if let Some ( Node :: Expr ( parent) ) = get_parent_node ( cx. tcx , expr. hir_id )
112
112
&& let ExprKind :: MethodCall ( _, receiver, _, _) = parent. kind
113
113
&& path_to_local_id ( receiver, id)
114
- && let Some ( Node :: Stmt ( ..) ) = get_parent_node ( cx. tcx , parent. hir_id )
115
114
&& let Some ( method_def_id) = cx. typeck_results ( ) . type_dependent_def_id ( parent. hir_id )
116
115
&& !method_def_id. is_local ( )
117
116
{
118
- return ControlFlow :: Continue ( ( ) ) ;
117
+ // The method call is a statement, so the return value is not used. That's not a read access:
118
+ //
119
+ // id.foo(args);
120
+ if let Some ( Node :: Stmt ( ..) ) = get_parent_node ( cx. tcx , parent. hir_id ) {
121
+ return ControlFlow :: Continue ( ( ) ) ;
122
+ }
119
123
}
120
124
121
125
// Any other access to `id` is a read access. Stop searching.
0 commit comments