1
Fork 0

Reduce use of local_def_id_to_hir_id.

This commit is contained in:
Camille GILLOT 2021-10-20 20:59:15 +02:00
parent ebcc847369
commit 67727aa7c3
39 changed files with 182 additions and 237 deletions

View file

@ -23,7 +23,7 @@ use std::mem;
// may need to be marked as live.
fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
matches!(
tcx.hir().find(tcx.hir().local_def_id_to_hir_id(def_id)),
tcx.hir().find_by_def_id(def_id),
Some(
Node::Item(..)
| Node::ImplItem(..)
@ -232,7 +232,7 @@ 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.hir().find(self.tcx.hir().local_def_id_to_hir_id(id)) {
if let Some(node) = self.tcx.hir().find_by_def_id(id) {
self.live_symbols.insert(id);
self.visit_node(node);
}

View file

@ -152,11 +152,10 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De
if let Some(def_id) = main_def.opt_fn_def_id() {
// non-local main imports are handled below
if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
if matches!(tcx.hir().find(hir_id), Some(Node::ForeignItem(_))) {
if matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) {
tcx.sess
.struct_span_err(
tcx.hir().span(hir_id),
tcx.def_span(def_id),
"the `main` function cannot be declared in an `extern` block",
)
.emit();

View file

@ -6,6 +6,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(crate_visibility_modifier)]
#![feature(let_else)]
#![feature(map_try_insert)]
#![feature(min_specialization)]
#![feature(nll)]

View file

@ -52,7 +52,7 @@ fn method_might_be_inlined(
return true;
}
}
match tcx.hir().find(tcx.hir().local_def_id_to_hir_id(impl_src)) {
match tcx.hir().find_by_def_id(impl_src) {
Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs),
Some(..) | None => span_bug!(impl_item.span, "impl did is not an item"),
}
@ -140,14 +140,11 @@ impl<'tcx> ReachableContext<'tcx> {
// Returns true if the given def ID represents a local item that is
// eligible for inlining and false otherwise.
fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool {
let hir_id = match def_id.as_local() {
Some(def_id) => self.tcx.hir().local_def_id_to_hir_id(def_id),
None => {
return false;
}
let Some(def_id) = def_id.as_local() else {
return false;
};
match self.tcx.hir().find(hir_id) {
match self.tcx.hir().find_by_def_id(def_id) {
Some(Node::Item(item)) => match item.kind {
hir::ItemKind::Fn(..) => {
item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id))
@ -169,6 +166,7 @@ impl<'tcx> ReachableContext<'tcx> {
if generics.requires_monomorphization(self.tcx) || attrs.requests_inline() {
true
} else {
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let impl_did = self.tcx.hir().get_parent_item(hir_id);
// Check the impl. If the generics on the self
// type of the impl require inlining, this method
@ -198,9 +196,7 @@ impl<'tcx> ReachableContext<'tcx> {
continue;
}
if let Some(ref item) =
self.tcx.hir().find(self.tcx.hir().local_def_id_to_hir_id(search_item))
{
if let Some(ref item) = self.tcx.hir().find_by_def_id(search_item) {
self.propagate_node(item, search_item);
}
}