Skip to content

Commit bec5a91

Browse files
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
1 parent eb4ba58 commit bec5a91

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

compiler/rustc_passes/src/dead.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -243,36 +243,24 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
243243
/// will be ignored for the purposes of dead code analysis (see PR #85200
244244
/// for discussion).
245245
fn should_ignore_item(&self, def_id: DefId) -> bool {
246-
if !self.tcx.has_attr(def_id, sym::automatically_derived)
247-
&& !self
248-
.tcx
249-
.impl_of_method(def_id)
250-
.map_or(false, |impl_id| self.tcx.has_attr(impl_id, sym::automatically_derived))
251-
{
252-
return false;
253-
}
254-
255-
let has_attr = |def_id| self.tcx.has_attr(def_id, sym::rustc_trivial_field_reads);
256-
257246
if let Some(impl_of) = self.tcx.impl_of_method(def_id) {
247+
if !self.tcx.has_attr(impl_of, sym::automatically_derived) {
248+
return false;
249+
}
250+
258251
if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) {
259-
if has_attr(trait_of) {
252+
if self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) {
260253
return true;
261254
}
262255
}
263-
} else if let Some(trait_of) = self.tcx.trait_of_item(def_id) {
264-
if has_attr(trait_of) {
265-
return true;
266-
}
267256
}
268257

269258
return false;
270259
}
271260

272261
fn visit_node(&mut self, node: Node<'tcx>) {
273262
if let Some(item_def_id) = match node {
274-
Node::TraitItem(hir::TraitItem { def_id, .. })
275-
| Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()),
263+
Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()),
276264
_ => None,
277265
} {
278266
if self.should_ignore_item(item_def_id) {

0 commit comments

Comments
 (0)