Access attrs directly from HirId in rustc_passes::dead.
This commit is contained in:
parent
f8514aaa56
commit
a50454d6c8
1 changed files with 9 additions and 23 deletions
|
@ -15,7 +15,6 @@ use rustc_middle::middle::privacy;
|
||||||
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
|
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
|
|
||||||
use rustc_ast as ast;
|
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
|
|
||||||
// Any local node that may call something in its body block should be
|
// Any local node that may call something in its body block should be
|
||||||
|
@ -346,11 +345,8 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_allow_dead_code_or_lang_attr(
|
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
|
||||||
tcx: TyCtxt<'_>,
|
let attrs = tcx.hir().attrs(id);
|
||||||
id: hir::HirId,
|
|
||||||
attrs: &[ast::Attribute],
|
|
||||||
) -> bool {
|
|
||||||
if tcx.sess.contains_name(attrs, sym::lang) {
|
if tcx.sess.contains_name(attrs, sym::lang) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -400,8 +396,7 @@ struct LifeSeeder<'k, 'tcx> {
|
||||||
|
|
||||||
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||||
let allow_dead_code =
|
let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id());
|
||||||
has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id(), &item.attrs);
|
|
||||||
if allow_dead_code {
|
if allow_dead_code {
|
||||||
self.worklist.push(item.hir_id());
|
self.worklist.push(item.hir_id());
|
||||||
}
|
}
|
||||||
|
@ -424,11 +419,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||||
for impl_item_ref in items {
|
for impl_item_ref in items {
|
||||||
let impl_item = self.krate.impl_item(impl_item_ref.id);
|
let impl_item = self.krate.impl_item(impl_item_ref.id);
|
||||||
if of_trait.is_some()
|
if of_trait.is_some()
|
||||||
|| has_allow_dead_code_or_lang_attr(
|
|| has_allow_dead_code_or_lang_attr(self.tcx, impl_item.hir_id())
|
||||||
self.tcx,
|
|
||||||
impl_item.hir_id(),
|
|
||||||
&impl_item.attrs,
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
self.worklist.push(impl_item_ref.id.hir_id());
|
self.worklist.push(impl_item_ref.id.hir_id());
|
||||||
}
|
}
|
||||||
|
@ -446,7 +437,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||||
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
|
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
|
||||||
use hir::TraitItemKind::{Const, Fn};
|
use hir::TraitItemKind::{Const, Fn};
|
||||||
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
|
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
|
||||||
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id(), &trait_item.attrs)
|
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id())
|
||||||
{
|
{
|
||||||
self.worklist.push(trait_item.hir_id());
|
self.worklist.push(trait_item.hir_id());
|
||||||
}
|
}
|
||||||
|
@ -459,11 +450,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||||
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
|
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
|
||||||
use hir::ForeignItemKind::{Fn, Static};
|
use hir::ForeignItemKind::{Fn, Static};
|
||||||
if matches!(foreign_item.kind, Static(..) | Fn(..))
|
if matches!(foreign_item.kind, Static(..) | Fn(..))
|
||||||
&& has_allow_dead_code_or_lang_attr(
|
&& has_allow_dead_code_or_lang_attr(self.tcx, foreign_item.hir_id())
|
||||||
self.tcx,
|
|
||||||
foreign_item.hir_id(),
|
|
||||||
&foreign_item.attrs,
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
self.worklist.push(foreign_item.hir_id());
|
self.worklist.push(foreign_item.hir_id());
|
||||||
}
|
}
|
||||||
|
@ -543,17 +530,16 @@ impl DeadVisitor<'tcx> {
|
||||||
!field.is_positional()
|
!field.is_positional()
|
||||||
&& !self.symbol_is_live(field.hir_id)
|
&& !self.symbol_is_live(field.hir_id)
|
||||||
&& !field_type.is_phantom_data()
|
&& !field_type.is_phantom_data()
|
||||||
&& !has_allow_dead_code_or_lang_attr(self.tcx, field.hir_id, &field.attrs)
|
&& !has_allow_dead_code_or_lang_attr(self.tcx, field.hir_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_warn_about_variant(&mut self, variant: &hir::Variant<'_>) -> bool {
|
fn should_warn_about_variant(&mut self, variant: &hir::Variant<'_>) -> bool {
|
||||||
!self.symbol_is_live(variant.id)
|
!self.symbol_is_live(variant.id) && !has_allow_dead_code_or_lang_attr(self.tcx, variant.id)
|
||||||
&& !has_allow_dead_code_or_lang_attr(self.tcx, variant.id, &variant.attrs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem<'_>) -> bool {
|
fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem<'_>) -> bool {
|
||||||
!self.symbol_is_live(fi.hir_id())
|
!self.symbol_is_live(fi.hir_id())
|
||||||
&& !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id(), &fi.attrs)
|
&& !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
// id := HIR id of an item's definition.
|
// id := HIR id of an item's definition.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue