Skip to content

Commit bfce24a

Browse files
committed
Modify as_local_hir_id to return a bare HirId
1 parent 6148db7 commit bfce24a

File tree

80 files changed

+248
-305
lines changed

Some content is hidden

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

80 files changed

+248
-305
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
@@ -362,7 +362,7 @@ fn upstream_drop_glue_for_provider<'tcx>(
362362

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

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(_) | Node::Expr(_)) => "body",
197197
Some(Node::Item(it)) => item_scope_tag(&it),
@@ -1786,7 +1786,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17861786
// Get the `hir::Param` to verify whether it already has any bounds.
17871787
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
17881788
// instead we suggest `T: 'a + 'b` in that case.
1789-
let id = hir.as_local_hir_id(def_id).unwrap();
1789+
let id = hir.as_local_hir_id(def_id);
17901790
let mut has_bounds = false;
17911791
if let Node::GenericParam(param) = hir.get(id) {
17921792
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
@@ -617,7 +617,7 @@ impl EncodeContext<'tcx> {
617617
ctor: variant.ctor_def_id.map(|did| did.index),
618618
};
619619

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

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

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

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

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

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

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

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

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

@@ -1313,7 +1313,7 @@ impl EncodeContext<'tcx> {
13131313

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

13191319
let def_id = def_id.to_def_id();
@@ -1341,7 +1341,7 @@ impl EncodeContext<'tcx> {
13411341

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

0 commit comments

Comments
 (0)