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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 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.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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 8 deletions
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();

0 commit comments

Comments
 (0)