Skip to content

Commit 04687b5

Browse files
committed
Refactor
1 parent f19db28 commit 04687b5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

clippy_lints/src/collection_is_never_read.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,25 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
9595
return ControlFlow::Continue(());
9696
}
9797

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:
9999
//
100-
// id.foo(...); // Not reading `id`.
100+
// id.foo(args)
101101
//
102102
// Only assuming this for "official" methods defined on the type. For methods defined in extension
103103
// traits (identified as local, based on the orphan rule), pessimistically assume that they might
104104
// have side effects, so consider them a read.
105105
if let Some(Node::Expr(parent)) = get_parent_node(cx.tcx, expr.hir_id)
106106
&& let ExprKind::MethodCall(_, receiver, _, _) = parent.kind
107107
&& path_to_local_id(receiver, id)
108-
&& let Some(Node::Stmt(..)) = get_parent_node(cx.tcx, parent.hir_id)
109108
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
110109
&& !method_def_id.is_local()
111110
{
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+
}
113117
}
114118

115119
// Any other access to `id` is a read access. Stop searching.

0 commit comments

Comments
 (0)