hir: Remove opt_local_def_id_to_hir_id
and opt_hir_node_by_def_id
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
This commit is contained in:
parent
30f74ff0dc
commit
89b536dbc8
37 changed files with 135 additions and 199 deletions
|
@ -33,15 +33,13 @@ use crate::errors::{
|
|||
// may need to be marked as live.
|
||||
fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
matches!(
|
||||
tcx.opt_hir_node_by_def_id(def_id),
|
||||
Some(
|
||||
Node::Item(..)
|
||||
| Node::ImplItem(..)
|
||||
| Node::ForeignItem(..)
|
||||
| Node::TraitItem(..)
|
||||
| Node::Variant(..)
|
||||
| Node::AnonConst(..)
|
||||
)
|
||||
tcx.hir_node_by_def_id(def_id),
|
||||
Node::Item(..)
|
||||
| Node::ImplItem(..)
|
||||
| Node::ForeignItem(..)
|
||||
| Node::TraitItem(..)
|
||||
| Node::Variant(..)
|
||||
| Node::AnonConst(..)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -316,33 +314,31 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
// tuple struct constructor function
|
||||
let id = self.struct_constructors.get(&id).copied().unwrap_or(id);
|
||||
|
||||
if let Some(node) = self.tcx.opt_hir_node_by_def_id(id) {
|
||||
// When using `#[allow]` or `#[expect]` of `dead_code`, we do a QOL improvement
|
||||
// by declaring fn calls, statics, ... within said items as live, as well as
|
||||
// the item itself, although technically this is not the case.
|
||||
//
|
||||
// This means that the lint for said items will never be fired.
|
||||
//
|
||||
// This doesn't make any difference for the item declared with `#[allow]`, as
|
||||
// the lint firing will be a nop, as it will be silenced by the `#[allow]` of
|
||||
// the item.
|
||||
//
|
||||
// However, for `#[expect]`, the presence or absence of the lint is relevant,
|
||||
// so we don't add it to the list of live symbols when it comes from a
|
||||
// `#[expect]`. This means that we will correctly report an item as live or not
|
||||
// for the `#[expect]` case.
|
||||
//
|
||||
// Note that an item can and will be duplicated on the worklist with different
|
||||
// `ComesFromAllowExpect`, particularly if it was added from the
|
||||
// `effective_visibilities` query or from the `#[allow]`/`#[expect]` checks,
|
||||
// this "duplication" is essential as otherwise a function with `#[expect]`
|
||||
// called from a `pub fn` may be falsely reported as not live, falsely
|
||||
// triggering the `unfulfilled_lint_expectations` lint.
|
||||
if comes_from_allow_expect != ComesFromAllowExpect::Yes {
|
||||
self.live_symbols.insert(id);
|
||||
}
|
||||
self.visit_node(node);
|
||||
// When using `#[allow]` or `#[expect]` of `dead_code`, we do a QOL improvement
|
||||
// by declaring fn calls, statics, ... within said items as live, as well as
|
||||
// the item itself, although technically this is not the case.
|
||||
//
|
||||
// This means that the lint for said items will never be fired.
|
||||
//
|
||||
// This doesn't make any difference for the item declared with `#[allow]`, as
|
||||
// the lint firing will be a nop, as it will be silenced by the `#[allow]` of
|
||||
// the item.
|
||||
//
|
||||
// However, for `#[expect]`, the presence or absence of the lint is relevant,
|
||||
// so we don't add it to the list of live symbols when it comes from a
|
||||
// `#[expect]`. This means that we will correctly report an item as live or not
|
||||
// for the `#[expect]` case.
|
||||
//
|
||||
// Note that an item can and will be duplicated on the worklist with different
|
||||
// `ComesFromAllowExpect`, particularly if it was added from the
|
||||
// `effective_visibilities` query or from the `#[allow]`/`#[expect]` checks,
|
||||
// this "duplication" is essential as otherwise a function with `#[expect]`
|
||||
// called from a `pub fn` may be falsely reported as not live, falsely
|
||||
// triggering the `unfulfilled_lint_expectations` lint.
|
||||
if comes_from_allow_expect != ComesFromAllowExpect::Yes {
|
||||
self.live_symbols.insert(id);
|
||||
}
|
||||
self.visit_node(self.tcx.hir_node_by_def_id(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -739,8 +735,8 @@ fn check_item<'tcx>(
|
|||
for local_def_id in local_def_ids {
|
||||
// check the function may construct Self
|
||||
let mut may_construct_self = true;
|
||||
if let Some(hir_id) = tcx.opt_local_def_id_to_hir_id(local_def_id)
|
||||
&& let Some(fn_sig) = tcx.hir().fn_sig_by_hir_id(hir_id)
|
||||
if let Some(fn_sig) =
|
||||
tcx.hir().fn_sig_by_hir_id(tcx.local_def_id_to_hir_id(local_def_id))
|
||||
{
|
||||
may_construct_self =
|
||||
matches!(fn_sig.decl.implicit_self, hir::ImplicitSelfKind::None);
|
||||
|
|
|
@ -127,7 +127,7 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
|
|||
{
|
||||
// non-local main imports are handled below
|
||||
if let Some(def_id) = def_id.as_local()
|
||||
&& matches!(tcx.opt_hir_node_by_def_id(def_id), Some(Node::ForeignItem(_)))
|
||||
&& matches!(tcx.hir_node_by_def_id(def_id), Node::ForeignItem(_))
|
||||
{
|
||||
tcx.dcx().emit_err(ExternMain { span: tcx.def_span(def_id) });
|
||||
return None;
|
||||
|
|
|
@ -116,26 +116,25 @@ impl<'tcx> ReachableContext<'tcx> {
|
|||
return false;
|
||||
};
|
||||
|
||||
match self.tcx.opt_hir_node_by_def_id(def_id) {
|
||||
Some(Node::Item(item)) => match item.kind {
|
||||
match self.tcx.hir_node_by_def_id(def_id) {
|
||||
Node::Item(item) => match item.kind {
|
||||
hir::ItemKind::Fn(..) => item_might_be_inlined(self.tcx, def_id.into()),
|
||||
_ => false,
|
||||
},
|
||||
Some(Node::TraitItem(trait_method)) => match trait_method.kind {
|
||||
Node::TraitItem(trait_method) => match trait_method.kind {
|
||||
hir::TraitItemKind::Const(_, ref default) => default.is_some(),
|
||||
hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => true,
|
||||
hir::TraitItemKind::Fn(_, hir::TraitFn::Required(_))
|
||||
| hir::TraitItemKind::Type(..) => false,
|
||||
},
|
||||
Some(Node::ImplItem(impl_item)) => match impl_item.kind {
|
||||
Node::ImplItem(impl_item) => match impl_item.kind {
|
||||
hir::ImplItemKind::Const(..) => true,
|
||||
hir::ImplItemKind::Fn(..) => {
|
||||
item_might_be_inlined(self.tcx, impl_item.hir_id().owner.to_def_id())
|
||||
}
|
||||
hir::ImplItemKind::Type(_) => false,
|
||||
},
|
||||
Some(_) => false,
|
||||
None => false, // This will happen for default methods.
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,9 +146,7 @@ impl<'tcx> ReachableContext<'tcx> {
|
|||
continue;
|
||||
}
|
||||
|
||||
if let Some(ref item) = self.tcx.opt_hir_node_by_def_id(search_item) {
|
||||
self.propagate_node(item, search_item);
|
||||
}
|
||||
self.propagate_node(&self.tcx.hir_node_by_def_id(search_item), search_item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue