diff options
| author | Michael Schubart <michael@schubart.net> | 2023-03-12 14:45:22 +0000 |
|---|---|---|
| committer | Michael Schubart <michael@schubart.net> | 2023-04-11 10:27:32 +0900 |
| commit | 63030acf4ff453da2beb7f43b13cca8fb6cf425a (patch) | |
| tree | ebe6c50d209743140291ef99fdb282701c780779 | |
| parent | 5ec2e192f58aa4fc82e3b4551e16e0f83d368569 (diff) | |
| download | rust-63030acf4ff453da2beb7f43b13cca8fb6cf425a.tar.gz rust-63030acf4ff453da2beb7f43b13cca8fb6cf425a.zip | |
Refactor
| -rw-r--r-- | clippy_lints/src/collection_is_never_read.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/clippy_lints/src/collection_is_never_read.rs b/clippy_lints/src/collection_is_never_read.rs index 15a5b7dd274..a5feffa3106 100644 --- a/clippy_lints/src/collection_is_never_read.rs +++ b/clippy_lints/src/collection_is_never_read.rs @@ -101,9 +101,9 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc return ControlFlow::Continue(()); } - // Method call on `id` in a statement ignores any return value, so it's not a read access: + // Look for method call with receiver `id`. It might be a non-read access: // - // id.foo(...); // Not reading `id`. + // id.foo(args) // // Only assuming this for "official" methods defined on the type. For methods defined in extension // traits (identified as local, based on the orphan rule), pessimistically assume that they might @@ -111,11 +111,15 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc if let Some(Node::Expr(parent)) = get_parent_node(cx.tcx, expr.hir_id) && let ExprKind::MethodCall(_, receiver, _, _) = parent.kind && path_to_local_id(receiver, id) - && let Some(Node::Stmt(..)) = get_parent_node(cx.tcx, parent.hir_id) && let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && !method_def_id.is_local() { - return ControlFlow::Continue(()); + // The method call is a statement, so the return value is not used. That's not a read access: + // + // id.foo(args); + if let Some(Node::Stmt(..)) = get_parent_node(cx.tcx, parent.hir_id) { + return ControlFlow::Continue(()); + } } // Any other access to `id` is a read access. Stop searching. |
