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