Skip to content

Commit a50454d

Browse files
committed
Access attrs directly from HirId in rustc_passes::dead.
1 parent f8514aa commit a50454d

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

compiler/rustc_passes/src/dead.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_middle::middle::privacy;
1515
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
1616
use rustc_session::lint;
1717

18-
use rustc_ast as ast;
1918
use rustc_span::symbol::{sym, Symbol};
2019

2120
// Any local node that may call something in its body block should be
@@ -346,11 +345,8 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
346345
}
347346
}
348347

349-
fn has_allow_dead_code_or_lang_attr(
350-
tcx: TyCtxt<'_>,
351-
id: hir::HirId,
352-
attrs: &[ast::Attribute],
353-
) -> bool {
348+
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
349+
let attrs = tcx.hir().attrs(id);
354350
if tcx.sess.contains_name(attrs, sym::lang) {
355351
return true;
356352
}
@@ -400,8 +396,7 @@ struct LifeSeeder<'k, 'tcx> {
400396

401397
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
402398
fn visit_item(&mut self, item: &hir::Item<'_>) {
403-
let allow_dead_code =
404-
has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id(), &item.attrs);
399+
let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id());
405400
if allow_dead_code {
406401
self.worklist.push(item.hir_id());
407402
}
@@ -424,11 +419,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
424419
for impl_item_ref in items {
425420
let impl_item = self.krate.impl_item(impl_item_ref.id);
426421
if of_trait.is_some()
427-
|| has_allow_dead_code_or_lang_attr(
428-
self.tcx,
429-
impl_item.hir_id(),
430-
&impl_item.attrs,
431-
)
422+
|| has_allow_dead_code_or_lang_attr(self.tcx, impl_item.hir_id())
432423
{
433424
self.worklist.push(impl_item_ref.id.hir_id());
434425
}
@@ -446,7 +437,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
446437
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
447438
use hir::TraitItemKind::{Const, Fn};
448439
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
449-
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id(), &trait_item.attrs)
440+
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id())
450441
{
451442
self.worklist.push(trait_item.hir_id());
452443
}
@@ -459,11 +450,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
459450
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
460451
use hir::ForeignItemKind::{Fn, Static};
461452
if matches!(foreign_item.kind, Static(..) | Fn(..))
462-
&& has_allow_dead_code_or_lang_attr(
463-
self.tcx,
464-
foreign_item.hir_id(),
465-
&foreign_item.attrs,
466-
)
453+
&& has_allow_dead_code_or_lang_attr(self.tcx, foreign_item.hir_id())
467454
{
468455
self.worklist.push(foreign_item.hir_id());
469456
}
@@ -543,17 +530,16 @@ impl DeadVisitor<'tcx> {
543530
!field.is_positional()
544531
&& !self.symbol_is_live(field.hir_id)
545532
&& !field_type.is_phantom_data()
546-
&& !has_allow_dead_code_or_lang_attr(self.tcx, field.hir_id, &field.attrs)
533+
&& !has_allow_dead_code_or_lang_attr(self.tcx, field.hir_id)
547534
}
548535

549536
fn should_warn_about_variant(&mut self, variant: &hir::Variant<'_>) -> bool {
550-
!self.symbol_is_live(variant.id)
551-
&& !has_allow_dead_code_or_lang_attr(self.tcx, variant.id, &variant.attrs)
537+
!self.symbol_is_live(variant.id) && !has_allow_dead_code_or_lang_attr(self.tcx, variant.id)
552538
}
553539

554540
fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem<'_>) -> bool {
555541
!self.symbol_is_live(fi.hir_id())
556-
&& !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id(), &fi.attrs)
542+
&& !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id())
557543
}
558544

559545
// id := HIR id of an item's definition.

0 commit comments

Comments
 (0)