Skip to content

Commit 8ea87bd

Browse files
committed
simplyfiy local_def_id_to_hir_id
1 parent b976ad0 commit 8ea87bd

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

compiler/rustc_hir/src/hir_id.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ impl HirOwner {
1616
pub fn to_def_id(&self) -> DefId {
1717
self.def_id.to_def_id()
1818
}
19+
20+
pub fn to_hir_id(self) -> HirId {
21+
HirId { owner: self, local_id: ItemLocalId::from_u32(0) }
22+
}
1923
}
2024

2125
impl rustc_index::vec::Idx for HirOwner {

compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl DirtyCleanVisitor<'tcx> {
239239
/// Return all DepNode labels that should be asserted for this item.
240240
/// index=0 is the "name" used for error messages
241241
fn auto_labels(&mut self, item_id: HirOwner, attr: &Attribute) -> (&'static str, Labels) {
242-
let hir_id = self.tcx.hir().local_def_id_to_hir_id(item_id.def_id);
242+
let hir_id = item_id.to_hir_id();
243243
let node = self.tcx.hir().get(hir_id);
244244
let (name, labels) = match node {
245245
HirNode::Item(item) => {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20522052
.in_progress_typeck_results
20532053
.map(|typeck_results| typeck_results.borrow().hir_owner)
20542054
.map(|owner| {
2055-
let hir_id = hir.local_def_id_to_hir_id(owner.def_id);
2055+
let hir_id = owner.to_hir_id();
20562056
let parent_id = hir.get_parent_item(hir_id);
20572057
(
20582058
// Parent item could be a `mod`, so we check the HIR before calling:

compiler/rustc_passes/src/diagnostic_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'tcx> DiagnosticItemCollector<'tcx> {
5050
}
5151

5252
fn observe_item(&mut self, def_id: HirOwner) {
53-
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.def_id);
53+
let hir_id = def_id.to_hir_id();
5454
let attrs = self.tcx.hir().attrs(hir_id);
5555
if let Some(name) = extract(&self.tcx.sess, attrs) {
5656
// insert into our table

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ fn convert_named_region_map(named_region_map: NamedRegionMap) -> ResolveLifetime
502502
fn resolve_lifetimes_for<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ResolveLifetimes {
503503
let item_id = item_for(tcx, def_id);
504504
if item_id == def_id {
505-
let item = tcx.hir().item(hir::ItemId { def_id: HirOwner { def_id: item_id } });
505+
let item = tcx.hir().item(hir::ItemId { def_id: HirOwner { def_id } });
506506
match item.kind {
507507
hir::ItemKind::Trait(..) => tcx.resolve_lifetimes_trait_definition(item_id),
508508
_ => tcx.resolve_lifetimes(item_id),
@@ -760,11 +760,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
760760
// their owner, we can keep going until we find the Item that owns that. We then
761761
// conservatively add all resolved lifetimes. Otherwise we run into problems in
762762
// cases like `type Foo<'a> = impl Bar<As = impl Baz + 'a>`.
763-
for (_hir_id, node) in self
764-
.tcx
765-
.hir()
766-
.parent_iter(self.tcx.hir().local_def_id_to_hir_id(item.def_id.def_id))
767-
{
763+
for (_hir_id, node) in self.tcx.hir().parent_iter(item.def_id.to_hir_id()) {
768764
match node {
769765
hir::Node::Item(parent_item) => {
770766
let resolved_lifetimes: &ResolveLifetimes = self

0 commit comments

Comments
 (0)