Skip to content

Commit 9d5e085

Browse files
committed
Modify as_local_hir_id to return a bare HirId
1 parent 3532d6e commit 9d5e085

File tree

81 files changed

+245
-298
lines changed

Some content is hidden

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

81 files changed

+245
-298
lines changed

src/librustc_codegen_llvm/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl CodegenCx<'ll, 'tcx> {
210210
debug!("get_static: sym={} instance={:?}", sym, instance);
211211

212212
let g = if let Some(id) =
213-
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap())
213+
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
214214
{
215215
let llty = self.layout_of(ty).llvm_type(self);
216216
let (g, attrs) = match self.tcx.hir().get(id) {

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn upstream_drop_glue_for_provider<'tcx>(
360360

361361
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
362362
if let Some(def_id) = def_id.as_local() {
363-
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id).unwrap())
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_hir/definitions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ impl Definitions {
342342
}
343343

344344
#[inline]
345-
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> Option<hir::HirId> {
346-
Some(self.local_def_id_to_hir_id(def_id))
345+
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId {
346+
self.local_def_id_to_hir_id(def_id)
347347
}
348348

349349
#[inline]

src/librustc_infer/infer/error_reporting/mod.rs

+2-2
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.expect_local()).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),
@@ -1784,7 +1784,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
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).unwrap();
1787+
let id = hir.as_local_hir_id(def_id);
17881788
let mut has_bounds = false;
17891789
if let Node::GenericParam(param) = hir.get(id) {
17901790
has_bounds = !param.bounds.is_empty();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3131
let def_id = anon_reg.def_id;
3232
if let Some(hir_id) =
33-
def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id).unwrap())
33+
def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id))
3434
{
3535
let fndecl = match self.tcx().hir().get(hir_id) {
3636
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4747
{
4848
let hir = &self.tcx().hir();
4949
if let Some(hir_id) =
50-
free_region.scope.as_local().map(|def_id| hir.as_local_hir_id(def_id).unwrap())
50+
free_region.scope.as_local().map(|def_id| hir.as_local_hir_id(def_id))
5151
{
5252
if let Node::Expr(Expr { kind: Closure(_, _, _, closure_span, None), .. }) =
5353
hir.get(hir_id)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5151
};
5252

5353
let hir = &self.tcx().hir();
54-
let hir_id = hir.as_local_hir_id(id.as_local()?)?;
54+
let hir_id = hir.as_local_hir_id(id.as_local()?);
5555
let body_id = hir.maybe_body_owned_by(hir_id)?;
5656
let body = hir.body(body_id);
5757
let owner_id = hir.body_owner(body_id);

src/librustc_lint/builtin.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
436436
// If the trait is private, add the impl items to `private_traits` so they don't get
437437
// reported for missing docs.
438438
let real_trait = trait_ref.path.res.def_id();
439-
if let Some(hir_id) = real_trait
440-
.as_local()
441-
.map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap())
439+
if let Some(hir_id) =
440+
real_trait.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id))
442441
{
443442
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
444443
if let hir::VisibilityKind::Inherited = item.vis.node {
@@ -612,10 +611,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
612611
let mut impls = HirIdSet::default();
613612
cx.tcx.for_each_impl(debug, |d| {
614613
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
615-
if let Some(hir_id) = ty_def
616-
.did
617-
.as_local()
618-
.map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap())
614+
if let Some(hir_id) =
615+
ty_def.did.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id))
619616
{
620617
impls.insert(hir_id);
621618
}

src/librustc_lint/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
364364
param_env: ty::ParamEnv::empty(),
365365
access_levels,
366366
lint_store: unerased_lint_store(tcx),
367-
last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id).unwrap(),
367+
last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id),
368368
generics: None,
369369
only_module: true,
370370
};

src/librustc_metadata/rmeta/encoder.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl EncodeContext<'tcx> {
616616
ctor: variant.ctor_def_id.map(|did| did.index),
617617
};
618618

619-
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local()).unwrap();
619+
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
620620
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
621621

622622
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
@@ -662,7 +662,7 @@ impl EncodeContext<'tcx> {
662662

663663
// Variant constructors have the same visibility as the parent enums, unless marked as
664664
// non-exhaustive, in which case they are lowered to `pub(crate)`.
665-
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local()).unwrap();
665+
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
666666
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
667667
let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx);
668668
if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public {
@@ -728,7 +728,7 @@ impl EncodeContext<'tcx> {
728728
let def_id = field.did;
729729
debug!("EncodeContext::encode_field({:?})", def_id);
730730

731-
let variant_id = tcx.hir().as_local_hir_id(variant.def_id.expect_local()).unwrap();
731+
let variant_id = tcx.hir().as_local_hir_id(variant.def_id.expect_local());
732732
let variant_data = tcx.hir().expect_variant_data(variant_id);
733733

734734
record!(self.tables.kind[def_id] <- EntryKind::Field);
@@ -755,7 +755,7 @@ impl EncodeContext<'tcx> {
755755
ctor: Some(def_id.index),
756756
};
757757

758-
let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local()).unwrap();
758+
let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local());
759759
let struct_vis = &tcx.hir().expect_item(struct_id).vis;
760760
let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx);
761761
for field in &variant.fields {
@@ -817,7 +817,7 @@ impl EncodeContext<'tcx> {
817817
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
818818
let tcx = self.tcx;
819819

820-
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap();
820+
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
821821
let ast_item = tcx.hir().expect_trait_item(hir_id);
822822
let trait_item = tcx.associated_item(def_id);
823823

@@ -908,7 +908,7 @@ impl EncodeContext<'tcx> {
908908
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
909909
let tcx = self.tcx;
910910

911-
let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap();
911+
let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local());
912912
let ast_item = self.tcx.hir().expect_impl_item(hir_id);
913913
let impl_item = self.tcx.associated_item(def_id);
914914

@@ -1312,7 +1312,7 @@ impl EncodeContext<'tcx> {
13121312

13131313
// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
13141314
// including on the signature, which is inferred in `typeck_tables_of.
1315-
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
1315+
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
13161316
let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id);
13171317

13181318
let def_id = def_id.to_def_id();
@@ -1340,7 +1340,7 @@ impl EncodeContext<'tcx> {
13401340

13411341
fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) {
13421342
debug!("EncodeContext::encode_info_for_anon_const({:?})", def_id);
1343-
let id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
1343+
let id = self.tcx.hir().as_local_hir_id(def_id);
13441344
let body_id = self.tcx.hir().body_owned_by(id);
13451345
let const_data = self.encode_rendered_const_for_body(body_id);
13461346
let def_id = def_id.to_def_id();

src/librustc_middle/dep_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
181181
}
182182

183183
fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
184-
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
184+
let hir_id = tcx.hir().as_local_hir_id(def_id);
185185
def_id == hir_id.owner
186186
}

src/librustc_middle/hir/map/mod.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'hir> Map<'hir> {
198198
}
199199

200200
#[inline]
201-
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> Option<HirId> {
201+
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> HirId {
202202
self.tcx.definitions.as_local_hir_id(def_id)
203203
}
204204

@@ -449,7 +449,7 @@ impl<'hir> Map<'hir> {
449449
}
450450

451451
pub fn get_module(&self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
452-
let hir_id = self.as_local_hir_id(module).unwrap();
452+
let hir_id = self.as_local_hir_id(module);
453453
match self.get_entry(hir_id).node {
454454
Node::Item(&Item { span, kind: ItemKind::Mod(ref m), .. }) => (m, span, hir_id),
455455
Node::Crate(item) => (&item.module, item.span, hir_id),
@@ -482,11 +482,7 @@ impl<'hir> Map<'hir> {
482482
}
483483

484484
pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
485-
if let Some(id) = id.as_local() {
486-
self.as_local_hir_id(id).map(|id| self.get(id))
487-
} else {
488-
None
489-
}
485+
if let Some(id) = id.as_local() { Some(self.get(self.as_local_hir_id(id))) } else { None }
490486
}
491487

492488
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
@@ -889,11 +885,7 @@ impl<'hir> Map<'hir> {
889885
}
890886

891887
pub fn span_if_local(&self, id: DefId) -> Option<Span> {
892-
if let Some(id) = id.as_local() {
893-
self.as_local_hir_id(id).map(|id| self.span(id))
894-
} else {
895-
None
896-
}
888+
if let Some(id) = id.as_local() { Some(self.span(self.as_local_hir_id(id))) } else { None }
897889
}
898890

899891
pub fn res_span(&self, res: Res) -> Option<Span> {
@@ -1094,7 +1086,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String {
10941086
pub fn provide(providers: &mut Providers<'_>) {
10951087
providers.def_kind = |tcx, def_id| {
10961088
if let Some(def_id) = def_id.as_local() {
1097-
tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id).unwrap())
1089+
tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id))
10981090
} else {
10991091
bug!("calling local def_kind query provider for upstream DefId: {:?}", def_id);
11001092
}

src/librustc_middle/hir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ impl<'tcx> TyCtxt<'tcx> {
6868
pub fn provide(providers: &mut Providers<'_>) {
6969
providers.parent_module_from_def_id = |tcx, id| {
7070
let hir = tcx.hir();
71-
hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id).unwrap()))
71+
hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id)))
7272
};
7373
providers.hir_crate = |tcx, _| tcx.untracked_crate;
7474
providers.index_hir = map::index_hir;
7575
providers.hir_module_items = |tcx, id| {
7676
let hir = tcx.hir();
77-
let module = hir.as_local_hir_id(id).unwrap();
77+
let module = hir.as_local_hir_id(id);
7878
&tcx.untracked_crate.modules[&module]
7979
};
8080
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;

src/librustc_middle/middle/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl<'tcx> ScopeTree {
554554
pub fn early_free_scope(&self, tcx: TyCtxt<'tcx>, br: &ty::EarlyBoundRegion) -> Scope {
555555
let param_owner = tcx.parent(br.def_id).unwrap();
556556

557-
let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local()).unwrap();
557+
let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local());
558558
let scope = tcx
559559
.hir()
560560
.maybe_body_owned_by(param_owner_id)
@@ -595,7 +595,7 @@ impl<'tcx> ScopeTree {
595595
// on the same function that they ended up being freed in.
596596
assert_eq!(param_owner, fr.scope);
597597

598-
let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local()).unwrap();
598+
let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local());
599599
let body_id = tcx.hir().body_owned_by(param_owner_id);
600600
Scope { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
601601
}

src/librustc_middle/mir/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -2284,9 +2284,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22842284
}
22852285

22862286
AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
2287-
if let Some(hir_id) = def_id
2288-
.as_local()
2289-
.map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap())
2287+
if let Some(hir_id) =
2288+
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
22902289
{
22912290
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
22922291
let substs = tcx.lift(&substs).unwrap();
@@ -2313,9 +2312,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23132312
}),
23142313

23152314
AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
2316-
if let Some(hir_id) = def_id
2317-
.as_local()
2318-
.map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap())
2315+
if let Some(hir_id) =
2316+
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
23192317
{
23202318
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
23212319
let mut struct_fmt = fmt.debug_struct(&name);

src/librustc_middle/mir/mono.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ impl<'tcx> MonoItem<'tcx> {
198198
pub fn local_span(&self, tcx: TyCtxt<'tcx>) -> Option<Span> {
199199
match *self {
200200
MonoItem::Fn(Instance { def, .. }) => {
201-
def.def_id().as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap())
201+
def.def_id().as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
202202
}
203203
MonoItem::Static(def_id) => {
204-
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap())
204+
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
205205
}
206206
MonoItem::GlobalAsm(hir_id) => Some(hir_id),
207207
}
@@ -343,9 +343,9 @@ impl<'tcx> CodegenUnit<'tcx> {
343343
// instances into account. The others don't matter for
344344
// the codegen tests and can even make item order
345345
// unstable.
346-
InstanceDef::Item(def_id) => def_id
347-
.as_local()
348-
.map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()),
346+
InstanceDef::Item(def_id) => {
347+
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
348+
}
349349
InstanceDef::VtableShim(..)
350350
| InstanceDef::ReifyShim(..)
351351
| InstanceDef::Intrinsic(..)
@@ -357,7 +357,7 @@ impl<'tcx> CodegenUnit<'tcx> {
357357
}
358358
}
359359
MonoItem::Static(def_id) => {
360-
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap())
360+
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
361361
}
362362
MonoItem::GlobalAsm(hir_id) => Some(hir_id),
363363
},

src/librustc_middle/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ rustc_queries! {
287287
/// per-type-parameter predicates for resolving `T::AssocTy`.
288288
query type_param_predicates(key: (DefId, DefId)) -> ty::GenericPredicates<'tcx> {
289289
desc { |tcx| "computing the bounds for type parameter `{}`", {
290-
let id = tcx.hir().as_local_hir_id(key.1.expect_local()).unwrap();
290+
let id = tcx.hir().as_local_hir_id(key.1.expect_local());
291291
tcx.hir().ty_param_name(id)
292292
}}
293293
}

src/librustc_middle/ty/context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,7 @@ impl<'tcx> TyCtxt<'tcx> {
14131413
_ => return None, // not a free region
14141414
};
14151415

1416-
let hir_id =
1417-
self.hir().as_local_hir_id(suitable_region_binding_scope.expect_local()).unwrap();
1416+
let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope.expect_local());
14181417
let is_impl_item = match self.hir().find(hir_id) {
14191418
Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false,
14201419
Some(Node::ImplItem(..)) => {
@@ -1432,7 +1431,7 @@ impl<'tcx> TyCtxt<'tcx> {
14321431

14331432
pub fn return_type_impl_trait(&self, scope_def_id: DefId) -> Option<(Ty<'tcx>, Span)> {
14341433
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
1435-
let hir_id = self.hir().as_local_hir_id(scope_def_id.expect_local()).unwrap();
1434+
let hir_id = self.hir().as_local_hir_id(scope_def_id.expect_local());
14361435
match self.hir().get(hir_id) {
14371436
Node::Item(item) => {
14381437
match item.kind {

0 commit comments

Comments
 (0)