Skip to content

Commit 0d47312

Browse files
authored
Rollup merge of #71215 - marmeladema:issue70853/librustc_middle-local-def-id-2, r=eddyb
Simplify `local_def_id` and `as_local_hir_id`
2 parents d3b0480 + da9c867 commit 0d47312

File tree

118 files changed

+1091
-986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1091
-986
lines changed

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
116116
if cx.tcx.sess.opts.share_generics() {
117117
// We are in share_generics mode.
118118

119-
if instance_def_id.is_local() {
119+
if let Some(instance_def_id) = instance_def_id.as_local() {
120120
// This is a definition from the current crate. If the
121121
// definition is unreachable for downstream crates or
122122
// the current crate does not re-export generics, the

src/librustc_codegen_llvm/consts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ impl CodegenCx<'ll, 'tcx> {
209209

210210
debug!("get_static: sym={} instance={:?}", sym, instance);
211211

212-
let g = if let Some(id) = self.tcx.hir().as_local_hir_id(def_id) {
212+
let g = if let Some(def_id) = def_id.as_local() {
213+
let id = self.tcx.hir().as_local_hir_id(def_id);
213214
let llty = self.layout_of(ty).llvm_type(self);
214215
let (g, attrs) = match self.tcx.hir().get(id) {
215216
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn reachable_non_generics_provider(
9494
if !generics.requires_monomorphization(tcx) &&
9595
// Functions marked with #[inline] are only ever codegened
9696
// with "internal" linkage and are never exported.
97-
!Instance::mono(tcx, def_id).def.generates_cgu_internal_copy(tcx)
97+
!Instance::mono(tcx, def_id.to_def_id()).def.generates_cgu_internal_copy(tcx)
9898
{
9999
Some(def_id)
100100
} else {
@@ -107,7 +107,7 @@ fn reachable_non_generics_provider(
107107
})
108108
.map(|def_id| {
109109
let export_level = if special_runtime_crate {
110-
let name = tcx.symbol_name(Instance::mono(tcx, def_id)).name.as_str();
110+
let name = tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())).name.as_str();
111111
// We can probably do better here by just ensuring that
112112
// it has hidden visibility rather than public
113113
// visibility, as this is primarily here to ensure it's
@@ -124,14 +124,14 @@ fn reachable_non_generics_provider(
124124
SymbolExportLevel::Rust
125125
}
126126
} else {
127-
symbol_export_level(tcx, def_id)
127+
symbol_export_level(tcx, def_id.to_def_id())
128128
};
129129
debug!(
130130
"EXPORTED SYMBOL (local): {} ({:?})",
131-
tcx.symbol_name(Instance::mono(tcx, def_id)),
131+
tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())),
132132
export_level
133133
);
134-
(def_id, export_level)
134+
(def_id.to_def_id(), export_level)
135135
})
136136
.collect();
137137

@@ -359,8 +359,8 @@ fn upstream_drop_glue_for_provider<'tcx>(
359359
}
360360

361361
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
362-
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
363-
!tcx.reachable_set(LOCAL_CRATE).contains(&hir_id)
362+
if let Some(def_id) = def_id.as_local() {
363+
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id))
364364
} else {
365365
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
366366
}

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
322322
}
323323

324324
fn node_path(&self, id: hir::HirId) -> Option<String> {
325-
Some(self.tcx.def_path_str(self.tcx.hir().local_def_id(id)))
325+
Some(self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()))
326326
}
327327
}
328328

src/librustc_hir/definitions.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,8 @@ impl Definitions {
342342
}
343343

344344
#[inline]
345-
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<hir::HirId> {
346-
if let Some(def_id) = def_id.as_local() {
347-
Some(self.local_def_id_to_hir_id(def_id))
348-
} else {
349-
None
350-
}
345+
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId {
346+
self.local_def_id_to_hir_id(def_id)
351347
}
352348

353349
#[inline]

src/librustc_incremental/assert_dep_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl IfThisChanged<'tcx> {
115115

116116
fn process_attrs(&mut self, hir_id: hir::HirId, attrs: &[ast::Attribute]) {
117117
let def_id = self.tcx.hir().local_def_id(hir_id);
118-
let def_path_hash = self.tcx.def_path_hash(def_id);
118+
let def_path_hash = self.tcx.def_path_hash(def_id.to_def_id());
119119
for attr in attrs {
120120
if attr.check_name(sym::rustc_if_this_changed) {
121121
let dep_node_interned = self.argument(attr);
@@ -131,7 +131,7 @@ impl IfThisChanged<'tcx> {
131131
}
132132
},
133133
};
134-
self.if_this_changed.push((attr.span, def_id, dep_node));
134+
self.if_this_changed.push((attr.span, def_id.to_def_id(), dep_node));
135135
} else if attr.check_name(sym::rustc_then_this_would_need) {
136136
let dep_node_interned = self.argument(attr);
137137
let dep_node = match dep_node_interned {

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,16 @@ impl DirtyCleanVisitor<'tcx> {
434434

435435
fn check_item(&mut self, item_id: hir::HirId, item_span: Span) {
436436
let def_id = self.tcx.hir().local_def_id(item_id);
437-
for attr in self.tcx.get_attrs(def_id).iter() {
437+
for attr in self.tcx.get_attrs(def_id.to_def_id()).iter() {
438438
let assertion = match self.assertion_maybe(item_id, attr) {
439439
Some(a) => a,
440440
None => continue,
441441
};
442442
self.checked_attrs.insert(attr.id);
443-
for dep_node in self.dep_nodes(&assertion.clean, def_id) {
443+
for dep_node in self.dep_nodes(&assertion.clean, def_id.to_def_id()) {
444444
self.assert_clean(item_span, dep_node);
445445
}
446-
for dep_node in self.dep_nodes(&assertion.dirty, def_id) {
446+
for dep_node in self.dep_nodes(&assertion.dirty, def_id.to_def_id()) {
447447
self.assert_dirty(item_span, dep_node);
448448
}
449449
}

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn msg_span_from_early_bound_and_free_regions(
191191
let sm = tcx.sess.source_map();
192192

193193
let scope = region.free_region_binding_scope(tcx);
194-
let node = tcx.hir().as_local_hir_id(scope).unwrap();
194+
let node = tcx.hir().as_local_hir_id(scope.expect_local());
195195
let tag = match tcx.hir().find(node) {
196196
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
197197
Some(Node::Item(it)) => item_scope_tag(&it),
@@ -1780,10 +1780,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17801780
if !(generics.has_self && param.index == 0) {
17811781
let type_param = generics.type_param(param, self.tcx);
17821782
let hir = &self.tcx.hir();
1783-
hir.as_local_hir_id(type_param.def_id).map(|id| {
1783+
type_param.def_id.as_local().map(|def_id| {
17841784
// Get the `hir::Param` to verify whether it already has any bounds.
17851785
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
17861786
// instead we suggest `T: 'a + 'b` in that case.
1787+
let id = hir.as_local_hir_id(def_id);
17871788
let mut has_bounds = false;
17881789
if let Node::GenericParam(param) = hir.get(id) {
17891790
has_bounds = !param.bounds.is_empty();

src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2929
) -> Option<(&hir::Ty<'_>, &hir::FnDecl<'_>)> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3131
let def_id = anon_reg.def_id;
32-
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
32+
if let Some(def_id) = def_id.as_local() {
33+
let hir_id = self.tcx().hir().as_local_hir_id(def_id);
3334
let fndecl = match self.tcx().hir().get(hir_id) {
3435
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
3536
| Node::TraitItem(&hir::TraitItem {

src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4646
) = (&sub_origin, sup_region)
4747
{
4848
let hir = &self.tcx().hir();
49-
if let Some(hir_id) = hir.as_local_hir_id(free_region.scope) {
49+
if let Some(def_id) = free_region.scope.as_local() {
50+
let hir_id = hir.as_local_hir_id(def_id);
5051
if let Node::Expr(Expr { kind: Closure(_, _, _, closure_span, None), .. }) =
5152
hir.get(hir_id)
5253
{

0 commit comments

Comments
 (0)