diff options
| author | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2021-10-02 09:53:51 -0400 |
|---|---|---|
| committer | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2021-10-02 09:53:51 -0400 |
| commit | bec5a91450d58a821c8a41a93dd2563fc7eb4606 (patch) | |
| tree | 320117c8e81bd82f34409958b6b433fa8b0bfc9d | |
| parent | eb4ba58572bfaec9a9ca843b368e05564d9b1cb0 (diff) | |
| download | rust-bec5a91450d58a821c8a41a93dd2563fc7eb4606.tar.gz rust-bec5a91450d58a821c8a41a93dd2563fc7eb4606.zip | |
only check for automatically_derived on impls, not individual methods
this matches behavior of existing code https://github.com/rust-lang/rust/blob/b27661eb33c74cb514dba059b47d86b6582ac1c2/compiler/rustc_passes/src/liveness.rs#L326-L333
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index c6f34aad978..77279132401 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -243,27 +243,16 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { /// will be ignored for the purposes of dead code analysis (see PR #85200 /// for discussion). fn should_ignore_item(&self, def_id: DefId) -> bool { - if !self.tcx.has_attr(def_id, sym::automatically_derived) - && !self - .tcx - .impl_of_method(def_id) - .map_or(false, |impl_id| self.tcx.has_attr(impl_id, sym::automatically_derived)) - { - return false; - } - - let has_attr = |def_id| self.tcx.has_attr(def_id, sym::rustc_trivial_field_reads); - if let Some(impl_of) = self.tcx.impl_of_method(def_id) { + if !self.tcx.has_attr(impl_of, sym::automatically_derived) { + return false; + } + if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) { - if has_attr(trait_of) { + if self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) { return true; } } - } else if let Some(trait_of) = self.tcx.trait_of_item(def_id) { - if has_attr(trait_of) { - return true; - } } return false; @@ -271,8 +260,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { fn visit_node(&mut self, node: Node<'tcx>) { if let Some(item_def_id) = match node { - Node::TraitItem(hir::TraitItem { def_id, .. }) - | Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()), + Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()), _ => None, } { if self.should_ignore_item(item_def_id) { |
