From bfce24aa675072c832e5160acdefc4e98b7fe8f3 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Thu, 16 Apr 2020 20:36:32 +0100 Subject: [PATCH] Modify `as_local_hir_id` to return a bare `HirId` --- src/librustc_codegen_llvm/consts.rs | 2 +- .../back/symbol_export.rs | 2 +- src/librustc_hir/definitions.rs | 4 +- .../infer/error_reporting/mod.rs | 4 +- .../nice_region_error/find_anon_type.rs | 2 +- .../nice_region_error/outlives_closure.rs | 2 +- .../error_reporting/nice_region_error/util.rs | 2 +- src/librustc_lint/builtin.rs | 11 ++-- src/librustc_lint/late.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 16 ++--- src/librustc_middle/dep_graph/mod.rs | 2 +- src/librustc_middle/hir/map/mod.rs | 18 ++---- src/librustc_middle/hir/mod.rs | 4 +- src/librustc_middle/middle/region.rs | 4 +- src/librustc_middle/mir/mod.rs | 10 ++-- src/librustc_middle/mir/mono.rs | 12 ++-- src/librustc_middle/query/mod.rs | 2 +- src/librustc_middle/ty/context.rs | 5 +- src/librustc_middle/ty/mod.rs | 10 ++-- src/librustc_middle/ty/print/pretty.rs | 4 +- src/librustc_middle/ty/sty.rs | 2 +- .../diagnostics/conflict_errors.rs | 6 +- .../borrow_check/diagnostics/mod.rs | 6 +- .../diagnostics/mutability_errors.rs | 4 +- .../borrow_check/diagnostics/region_name.rs | 14 ++--- src/librustc_mir/borrow_check/mod.rs | 2 +- .../borrow_check/universal_regions.rs | 2 +- src/librustc_mir/const_eval/eval_queries.rs | 4 +- src/librustc_mir/const_eval/fn_queries.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 4 +- .../transform/check_consts/mod.rs | 2 +- .../transform/check_consts/validation.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 6 +- src/librustc_mir/transform/const_prop.rs | 2 +- src/librustc_mir/transform/inline.rs | 14 ++--- .../transform/qualify_min_const_fn.rs | 2 +- src/librustc_mir/util/liveness.rs | 2 +- src/librustc_mir_build/build/mod.rs | 2 +- src/librustc_mir_build/hair/cx/expr.rs | 2 +- .../hair/pattern/check_match.rs | 2 +- src/librustc_mir_build/lints.rs | 4 +- src/librustc_passes/dead.rs | 8 +-- src/librustc_passes/reachable.rs | 26 +++----- src/librustc_passes/region.rs | 2 +- src/librustc_passes/upvars.rs | 2 +- src/librustc_privacy/lib.rs | 21 ++++--- src/librustc_resolve/late/lifetimes.rs | 20 +++---- src/librustc_symbol_mangling/lib.rs | 2 +- src/librustc_trait_selection/opaque_types.rs | 4 +- .../traits/error_reporting/mod.rs | 3 +- .../traits/error_reporting/suggestions.rs | 6 +- .../traits/specialize/mod.rs | 2 +- src/librustc_traits/lowering/environment.rs | 2 +- src/librustc_ty/ty.rs | 10 ++-- src/librustc_typeck/astconv.rs | 8 +-- src/librustc_typeck/check/coercion.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 30 +++++----- src/librustc_typeck/check/dropck.rs | 4 +- src/librustc_typeck/check/expr.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 14 ++--- src/librustc_typeck/check/mod.rs | 60 +++++++++---------- src/librustc_typeck/check/wfcheck.rs | 8 +-- src/librustc_typeck/check/writeback.rs | 2 +- src/librustc_typeck/check_unused.rs | 8 +-- src/librustc_typeck/coherence/builtin.rs | 13 ++-- src/librustc_typeck/collect.rs | 26 ++++---- src/librustc_typeck/collect/type_of.rs | 4 +- .../impl_wf_check/min_specialization.rs | 2 +- src/librustc_typeck/lib.rs | 4 +- .../outlives/implicit_infer.rs | 2 +- src/librustc_typeck/outlives/mod.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 4 +- src/librustc_typeck/variance/mod.rs | 2 +- src/librustc_typeck/variance/terms.rs | 4 +- src/librustdoc/clean/inline.rs | 23 ++++--- src/librustdoc/clean/mod.rs | 5 +- src/librustdoc/clean/utils.rs | 2 +- src/librustdoc/core.rs | 2 +- .../passes/collect_intra_doc_links.rs | 6 +- src/librustdoc/visit_ast.rs | 2 +- 80 files changed, 248 insertions(+), 305 deletions(-) diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index ac2f47a740d5..c97b547946eb 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -210,7 +210,7 @@ impl CodegenCx<'ll, 'tcx> { debug!("get_static: sym={} instance={:?}", sym, instance); let g = if let Some(id) = - def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) { let llty = self.layout_of(ty).llvm_type(self); let (g, attrs) = match self.tcx.hir().get(id) { diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 5970059bb4ca..9faddf254d7e 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -362,7 +362,7 @@ fn upstream_drop_glue_for_provider<'tcx>( fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool { if let Some(def_id) = def_id.as_local() { - !tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id).unwrap()) + !tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id)) } else { bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id) } diff --git a/src/librustc_hir/definitions.rs b/src/librustc_hir/definitions.rs index 8927814ee04b..033c2973af6e 100644 --- a/src/librustc_hir/definitions.rs +++ b/src/librustc_hir/definitions.rs @@ -342,8 +342,8 @@ impl Definitions { } #[inline] - pub fn as_local_hir_id(&self, def_id: LocalDefId) -> Option { - Some(self.local_def_id_to_hir_id(def_id)) + pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId { + self.local_def_id_to_hir_id(def_id) } #[inline] diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index 7d8924718bb0..dd1d08a75ae1 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -191,7 +191,7 @@ fn msg_span_from_early_bound_and_free_regions( let sm = tcx.sess.source_map(); let scope = region.free_region_binding_scope(tcx); - let node = tcx.hir().as_local_hir_id(scope.expect_local()).unwrap(); + let node = tcx.hir().as_local_hir_id(scope.expect_local()); let tag = match tcx.hir().find(node) { Some(Node::Block(_) | Node::Expr(_)) => "body", Some(Node::Item(it)) => item_scope_tag(&it), @@ -1786,7 +1786,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // Get the `hir::Param` to verify whether it already has any bounds. // We do this to avoid suggesting code that ends up as `T: 'a'b`, // instead we suggest `T: 'a + 'b` in that case. - let id = hir.as_local_hir_id(def_id).unwrap(); + let id = hir.as_local_hir_id(def_id); let mut has_bounds = false; if let Node::GenericParam(param) = hir.get(id) { has_bounds = !param.bounds.is_empty(); diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs index d0141dc062af..e02a90c7b5f3 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -30,7 +30,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { if let Some(anon_reg) = self.tcx().is_suitable_region(region) { let def_id = anon_reg.def_id; if let Some(hir_id) = - def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id)) { let fndecl = match self.tcx().hir().get(hir_id) { Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs index 6bf60db00949..ca051cecbb8c 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs @@ -47,7 +47,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { { let hir = &self.tcx().hir(); if let Some(hir_id) = - free_region.scope.as_local().map(|def_id| hir.as_local_hir_id(def_id).unwrap()) + free_region.scope.as_local().map(|def_id| hir.as_local_hir_id(def_id)) { if let Node::Expr(Expr { kind: Closure(_, _, _, closure_span, None), .. }) = hir.get(hir_id) diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs index ab74513a6755..5c45f7584360 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs @@ -51,7 +51,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { }; let hir = &self.tcx().hir(); - let hir_id = hir.as_local_hir_id(id.as_local()?)?; + let hir_id = hir.as_local_hir_id(id.as_local()?); let body_id = hir.maybe_body_owned_by(hir_id)?; let body = hir.body(body_id); let owner_id = hir.body_owner(body_id); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 4040545db968..5b25204f21b1 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -436,9 +436,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { // If the trait is private, add the impl items to `private_traits` so they don't get // reported for missing docs. let real_trait = trait_ref.path.res.def_id(); - if let Some(hir_id) = real_trait - .as_local() - .map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap()) + if let Some(hir_id) = + real_trait.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id)) { if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) { if let hir::VisibilityKind::Inherited = item.vis.node { @@ -612,10 +611,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { let mut impls = HirIdSet::default(); cx.tcx.for_each_impl(debug, |d| { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { - if let Some(hir_id) = ty_def - .did - .as_local() - .map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap()) + if let Some(hir_id) = + ty_def.did.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id)) { impls.insert(hir_id); } diff --git a/src/librustc_lint/late.rs b/src/librustc_lint/late.rs index 0a0505e89d46..c4ac875fec53 100644 --- a/src/librustc_lint/late.rs +++ b/src/librustc_lint/late.rs @@ -364,7 +364,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( param_env: ty::ParamEnv::empty(), access_levels, lint_store: unerased_lint_store(tcx), - last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id).unwrap(), + last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id), generics: None, only_module: true, }; diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 7abd454a6f30..746ce1a28cb6 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -617,7 +617,7 @@ impl EncodeContext<'tcx> { ctor: variant.ctor_def_id.map(|did| did.index), }; - let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local()).unwrap(); + let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local()); let enum_vis = &tcx.hir().expect_item(enum_id).vis; record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data))); @@ -663,7 +663,7 @@ impl EncodeContext<'tcx> { // Variant constructors have the same visibility as the parent enums, unless marked as // non-exhaustive, in which case they are lowered to `pub(crate)`. - let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local()).unwrap(); + let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local()); let enum_vis = &tcx.hir().expect_item(enum_id).vis; let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx); if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public { @@ -729,7 +729,7 @@ impl EncodeContext<'tcx> { let def_id = field.did; debug!("EncodeContext::encode_field({:?})", def_id); - let variant_id = tcx.hir().as_local_hir_id(variant.def_id.expect_local()).unwrap(); + let variant_id = tcx.hir().as_local_hir_id(variant.def_id.expect_local()); let variant_data = tcx.hir().expect_variant_data(variant_id); record!(self.tables.kind[def_id] <- EntryKind::Field); @@ -756,7 +756,7 @@ impl EncodeContext<'tcx> { ctor: Some(def_id.index), }; - let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local()).unwrap(); + let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local()); let struct_vis = &tcx.hir().expect_item(struct_id).vis; let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx); for field in &variant.fields { @@ -818,7 +818,7 @@ impl EncodeContext<'tcx> { debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id); let tcx = self.tcx; - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let ast_item = tcx.hir().expect_trait_item(hir_id); let trait_item = tcx.associated_item(def_id); @@ -909,7 +909,7 @@ impl EncodeContext<'tcx> { debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id); let tcx = self.tcx; - let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local()); let ast_item = self.tcx.hir().expect_impl_item(hir_id); let impl_item = self.tcx.associated_item(def_id); @@ -1313,7 +1313,7 @@ impl EncodeContext<'tcx> { // NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic, // including on the signature, which is inferred in `typeck_tables_of. - let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def_id); let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id); let def_id = def_id.to_def_id(); @@ -1341,7 +1341,7 @@ impl EncodeContext<'tcx> { fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) { debug!("EncodeContext::encode_info_for_anon_const({:?})", def_id); - let id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); + let id = self.tcx.hir().as_local_hir_id(def_id); let body_id = self.tcx.hir().body_owned_by(id); let const_data = self.encode_rendered_const_for_body(body_id); let def_id = def_id.to_def_id(); diff --git a/src/librustc_middle/dep_graph/mod.rs b/src/librustc_middle/dep_graph/mod.rs index 0aca0f6e5b73..4786426792c3 100644 --- a/src/librustc_middle/dep_graph/mod.rs +++ b/src/librustc_middle/dep_graph/mod.rs @@ -181,6 +181,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { } fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); def_id == hir_id.owner } diff --git a/src/librustc_middle/hir/map/mod.rs b/src/librustc_middle/hir/map/mod.rs index 1dbb333708e4..8860fe7ff978 100644 --- a/src/librustc_middle/hir/map/mod.rs +++ b/src/librustc_middle/hir/map/mod.rs @@ -198,7 +198,7 @@ impl<'hir> Map<'hir> { } #[inline] - pub fn as_local_hir_id(&self, def_id: LocalDefId) -> Option { + pub fn as_local_hir_id(&self, def_id: LocalDefId) -> HirId { self.tcx.definitions.as_local_hir_id(def_id) } @@ -449,7 +449,7 @@ impl<'hir> Map<'hir> { } pub fn get_module(&self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) { - let hir_id = self.as_local_hir_id(module).unwrap(); + let hir_id = self.as_local_hir_id(module); match self.get_entry(hir_id).node { Node::Item(&Item { span, kind: ItemKind::Mod(ref m), .. }) => (m, span, hir_id), Node::Crate(item) => (&item.module, item.span, hir_id), @@ -482,11 +482,7 @@ impl<'hir> Map<'hir> { } pub fn get_if_local(&self, id: DefId) -> Option> { - if let Some(id) = id.as_local() { - self.as_local_hir_id(id).map(|id| self.get(id)) - } else { - None - } + if let Some(id) = id.as_local() { Some(self.get(self.as_local_hir_id(id))) } else { None } } pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> { @@ -887,11 +883,7 @@ impl<'hir> Map<'hir> { } pub fn span_if_local(&self, id: DefId) -> Option { - if let Some(id) = id.as_local() { - self.as_local_hir_id(id).map(|id| self.span(id)) - } else { - None - } + if let Some(id) = id.as_local() { Some(self.span(self.as_local_hir_id(id))) } else { None } } pub fn res_span(&self, res: Res) -> Option { @@ -1092,7 +1084,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String { pub fn provide(providers: &mut Providers<'_>) { providers.def_kind = |tcx, def_id| { if let Some(def_id) = def_id.as_local() { - tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id).unwrap()) + tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id)) } else { bug!("calling local def_kind query provider for upstream DefId: {:?}", def_id); } diff --git a/src/librustc_middle/hir/mod.rs b/src/librustc_middle/hir/mod.rs index c44a8b0b12e7..7ab66411b210 100644 --- a/src/librustc_middle/hir/mod.rs +++ b/src/librustc_middle/hir/mod.rs @@ -68,13 +68,13 @@ impl<'tcx> TyCtxt<'tcx> { pub fn provide(providers: &mut Providers<'_>) { providers.parent_module_from_def_id = |tcx, id| { let hir = tcx.hir(); - hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id).unwrap())) + hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id))) }; providers.hir_crate = |tcx, _| tcx.untracked_crate; providers.index_hir = map::index_hir; providers.hir_module_items = |tcx, id| { let hir = tcx.hir(); - let module = hir.as_local_hir_id(id).unwrap(); + let module = hir.as_local_hir_id(id); &tcx.untracked_crate.modules[&module] }; providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature; diff --git a/src/librustc_middle/middle/region.rs b/src/librustc_middle/middle/region.rs index 41f712f600aa..c3eeea7662ba 100644 --- a/src/librustc_middle/middle/region.rs +++ b/src/librustc_middle/middle/region.rs @@ -554,7 +554,7 @@ impl<'tcx> ScopeTree { pub fn early_free_scope(&self, tcx: TyCtxt<'tcx>, br: &ty::EarlyBoundRegion) -> Scope { let param_owner = tcx.parent(br.def_id).unwrap(); - let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local()).unwrap(); + let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local()); let scope = tcx .hir() .maybe_body_owned_by(param_owner_id) @@ -595,7 +595,7 @@ impl<'tcx> ScopeTree { // on the same function that they ended up being freed in. assert_eq!(param_owner, fr.scope); - let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local()).unwrap(); + let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local()); let body_id = tcx.hir().body_owned_by(param_owner_id); Scope { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite } } diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 96012c9e6538..93b031c5d884 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -2338,9 +2338,8 @@ impl<'tcx> Debug for Rvalue<'tcx> { } AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| { - if let Some(hir_id) = def_id - .as_local() - .map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + if let Some(hir_id) = + def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { let name = if tcx.sess.opts.debugging_opts.span_free_formats { let substs = tcx.lift(&substs).unwrap(); @@ -2367,9 +2366,8 @@ impl<'tcx> Debug for Rvalue<'tcx> { }), AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| { - if let Some(hir_id) = def_id - .as_local() - .map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + if let Some(hir_id) = + def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { let name = format!("[generator@{:?}]", tcx.hir().span(hir_id)); let mut struct_fmt = fmt.debug_struct(&name); diff --git a/src/librustc_middle/mir/mono.rs b/src/librustc_middle/mir/mono.rs index 1b18060c8866..fd1d410f0516 100644 --- a/src/librustc_middle/mir/mono.rs +++ b/src/librustc_middle/mir/mono.rs @@ -198,10 +198,10 @@ impl<'tcx> MonoItem<'tcx> { pub fn local_span(&self, tcx: TyCtxt<'tcx>) -> Option { match *self { MonoItem::Fn(Instance { def, .. }) => { - def.def_id().as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + def.def_id().as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) } MonoItem::Static(def_id) => { - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) } MonoItem::GlobalAsm(hir_id) => Some(hir_id), } @@ -343,9 +343,9 @@ impl<'tcx> CodegenUnit<'tcx> { // instances into account. The others don't matter for // the codegen tests and can even make item order // unstable. - InstanceDef::Item(def_id) => def_id - .as_local() - .map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()), + InstanceDef::Item(def_id) => { + def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) + } InstanceDef::VtableShim(..) | InstanceDef::ReifyShim(..) | InstanceDef::Intrinsic(..) @@ -357,7 +357,7 @@ impl<'tcx> CodegenUnit<'tcx> { } } MonoItem::Static(def_id) => { - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) } MonoItem::GlobalAsm(hir_id) => Some(hir_id), }, diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 618a83dc38fd..51bbb9016b6a 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -277,7 +277,7 @@ rustc_queries! { /// per-type-parameter predicates for resolving `T::AssocTy`. query type_param_predicates(key: (DefId, DefId)) -> ty::GenericPredicates<'tcx> { desc { |tcx| "computing the bounds for type parameter `{}`", { - let id = tcx.hir().as_local_hir_id(key.1.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(key.1.expect_local()); tcx.hir().ty_param_name(id) }} } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 85d216d9ca90..7797374259cb 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1413,8 +1413,7 @@ impl<'tcx> TyCtxt<'tcx> { _ => return None, // not a free region }; - let hir_id = - self.hir().as_local_hir_id(suitable_region_binding_scope.expect_local()).unwrap(); + let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope.expect_local()); let is_impl_item = match self.hir().find(hir_id) { Some(Node::Item(..) | Node::TraitItem(..)) => false, Some(Node::ImplItem(..)) => { @@ -1432,7 +1431,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn return_type_impl_trait(&self, scope_def_id: DefId) -> Option<(Ty<'tcx>, Span)> { // HACK: `type_of_def_id()` will fail on these (#55796), so return `None`. - let hir_id = self.hir().as_local_hir_id(scope_def_id.expect_local()).unwrap(); + let hir_id = self.hir().as_local_hir_id(scope_def_id.expect_local()); match self.hir().get(hir_id) { Node::Item(item) => { match item.kind { diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 9839bd806bd6..b785f79e1f35 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -2669,12 +2669,12 @@ impl<'tcx> TyCtxt<'tcx> { pub fn opt_item_name(self, def_id: DefId) -> Option { def_id .as_local() - .and_then(|def_id| self.hir().get(self.hir().as_local_hir_id(def_id).unwrap()).ident()) + .and_then(|def_id| self.hir().get(self.hir().as_local_hir_id(def_id)).ident()) } pub fn opt_associated_item(self, def_id: DefId) -> Option { let is_associated_item = if let Some(def_id) = def_id.as_local() { - match self.hir().get(self.hir().as_local_hir_id(def_id).unwrap()) { + match self.hir().get(self.hir().as_local_hir_id(def_id)) { Node::TraitItem(_) | Node::ImplItem(_) => true, _ => false, } @@ -2827,7 +2827,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Gets the attributes of a definition. pub fn get_attrs(self, did: DefId) -> Attributes<'tcx> { if let Some(did) = did.as_local() { - self.hir().attrs(self.hir().as_local_hir_id(did).unwrap()) + self.hir().attrs(self.hir().as_local_hir_id(did)) } else { self.item_attrs(did) } @@ -2866,7 +2866,7 @@ impl<'tcx> TyCtxt<'tcx> { /// with the name of the crate containing the impl. pub fn span_of_impl(self, impl_did: DefId) -> Result { if let Some(impl_did) = impl_did.as_local() { - let hir_id = self.hir().as_local_hir_id(impl_did).unwrap(); + let hir_id = self.hir().as_local_hir_id(impl_did); Ok(self.hir().span(hir_id)) } else { Err(self.crate_name(impl_did.krate)) @@ -2927,7 +2927,7 @@ pub struct AdtSizedConstraint<'tcx>(pub &'tcx [Ty<'tcx>]); /// Yields the parent function's `DefId` if `def_id` is an `impl Trait` definition. pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option { if let Some(def_id) = def_id.as_local() { - if let Node::Item(item) = tcx.hir().get(tcx.hir().as_local_hir_id(def_id).unwrap()) { + if let Node::Item(item) = tcx.hir().get(tcx.hir().as_local_hir_id(def_id)) { if let hir::ItemKind::OpaqueTy(ref opaque_ty) = item.kind { return opaque_ty.impl_trait_fn; } diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 646fc6fc8eb9..200ccf42c01f 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -609,7 +609,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) should use `def_span`. if let Some(hir_id) = - did.as_local().map(|did| self.tcx().hir().as_local_hir_id(did).unwrap()) + did.as_local().map(|did| self.tcx().hir().as_local_hir_id(did)) { p!(write("@{:?}", self.tcx().hir().span(hir_id))); @@ -655,7 +655,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) should use `def_span`. if let Some(hir_id) = - did.as_local().map(|did| self.tcx().hir().as_local_hir_id(did).unwrap()) + did.as_local().map(|did| self.tcx().hir().as_local_hir_id(did)) { if self.tcx().sess.opts.debugging_opts.span_free_formats { p!(write("@"), print_def_path(did, substs)); diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 4edd8420ebec..ac5477edcc3c 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -2266,7 +2266,7 @@ impl<'tcx> Const<'tcx> { ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => { // Find the name and index of the const parameter by indexing the generics of // the parent item and construct a `ParamConst`. - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let item_id = tcx.hir().get_parent_node(hir_id); let item_def_id = tcx.hir().local_def_id(item_id); let generics = tcx.generics_of(item_def_id.to_def_id()); diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index f4e75b1c971e..ef66e96381fa 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -192,7 +192,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let needs_note = match ty.kind { ty::Closure(id, _) => { let tables = self.infcx.tcx.typeck_tables_of(id); - let hir_id = self.infcx.tcx.hir().as_local_hir_id(id.expect_local()).unwrap(); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(id.expect_local()); tables.closure_kind_origins().get(hir_id).is_none() } @@ -867,7 +867,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if let Some(fn_hir_id) = self .mir_def_id .as_local() - .map(|def_id| self.infcx.tcx.hir().as_local_hir_id(def_id).unwrap()) + .map(|def_id| self.infcx.tcx.hir().as_local_hir_id(def_id)) { err.span_label( drop_span, @@ -1786,7 +1786,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ) -> Option> { debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig); let is_closure = self.infcx.tcx.is_closure(did); - let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(did.as_local()?)?; + let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(did.as_local()?); let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?; // We need to work out which arguments to highlight. We do this by looking diff --git a/src/librustc_mir/borrow_check/diagnostics/mod.rs b/src/librustc_mir/borrow_check/diagnostics/mod.rs index b3c6bee03ae5..16c5bf1518da 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mod.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mod.rs @@ -97,7 +97,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { debug!("add_moved_or_invoked_closure_note: closure={:?}", closure); if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind { - let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local()).unwrap(); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local()); if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) @@ -119,7 +119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // Check if we are just moving a closure after it has been invoked. if let Some(target) = target { if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind { - let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local()).unwrap(); + let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local()); if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) @@ -803,7 +803,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { "closure_span: def_id={:?} target_place={:?} places={:?}", def_id, target_place, places ); - let hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id.as_local()?)?; + let hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id.as_local()?); let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind; debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr); if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr { diff --git a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs index 0614538f4e40..1a4876db0ded 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs @@ -492,7 +492,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err.span_label(sp, format!("cannot {}", act)); let hir = self.infcx.tcx.hir(); - let closure_id = hir.as_local_hir_id(self.mir_def_id.expect_local()).unwrap(); + let closure_id = hir.as_local_hir_id(self.mir_def_id.expect_local()); let fn_call_id = hir.get_parent_node(closure_id); let node = hir.get(fn_call_id); let item_id = hir.get_parent_item(fn_call_id); @@ -691,7 +691,7 @@ fn annotate_struct_field( if let ty::Adt(def, _) = ty.kind { let field = def.all_fields().nth(field.index())?; // Use the HIR types to construct the diagnostic message. - let hir_id = tcx.hir().as_local_hir_id(field.did.as_local()?)?; + let hir_id = tcx.hir().as_local_hir_id(field.did.as_local()?); let node = tcx.hir().find(hir_id)?; // Now we're dealing with the actual struct that we're going to suggest a change to, // we can expect a field that is an immutable reference to a type. diff --git a/src/librustc_mir/borrow_check/diagnostics/region_name.rs b/src/librustc_mir/borrow_check/diagnostics/region_name.rs index 74cdccd7e3f0..37e2e0475048 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_name.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_name.rs @@ -237,12 +237,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { } ty::BoundRegion::BrEnv => { - let mir_hir_id = self - .infcx - .tcx - .hir() - .as_local_hir_id(self.mir_def_id.expect_local()) - .unwrap(); + let mir_hir_id = + self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id.expect_local()); let def_ty = self.regioncx.universal_regions().defining_ty; if let DefiningTy::Closure(_, substs) = def_ty { @@ -328,7 +324,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { argument_ty: Ty<'tcx>, argument_index: usize, ) -> Option { - let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id.as_local()?)?; + let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id.as_local()?); let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?; let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?; match argument_hir_ty.kind { @@ -639,7 +635,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap()); let type_name = self.infcx.extract_type_name(&return_ty, Some(highlight)).0; - let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id.expect_local()).unwrap(); + let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id.expect_local()); let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) { hir::Node::Expr(hir::Expr { @@ -691,7 +687,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap()); let type_name = self.infcx.extract_type_name(&yield_ty, Some(highlight)).0; - let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id.expect_local()).unwrap(); + let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id.expect_local()); let yield_span = match tcx.hir().get(mir_hir_id) { hir::Node::Expr(hir::Expr { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 7de890dfa6cb..7c7251c91349 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -116,7 +116,7 @@ fn do_mir_borrowck<'a, 'tcx>( let tcx = infcx.tcx; let param_env = tcx.param_env(def_id); - let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id); let mut local_names = IndexVec::from_elem(None, &input_body.local_decls); for var_debug_info in &input_body.var_debug_info { diff --git a/src/librustc_mir/borrow_check/universal_regions.rs b/src/librustc_mir/borrow_check/universal_regions.rs index de985cb37c56..e6099ba91922 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -224,7 +224,7 @@ impl<'tcx> UniversalRegions<'tcx> { param_env: ty::ParamEnv<'tcx>, ) -> Self { let tcx = infcx.tcx; - let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).unwrap(); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id); UniversalRegionsBuilder { infcx, mir_def_id: mir_def_id.to_def_id(), mir_hir_id, param_env } .build() } diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 6b6d02dedcb5..6d0a02ee3a47 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -342,7 +342,7 @@ pub fn const_eval_raw_provider<'tcx>( // validation thus preventing such a hard error from being a backwards // compatibility hazard Some(DefKind::Const | DefKind::AssocConst) => { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); err.report_as_lint( tcx.at(tcx.def_span(def_id)), "any use of this value will cause an error", @@ -365,7 +365,7 @@ pub fn const_eval_raw_provider<'tcx>( err.report_as_lint( tcx.at(span), "reaching this expression at runtime will panic or abort", - tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(), + tcx.hir().as_local_hir_id(def_id.expect_local()), Some(err.span), ) } diff --git a/src/librustc_mir/const_eval/fn_queries.rs b/src/librustc_mir/const_eval/fn_queries.rs index 8decebf6f8c2..74f8a1cb6d12 100644 --- a/src/librustc_mir/const_eval/fn_queries.rs +++ b/src/librustc_mir/const_eval/fn_queries.rs @@ -90,7 +90,7 @@ pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { /// Checks whether the function has a `const` modifier or, in case it is an intrinsic, whether /// said intrinsic is on the whitelist for being const callable. fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index a65b14e64f1b..802b8897bb98 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -430,9 +430,7 @@ fn check_recursion_limit<'tcx>( // infinite expansion. if adjusted_recursion_depth > *tcx.sess.recursion_limit.get() { let error = format!("reached the recursion limit while instantiating `{}`", instance); - if let Some(hir_id) = - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) - { + if let Some(hir_id) = def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { tcx.sess.span_fatal(tcx.hir().span(hir_id), &error); } else { tcx.sess.fatal(&error); diff --git a/src/librustc_mir/transform/check_consts/mod.rs b/src/librustc_mir/transform/check_consts/mod.rs index a0692cf8a709..46a46aa5ae95 100644 --- a/src/librustc_mir/transform/check_consts/mod.rs +++ b/src/librustc_mir/transform/check_consts/mod.rs @@ -72,7 +72,7 @@ impl ConstKind { pub fn for_item(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Option { use hir::BodyOwnerKind as HirKind; - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); let mode = match tcx.hir().body_owner_kind(hir_id) { HirKind::Closure => return None, diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 609499d25fde..f9f32247c948 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -190,7 +190,7 @@ impl Validator<'a, 'mir, 'tcx> { const_kind == Some(ConstKind::Static) && !tcx.has_attr(def_id, sym::thread_local); if should_check_for_sync { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); check_return_ty_is_sync(tcx, &body, hir_id); } } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 6f9d007f9d36..567fb61e0e8c 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -469,7 +469,7 @@ fn check_unused_unsafe( used_unsafe: &FxHashSet, unsafe_blocks: &mut Vec<(hir::HirId, bool)>, ) { - let body_id = tcx.hir().maybe_body_owned_by(tcx.hir().as_local_hir_id(def_id).unwrap()); + let body_id = tcx.hir().maybe_body_owned_by(tcx.hir().as_local_hir_id(def_id)); let body_id = match body_id { Some(body) => body, @@ -494,7 +494,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult let param_env = tcx.param_env(def_id); - let id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id.expect_local()); let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Closure => (false, false), hir::BodyOwnerKind::Fn => (is_const_fn(tcx, def_id), is_min_const_fn(tcx, def_id)), @@ -516,7 +516,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult } fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: DefId) { - let lint_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let lint_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); tcx.struct_span_lint_hir(SAFE_PACKED_BORROWS, lint_hir_id, tcx.def_span(def_id), |lint| { // FIXME: when we make this a hard error, this should have its diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 8647c3f07275..92859577d79c 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -66,7 +66,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp { } use rustc_middle::hir::map::blocks::FnLikeNode; - let hir_id = tcx.hir().as_local_hir_id(source.def_id().expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(source.def_id().expect_local()); let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some(); let is_assoc_const = match tcx.def_kind(source.def_id()) { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index cf0197659c80..523d6a160287 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -69,7 +69,7 @@ impl Inliner<'tcx> { let param_env = self.tcx.param_env(self.source.def_id()).with_reveal_all(); // Only do inlining into fn bodies. - let id = self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local()).unwrap(); + let id = self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local()); if self.tcx.hir().body_owner_kind(id).is_fn_or_closure() && self.source.promoted.is_none() { for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated() { if let Some(callsite) = @@ -94,14 +94,10 @@ impl Inliner<'tcx> { continue; } - let callee_hir_id = self.tcx.hir().as_local_hir_id(callsite.callee.expect_local()); - - let callee_body = if let Some(callee_hir_id) = callee_hir_id { - let self_hir_id = self - .tcx - .hir() - .as_local_hir_id(self.source.def_id().expect_local()) - .unwrap(); + let callee_body = if let Some(callee_def_id) = callsite.callee.as_local() { + let callee_hir_id = self.tcx.hir().as_local_hir_id(callee_def_id); + let self_hir_id = + self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local()); // Avoid a cycle here by only using `optimized_mir` only if we have // a lower `HirId` than the callee. This ensures that the callee will // not inline us. This trick only works without incremental compilation. diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index d2f1920b2634..a7217369bab3 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -13,7 +13,7 @@ type McfResult = Result<(), (Span, Cow<'static, str>)>; pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult { // Prevent const trait methods from being annotated as `stable`. if tcx.features().staged_api { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); if crate::const_eval::is_parent_const_impl_raw(tcx, hir_id) { return Err((body.span, "trait methods cannot be stable const fn".into())); } diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 595f39d028de..c6eefcc5ecaf 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -285,7 +285,7 @@ fn dump_matched_mir_node<'tcx>( ) { let mut file_path = PathBuf::new(); file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir)); - let item_id = tcx.hir().as_local_hir_id(source.def_id().expect_local()).unwrap(); + let item_id = tcx.hir().as_local_hir_id(source.def_id().expect_local()); let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name); file_path.push(&file_name); let _ = fs::File::create(&file_path).and_then(|file| { diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index ce3df93bf1e2..4dbe4bf7628e 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -27,7 +27,7 @@ crate fn mir_built(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::steal::Steal /// Construct the MIR for a given `DefId`. fn mir_build(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Body<'_> { - let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id); // Figure out what primary body this item has. let (body_id, return_ty_span) = match tcx.hir().get(id) { diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index 9669090eb466..0ef6d24d07b4 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -690,7 +690,7 @@ fn convert_path_expr<'a, 'tcx>( } Res::Def(DefKind::ConstParam, def_id) => { - let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local()); let item_id = cx.tcx.hir().get_parent_node(hir_id); let item_def_id = cx.tcx.hir().local_def_id(item_id); let generics = cx.tcx.generics_of(item_def_id); diff --git a/src/librustc_mir_build/hair/pattern/check_match.rs b/src/librustc_mir_build/hair/pattern/check_match.rs index 14f36038232a..c90634e511bb 100644 --- a/src/librustc_mir_build/hair/pattern/check_match.rs +++ b/src/librustc_mir_build/hair/pattern/check_match.rs @@ -23,7 +23,7 @@ use std::slice; crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) { let body_id = match def_id.as_local() { None => return, - Some(id) => tcx.hir().body_owned_by(tcx.hir().as_local_hir_id(id).unwrap()), + Some(id) => tcx.hir().body_owned_by(tcx.hir().as_local_hir_id(id)), }; let mut visitor = diff --git a/src/librustc_mir_build/lints.rs b/src/librustc_mir_build/lints.rs index dd2d6b06c18e..38f5df3e7055 100644 --- a/src/librustc_mir_build/lints.rs +++ b/src/librustc_mir_build/lints.rs @@ -11,7 +11,7 @@ use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION; use rustc_span::Span; crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) { if let FnKind::Closure(_) = fn_like_node.kind() { @@ -37,7 +37,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) { vis.reachable_recursive_calls.sort(); - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let sp = tcx.sess.source_map().guess_head_span(tcx.hir().span(hir_id)); tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| { let mut db = lint.build("function cannot return without recursing"); diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index 6ce1a7ef7776..261386f70d94 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -53,7 +53,7 @@ struct MarkSymbolVisitor<'a, 'tcx> { impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn check_def_id(&mut self, def_id: DefId) { if let Some(def_id) = def_id.as_local() { - let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def_id); if should_explore(self.tcx, hir_id) || self.struct_constructors.contains_key(&hir_id) { self.worklist.push(hir_id); } @@ -63,7 +63,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn insert_def_id(&mut self, def_id: DefId) { if let Some(def_id) = def_id.as_local() { - let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def_id); debug_assert!(!should_explore(self.tcx, hir_id)); self.live_symbols.insert(hir_id); } @@ -453,7 +453,7 @@ fn create_and_seed_worklist<'tcx>( .chain( // Seed entry point tcx.entry_fn(LOCAL_CRATE) - .map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap()), + .map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id.expect_local())), ) .collect::>(); @@ -538,7 +538,7 @@ impl DeadVisitor<'tcx> { for &impl_did in inherent_impls.iter() { for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] { if let Some(item_hir_id) = - item_did.as_local().map(|did| self.tcx.hir().as_local_hir_id(did).unwrap()) + item_did.as_local().map(|did| self.tcx.hir().as_local_hir_id(did)) { if self.live_symbols.contains(&item_hir_id) { return true; diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index a8ab127ddf83..d913486cb0e1 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -53,13 +53,9 @@ fn method_might_be_inlined( return true; } } - if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) { - match tcx.hir().find(impl_hir_id) { - Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs), - Some(..) | None => span_bug!(impl_item.span, "impl did is not an item"), - } - } else { - span_bug!(impl_item.span, "found a foreign impl as a parent of a local method") + match tcx.hir().find(tcx.hir().as_local_hir_id(impl_src)) { + Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs), + Some(..) | None => span_bug!(impl_item.span, "impl did is not an item"), } } @@ -108,9 +104,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> { } Some(res) => { if let Some((hir_id, def_id)) = res.opt_def_id().and_then(|def_id| { - def_id - .as_local() - .map(|def_id| (self.tcx.hir().as_local_hir_id(def_id).unwrap(), def_id)) + def_id.as_local().map(|def_id| (self.tcx.hir().as_local_hir_id(def_id), def_id)) }) { if self.def_id_represents_local_inlined_item(def_id.to_def_id()) { self.worklist.push(hir_id); @@ -144,7 +138,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // eligible for inlining and false otherwise. fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool { let hir_id = match def_id.as_local() { - Some(def_id) => self.tcx.hir().as_local_hir_id(def_id).unwrap(), + Some(def_id) => self.tcx.hir().as_local_hir_id(def_id), None => { return false; } @@ -176,7 +170,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // Check the impl. If the generics on the self // type of the impl require inlining, this method // does too. - let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap(); + let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did); match self.tcx.hir().expect_item(impl_hir_id).kind { hir::ItemKind::Impl { .. } => { let generics = self.tcx.generics_of(impl_did); @@ -362,9 +356,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx // FIXME(#53488) remove `let` let tcx = self.tcx; self.worklist.extend( - tcx.provided_trait_methods(trait_def_id).map(|assoc| { - tcx.hir().as_local_hir_id(assoc.def_id.expect_local()).unwrap() - }), + tcx.provided_trait_methods(trait_def_id) + .map(|assoc| tcx.hir().as_local_hir_id(assoc.def_id.expect_local())), ); } } @@ -403,8 +396,7 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> &'tcx HirIdSet reachable_context.worklist.extend(access_levels.map.iter().map(|(id, _)| *id)); for item in tcx.lang_items().items().iter() { if let Some(did) = *item { - if let Some(hir_id) = did.as_local().map(|did| tcx.hir().as_local_hir_id(did).unwrap()) - { + if let Some(hir_id) = did.as_local().map(|did| tcx.hir().as_local_hir_id(did)) { reachable_context.worklist.push(hir_id); } } diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index 3a9edd0410e0..927e6a7e712b 100644 --- a/src/librustc_passes/region.rs +++ b/src/librustc_passes/region.rs @@ -807,7 +807,7 @@ fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree { return tcx.region_scope_tree(closure_base_def_id); } - let id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id.expect_local()); let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) { let mut visitor = RegionResolutionVisitor { tcx, diff --git a/src/librustc_passes/upvars.rs b/src/librustc_passes/upvars.rs index 0cdc4f5bd8f7..fb986caa415c 100644 --- a/src/librustc_passes/upvars.rs +++ b/src/librustc_passes/upvars.rs @@ -15,7 +15,7 @@ pub fn provide(providers: &mut Providers<'_>) { return None; } - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(hir_id)?); let mut local_collector = LocalCollector::default(); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index c268189c5b2e..7e1a53d4c3f1 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -235,7 +235,7 @@ fn def_id_visibility<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, ) -> (ty::Visibility, Span, &'static str) { - match def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) { + match def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { Some(hir_id) => { let vis = match tcx.hir().get(hir_id) { Node::Item(item) => &item.vis, @@ -446,7 +446,7 @@ impl VisibilityLike for Option { fn new_min(find: &FindMin<'_, '_, Self>, def_id: DefId) -> Self { cmp::min( if let Some(hir_id) = - def_id.as_local().map(|def_id| find.tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| find.tcx.hir().as_local_hir_id(def_id)) { find.access_levels.map.get(&hir_id).cloned() } else { @@ -549,9 +549,8 @@ impl EmbargoVisitor<'tcx> { if export.vis.is_accessible_from(defining_mod, self.tcx) { if let Res::Def(def_kind, def_id) = export.res { let vis = def_id_visibility(self.tcx, def_id).0; - if let Some(hir_id) = def_id - .as_local() - .map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + if let Some(hir_id) = + def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) { self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod); } @@ -660,7 +659,7 @@ impl EmbargoVisitor<'tcx> { // there will be no corresponding item. .filter(|def_id| def_id.index != CRATE_DEF_INDEX || def_id.krate != LOCAL_CRATE) .and_then(|def_id| { - def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) }) .map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id)) { @@ -917,7 +916,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { if let Some(def_id) = export.res.opt_def_id() { if let Some(hir_id) = def_id .as_local() - .map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + .map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) { self.update(hir_id, Some(AccessLevel::Exported)); } @@ -1007,7 +1006,7 @@ impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { } fn visit_def_id(&mut self, def_id: DefId, _kind: &str, _descr: &dyn fmt::Display) -> bool { if let Some(def_id) = def_id.as_local() { - let hir_id = self.ev.tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = self.ev.tcx.hir().as_local_hir_id(def_id); if let ((ty::Visibility::Public, ..), _) | (_, Some(AccessLevel::ReachableFromImplTrait)) = (def_id_visibility(self.tcx(), def_id.to_def_id()), self.access_level) @@ -1457,7 +1456,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { if let Some(did) = did.as_local() { // .. and it corresponds to a private type in the AST (this returns // `None` for type parameters). - match self.tcx.hir().find(self.tcx.hir().as_local_hir_id(did).unwrap()) { + match self.tcx.hir().find(self.tcx.hir().as_local_hir_id(did)) { Some(Node::Item(ref item)) => !item.vis.node.is_pub(), Some(_) | None => false, } @@ -1576,7 +1575,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { let did = tr.path.res.def_id(); if let Some(did) = did.as_local() { - self.trait_is_public(self.tcx.hir().as_local_hir_id(did).unwrap()) + self.trait_is_public(self.tcx.hir().as_local_hir_id(did)) } else { true // external traits must be public } @@ -1837,7 +1836,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> { } let hir_id = match def_id.as_local() { - Some(def_id) => self.tcx.hir().as_local_hir_id(def_id).unwrap(), + Some(def_id) => self.tcx.hir().as_local_hir_id(def_id), None => return false, }; diff --git a/src/librustc_resolve/late/lifetimes.rs b/src/librustc_resolve/late/lifetimes.rs index 225e6da5ced9..8d9110f9a57d 100644 --- a/src/librustc_resolve/late/lifetimes.rs +++ b/src/librustc_resolve/late/lifetimes.rs @@ -598,7 +598,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { if let Some(Region::LateBound(_, def_id, _)) = def { if let Some(hir_id) = def_id .as_local() - .map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + .map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) { // Ensure that the parent of the def is an item, not HRTB let parent_id = self.tcx.hir().get_parent_node(hir_id); @@ -1169,8 +1169,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) { if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.normalize_to_macros_2_0())) { - let hir_id = - tcx.hir().as_local_hir_id(def.id().unwrap().expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap().expect_local()); signal_shadowing_problem( tcx, @@ -1541,7 +1540,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { match lifetimeuseset { Some(LifetimeUseSet::One(lifetime)) => { - let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local()); debug!("hir id first={:?}", hir_id); if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) { Node::Lifetime(hir_lifetime) => Some(( @@ -1562,7 +1561,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { if let Some(parent_def_id) = self.tcx.parent(def_id) { if let Some(parent_hir_id) = parent_def_id .as_local() - .map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + .map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) { // lifetimes in `derive` expansions don't count (Issue #53738) if self @@ -1605,7 +1604,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { debug!("not one use lifetime"); } None => { - let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local()); if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) { Node::Lifetime(hir_lifetime) => Some(( hir_lifetime.hir_id, @@ -1961,7 +1960,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let map = &self.map; let unsubst = if let Some(id) = - def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) { &map.object_lifetime_defaults[&id] } else { @@ -2668,11 +2667,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { Scope::Binder { ref lifetimes, s, .. } => { if let Some(&def) = lifetimes.get(¶m.name.normalize_to_macros_2_0()) { - let hir_id = self - .tcx - .hir() - .as_local_hir_id(def.id().unwrap().expect_local()) - .unwrap(); + let hir_id = + self.tcx.hir().as_local_hir_id(def.id().unwrap().expect_local()); signal_shadowing_problem( self.tcx, diff --git a/src/librustc_symbol_mangling/lib.rs b/src/librustc_symbol_mangling/lib.rs index c255b8304e5b..5a1c6491f86d 100644 --- a/src/librustc_symbol_mangling/lib.rs +++ b/src/librustc_symbol_mangling/lib.rs @@ -175,7 +175,7 @@ fn compute_symbol_name( let disambiguator = tcx.sess.local_crate_disambiguator(); return tcx.sess.generate_proc_macro_decls_symbol(disambiguator); } - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); match tcx.hir().get(hir_id) { Node::ForeignItem(_) => true, _ => false, diff --git a/src/librustc_trait_selection/opaque_types.rs b/src/librustc_trait_selection/opaque_types.rs index 16fef2f6e360..8af9d7ea9048 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -1037,7 +1037,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { // } // ``` if let Some(opaque_hir_id) = - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { let parent_def_id = self.parent_def_id; let def_scope_default = || { @@ -1219,7 +1219,7 @@ pub fn may_define_opaque_type( def_id: LocalDefId, opaque_hir_id: hir::HirId, ) -> bool { - let mut hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let mut hir_id = tcx.hir().as_local_hir_id(def_id); // Named opaque types can be defined by any siblings or children of siblings. let scope = tcx.hir().get_defining_scope(opaque_hir_id); diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index c6c9b068a5e7..fa9f1c9a7d97 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -507,8 +507,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { self.tcx.sess.source_map().guess_head_span( self.tcx.hir().span_if_local(closure_def_id).unwrap(), ); - let hir_id = - self.tcx.hir().as_local_hir_id(closure_def_id.expect_local()).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id.expect_local()); let mut err = struct_span_err!( self.tcx.sess, closure_span, diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index b6d592b3143e..88b9d257795f 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -430,7 +430,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { }; let hir = self.tcx.hir(); - let hir_id = hir.as_local_hir_id(def_id.as_local()?)?; + let hir_id = hir.as_local_hir_id(def_id.as_local()?); let parent_node = hir.get_parent_node(hir_id); match hir.find(parent_node) { Some(hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(local), .. })) => { @@ -1237,7 +1237,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let generator_body = generator_did .as_local() - .map(|def_id| hir.as_local_hir_id(def_id).unwrap()) + .map(|def_id| hir.as_local_hir_id(def_id)) .and_then(|hir_id| hir.maybe_body_owned_by(hir_id)) .map(|body_id| hir.body(body_id)); let mut visitor = AwaitsVisitor::default(); @@ -1388,7 +1388,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { .tcx .parent(generator_did) .and_then(|parent_did| parent_did.as_local()) - .and_then(|parent_did| hir.as_local_hir_id(parent_did)) + .map(|parent_did| hir.as_local_hir_id(parent_did)) .and_then(|parent_hir_id| hir.opt_name(parent_hir_id)) .map(|name| { format!("future returned by `{}` is not {}", name, trait_name) diff --git a/src/librustc_trait_selection/traits/specialize/mod.rs b/src/librustc_trait_selection/traits/specialize/mod.rs index 95bc64fdaff2..61583669c6b5 100644 --- a/src/librustc_trait_selection/traits/specialize/mod.rs +++ b/src/librustc_trait_selection/traits/specialize/mod.rs @@ -452,7 +452,7 @@ fn report_conflicting_impls( }; tcx.struct_span_lint_hir( lint, - tcx.hir().as_local_hir_id(impl_def_id).unwrap(), + tcx.hir().as_local_hir_id(impl_def_id), impl_span, decorate, ) diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index b598b6f4fb4e..e7fa245fd405 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -174,7 +174,7 @@ crate fn environment(tcx: TyCtxt<'_>, def_id: DefId) -> Environment<'_> { // could bound lifetimes. .map(Clause::ForAll); - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); enum NodeKind { diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index 1e215ebc42f1..16f395a4fec8 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -128,7 +128,7 @@ fn associated_item_from_impl_item_ref( } fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem { - let id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id.expect_local()); let parent_id = tcx.hir().get_parent_item(id); let parent_def_id = tcx.hir().local_def_id(parent_id); let parent_item = tcx.hir().expect_item(parent_id); @@ -166,7 +166,7 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem { } fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let item = tcx.hir().expect_item(hir_id); if let hir::ItemKind::Impl { defaultness, .. } = item.kind { defaultness @@ -200,7 +200,7 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtSizedConstrain } fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] { - let id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id.expect_local()); let item = tcx.hir().expect_item(id); match item.kind { hir::ItemKind::Trait(.., ref trait_item_refs) => tcx.arena.alloc_from_iter( @@ -267,7 +267,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { let body_id = def_id .as_local() - .map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + .map(|def_id| tcx.hir().as_local_hir_id(def_id)) .map_or(hir::CRATE_HIR_ID, |id| { tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id) }); @@ -355,7 +355,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { /// Check if a function is async. fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 1de01168c2f0..63b8eb224cec 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -147,7 +147,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { def: Option<&ty::GenericParamDef>, ) -> ty::Region<'tcx> { let tcx = self.tcx(); - let lifetime_name = |def_id| tcx.hir().name(tcx.hir().as_local_hir_id(def_id).unwrap()); + let lifetime_name = |def_id| tcx.hir().name(tcx.hir().as_local_hir_id(def_id)); let r = match tcx.named_region(lifetime.hir_id) { Some(rl::Region::Static) => tcx.lifetimes.re_static, @@ -1990,7 +1990,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!("find_bound_for_assoc_item: predicates={:#?}", predicates); - let param_hir_id = tcx.hir().as_local_hir_id(ty_param_def_id).unwrap(); + let param_hir_id = tcx.hir().as_local_hir_id(ty_param_def_id); let param_name = tcx.hir().ty_param_name(param_hir_id); self.one_bound_for_assoc_type( || { @@ -2374,7 +2374,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let parent_def_id = def_id .and_then(|def_id| { - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) }) .map(|hir_id| tcx.hir().get_parent_did(hir_id).to_def_id()); @@ -2669,7 +2669,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { assert_eq!(opt_self_ty, None); self.prohibit_generics(path.segments); - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let item_id = tcx.hir().get_parent_node(hir_id); let item_def_id = tcx.hir().local_def_id(item_id); let generics = tcx.generics_of(item_def_id); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 9da3dd0408a0..8070ad171202 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -1393,7 +1393,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { let ty = AstConv::ast_ty_to_ty(fcx, ty); // Get the `impl Trait`'s `DefId`. if let ty::Opaque(def_id, _) = ty.kind { - let hir_id = fcx.tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = fcx.tcx.hir().as_local_hir_id(def_id.expect_local()); // Get the `impl Trait`'s `Item` so that we can get its trait bounds and // get the `Trait`'s `DefId`. if let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) = diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index dbdb26afaec2..f834f74d5df1 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -76,7 +76,7 @@ fn compare_predicate_entailment<'tcx>( // This node-id should be used for the `body_id` field on each // `ObligationCause` (and the `FnCtxt`). This is what // `regionck_item` expects. - let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local()).unwrap(); + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local()); let cause = ObligationCause { span: impl_m_span, @@ -399,7 +399,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( trait_sig: ty::FnSig<'tcx>, ) -> (Span, Option) { let tcx = infcx.tcx; - let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local()).unwrap(); + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local()); let (impl_m_output, impl_m_iter) = match tcx.hir().expect_impl_item(impl_m_hir_id).kind { ImplItemKind::Fn(ref impl_m_sig, _) => { (&impl_m_sig.decl.output, impl_m_sig.decl.inputs.iter()) @@ -410,7 +410,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( match *terr { TypeError::Mutability => { if let Some(trait_m_hir_id) = - trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { let trait_m_iter = match tcx.hir().expect_trait_item(trait_m_hir_id).kind { TraitItemKind::Fn(ref trait_m_sig, _) => trait_m_sig.decl.inputs.iter(), @@ -439,7 +439,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( } TypeError::Sorts(ExpectedFound { .. }) => { if let Some(trait_m_hir_id) = - trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { let (trait_m_output, trait_m_iter) = match tcx.hir().expect_trait_item(trait_m_hir_id).kind { @@ -592,7 +592,7 @@ fn compare_number_of_generics<'tcx>( err_occurred = true; let (trait_spans, impl_trait_spans) = if let Some(trait_hir_id) = - trait_.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()) + trait_.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) { let trait_item = tcx.hir().expect_trait_item(trait_hir_id); if trait_item.generics.params.is_empty() { @@ -618,7 +618,7 @@ fn compare_number_of_generics<'tcx>( (trait_span.map(|s| vec![s]), vec![]) }; - let impl_hir_id = tcx.hir().as_local_hir_id(impl_.def_id.expect_local()).unwrap(); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_.def_id.expect_local()); let impl_item = tcx.hir().expect_impl_item(impl_hir_id); let impl_item_impl_trait_spans: Vec = impl_item .generics @@ -710,7 +710,7 @@ fn compare_number_of_method_arguments<'tcx>( let impl_number_args = impl_m_fty.inputs().skip_binder().len(); if trait_number_args != impl_number_args { let trait_span = if let Some(def_id) = trait_m.def_id.as_local() { - let trait_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let trait_id = tcx.hir().as_local_hir_id(def_id); match tcx.hir().expect_trait_item(trait_id).kind { TraitItemKind::Fn(ref trait_m_sig, _) => { let pos = if trait_number_args > 0 { trait_number_args - 1 } else { 0 }; @@ -733,7 +733,7 @@ fn compare_number_of_method_arguments<'tcx>( } else { trait_item_span }; - let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local()).unwrap(); + let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local()); let impl_span = match tcx.hir().expect_impl_item(impl_m_hir_id).kind { ImplItemKind::Fn(ref impl_m_sig, _) => { let pos = if impl_number_args > 0 { impl_number_args - 1 } else { 0 }; @@ -815,7 +815,7 @@ fn compare_synthetic_generics<'tcx>( impl_m_type_params.zip(trait_m_type_params) { if impl_synthetic != trait_synthetic { - let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id.expect_local()).unwrap(); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id.expect_local()); let impl_span = tcx.hir().span(impl_hir_id); let trait_span = tcx.def_span(trait_def_id); let mut err = struct_span_err!( @@ -836,10 +836,10 @@ fn compare_synthetic_generics<'tcx>( // FIXME: this is obviously suboptimal since the name can already be used // as another generic argument let new_name = tcx.sess.source_map().span_to_snippet(trait_span).ok()?; - let trait_m = tcx.hir().as_local_hir_id(trait_m.def_id.as_local()?)?; + let trait_m = tcx.hir().as_local_hir_id(trait_m.def_id.as_local()?); let trait_m = tcx.hir().trait_item(hir::TraitItemId { hir_id: trait_m }); - let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id.as_local()?)?; + let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id.as_local()?); let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m }); // in case there are no generics, take the spot between the function name @@ -873,7 +873,7 @@ fn compare_synthetic_generics<'tcx>( (None, Some(hir::SyntheticTyParamKind::ImplTrait)) => { err.span_label(impl_span, "expected `impl Trait`, found generic parameter"); (|| { - let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id.as_local()?)?; + let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id.as_local()?); let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m }); let input_tys = match impl_m.kind { hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs, @@ -966,7 +966,7 @@ crate fn compare_const_impl<'tcx>( // Create a parameter environment that represents the implementation's // method. - let impl_c_hir_id = tcx.hir().as_local_hir_id(impl_c.def_id.expect_local()).unwrap(); + let impl_c_hir_id = tcx.hir().as_local_hir_id(impl_c.def_id.expect_local()); // Compute placeholder form of impl and trait const tys. let impl_ty = tcx.type_of(impl_c.def_id); @@ -1011,7 +1011,7 @@ crate fn compare_const_impl<'tcx>( ); let trait_c_hir_id = - trait_c.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id).unwrap()); + trait_c.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)); let trait_c_span = trait_c_hir_id.map(|trait_c_hir_id| { // Add a label to the Span containing just the type of the const match tcx.hir().expect_trait_item(trait_c_hir_id).kind { @@ -1099,7 +1099,7 @@ fn compare_type_predicate_entailment( // This `HirId` should be used for the `body_id` field on each // `ObligationCause` (and the `FnCtxt`). This is what // `regionck_item` expects. - let impl_ty_hir_id = tcx.hir().as_local_hir_id(impl_ty.def_id.expect_local()).unwrap(); + let impl_ty_hir_id = tcx.hir().as_local_hir_id(impl_ty.def_id.expect_local()); let cause = ObligationCause { span: impl_ty_span, body_id: impl_ty_hir_id, diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 40efbd6f95c2..078401ee6a81 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -71,7 +71,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>( drop_impl_ty: Ty<'tcx>, self_type_did: DefId, ) -> Result<(), ErrorReported> { - let drop_impl_hir_id = tcx.hir().as_local_hir_id(drop_impl_did).unwrap(); + let drop_impl_hir_id = tcx.hir().as_local_hir_id(drop_impl_did); // check that the impl type can be made to match the trait type. @@ -190,7 +190,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( // absent. So we report an error that the Drop impl injected a // predicate that is not present on the struct definition. - let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did).unwrap(); + let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did); // We can assume the predicates attached to struct/enum definition // hold. diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 353ab250cf08..2bca5e758252 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1626,7 +1626,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let param_def_id = generic_param.def_id; let param_hir_id = match param_def_id.as_local() { - Some(x) => self.tcx.hir().as_local_hir_id(x).unwrap(), + Some(x) => self.tcx.hir().as_local_hir_id(x), None => return, }; let param_span = self.tcx.hir().span(param_hir_id); diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 37cf5180cf86..dc94a57882da 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -580,9 +580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind { let node = def.did.as_local().map(|def_id| { - self.tcx - .hir() - .get(self.tcx.hir().as_local_hir_id(def_id).unwrap()) + self.tcx.hir().get(self.tcx.hir().as_local_hir_id(def_id)) }); if let Some(hir::Node::Item(hir::Item { kind, .. })) = node { if let Some(g) = kind.generics() { @@ -857,7 +855,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { candidates: Vec, ) { let module_did = self.tcx.parent_module(self.body_id); - let module_id = self.tcx.hir().as_local_hir_id(module_did).unwrap(); + let module_id = self.tcx.hir().as_local_hir_id(module_did); let krate = self.tcx.hir().krate(); let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id); if let Some(span) = span { @@ -961,7 +959,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .filter(|item| { if let ty::AssocKind::Fn = item.kind { let id = item.def_id.as_local().map(|def_id| { - self.tcx.hir().as_local_hir_id(def_id).unwrap() + self.tcx.hir().as_local_hir_id(def_id) }); if let Some(hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(fn_sig, method), @@ -1054,10 +1052,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let generics = self.tcx.generics_of(table_owner.to_def_id()); let type_param = generics.type_param(param, self.tcx); let hir = &self.tcx.hir(); - if let Some(id) = type_param - .def_id - .as_local() - .map(|def_id| hir.as_local_hir_id(def_id).unwrap()) + if let Some(id) = + type_param.def_id.as_local().map(|def_id| hir.as_local_hir_id(def_id)) { // Get the `hir::Param` to verify whether it already has any bounds. // We do this to avoid suggesting code that ends up as `T: FooBar`, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e318eec3e1c7..51e3bc4cae40 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -977,7 +977,7 @@ fn diagnostic_only_typeck_tables_of<'tcx>( ) -> &ty::TypeckTables<'tcx> { assert!(def_id.is_local()); let fallback = move || { - let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap()); + let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id.expect_local())); tcx.sess.delay_span_bug(span, "diagnostic only typeck table used"); tcx.types.err }; @@ -996,7 +996,7 @@ fn typeck_tables_of_with_fallback<'tcx>( return tcx.typeck_tables_of(outer_def_id); } - let id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id.expect_local()); let span = tcx.hir().span(id); // Figure out what primary body this item has. @@ -1333,7 +1333,7 @@ fn check_fn<'a, 'tcx>( } let outer_def_id = tcx.closure_base_def_id(hir.local_def_id(fn_id).to_def_id()); - let outer_hir_id = hir.as_local_hir_id(outer_def_id.expect_local()).unwrap(); + let outer_hir_id = hir.as_local_hir_id(outer_def_id.expect_local()); GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id }.visit_body(body); // C-variadic fns also have a `VaList` input that's not listed in `fn_sig` @@ -1448,7 +1448,7 @@ fn check_fn<'a, 'tcx>( // Check that the main return type implements the termination trait. if let Some(term_id) = tcx.lang_items().termination() { if let Some((def_id, EntryFnType::Main)) = tcx.entry_fn(LOCAL_CRATE) { - let main_id = hir.as_local_hir_id(def_id.expect_local()).unwrap(); + let main_id = hir.as_local_hir_id(def_id.expect_local()); if main_id == fn_id { let substs = tcx.mk_substs_trait(declared_ret_ty, &[]); let trait_ref = ty::TraitRef::new(term_id, substs); @@ -1626,7 +1626,7 @@ fn check_opaque<'tcx>( /// Checks that an opaque type does not use `Self` or `T::Foo` projections that would result /// in "inheriting lifetimes". fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) { - let item = tcx.hir().expect_item(tcx.hir().as_local_hir_id(def_id).unwrap()); + let item = tcx.hir().expect_item(tcx.hir().as_local_hir_id(def_id)); debug!( "check_opaque_for_inheriting_lifetimes: def_id={:?} span={:?} item={:?}", def_id, span, item @@ -2460,34 +2460,32 @@ fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: &ty::AdtDef) { ); let hir = tcx.hir(); - if let Some(hir_id) = hir.as_local_hir_id(def_spans[0].0.expect_local()) { - if let Node::Item(Item { ident, .. }) = hir.get(hir_id) { - err.span_note( - tcx.def_span(def_spans[0].0), - &format!("`{}` has a `#[repr(align)]` attribute", ident), - ); - } + let hir_id = hir.as_local_hir_id(def_spans[0].0.expect_local()); + if let Node::Item(Item { ident, .. }) = hir.get(hir_id) { + err.span_note( + tcx.def_span(def_spans[0].0), + &format!("`{}` has a `#[repr(align)]` attribute", ident), + ); } if def_spans.len() > 2 { let mut first = true; for (adt_def, span) in def_spans.iter().skip(1).rev() { - if let Some(hir_id) = hir.as_local_hir_id(adt_def.expect_local()) { - if let Node::Item(Item { ident, .. }) = hir.get(hir_id) { - err.span_note( - *span, - &if first { - format!( - "`{}` contains a field of type `{}`", - tcx.type_of(def.did), - ident - ) - } else { - format!("...which contains a field of type `{}`", ident) - }, - ); - first = false; - } + let hir_id = hir.as_local_hir_id(adt_def.expect_local()); + if let Node::Item(Item { ident, .. }) = hir.get(hir_id) { + err.span_note( + *span, + &if first { + format!( + "`{}` contains a field of type `{}`", + tcx.type_of(def.did), + ident + ) + } else { + format!("...which contains a field of type `{}`", ident) + }, + ); + first = false; } } } @@ -2696,7 +2694,7 @@ pub fn check_enum<'tcx>( // Check for duplicate discriminant values if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) { let variant_did = def.variants[VariantIdx::new(i)].def_id; - let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did.expect_local()).unwrap(); + let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did.expect_local()); let variant_i = tcx.hir().expect_variant(variant_i_hir_id); let i_span = match variant_i.disr_expr { Some(ref expr) => tcx.hir().span(expr.hir_id), @@ -2757,7 +2755,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { fn get_type_parameter_bounds(&self, _: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> { let tcx = self.tcx; - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let item_id = tcx.hir().ty_param_owner(hir_id); let item_def_id = tcx.hir().local_def_id(item_id); let generics = tcx.generics_of(item_def_id); @@ -4974,7 +4972,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sugg_call = fields.iter().map(|_| "_").collect::>().join(", "); match def_id .as_local() - .map(|def_id| hir.as_local_hir_id(def_id).unwrap()) + .map(|def_id| hir.as_local_hir_id(def_id)) .and_then(|hir_id| hir.def_kind(hir_id)) { Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, _)) => { diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index b3c1b5b23e68..ffe1dcbd4440 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -71,7 +71,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> { /// not included it frequently leads to confusing errors in fn bodies. So it's better to check /// the types first. pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); let item = tcx.hir().expect_item(hir_id); debug!( @@ -184,7 +184,7 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { } pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); let trait_item = tcx.hir().expect_trait_item(hir_id); let method_sig = match trait_item.kind { @@ -258,7 +258,7 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem } pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); let impl_item = tcx.hir().expect_impl_item(hir_id); let method_sig = match impl_item.kind { @@ -878,7 +878,7 @@ fn check_opaque_types<'fcx, 'tcx>( // FIXME(eddyb) is `generics.parent.is_none()` correct? It seems // potentially risky wrt associated types in `impl`s. if generics.parent.is_none() && def_id.is_local() { - let opaque_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let opaque_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); if may_define_opaque_type(tcx, fn_def_id, opaque_hir_id) { trace!("check_opaque_types: may define, generics={:#?}", generics); let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default(); diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index f03438af9201..56714a4fa679 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -427,7 +427,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn visit_opaque_types(&mut self, span: Span) { for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() { - let hir_id = self.tcx().hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = self.tcx().hir().as_local_hir_id(def_id.expect_local()); let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id); debug_assert!(!instantiated_ty.has_escaping_bound_vars()); diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 0c6fc8f32aaf..da93462fe268 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -89,10 +89,8 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { // Note that if we carry through to the `extern_mod_stmt_cnum` query // below it'll cause a panic because `def_id` is actually bogus at this // point in time otherwise. - if let Some(id) = tcx.hir().as_local_hir_id(def_id.expect_local()) { - if tcx.hir().find(id).is_none() { - return false; - } + if tcx.hir().find(tcx.hir().as_local_hir_id(def_id.expect_local())).is_none() { + return false; } true }) @@ -115,7 +113,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { }); for extern_crate in &crates_to_lint { - let id = tcx.hir().as_local_hir_id(extern_crate.def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(extern_crate.def_id.expect_local()); let item = tcx.hir().expect_item(id); // If the crate is fully unused, we suggest removing it altogether. diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index c0613ffdf2ea..c01c4d90c8e1 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -53,7 +53,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) { return; } - let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).expect("foreign Drop impl on non-ADT"); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_did); let sp = match tcx.hir().expect_item(impl_hir_id).kind { ItemKind::Impl { self_ty, .. } => self_ty.span, _ => bug!("expected Drop impl item"), @@ -72,12 +72,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) { fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) { debug!("visit_implementation_of_copy: impl_did={:?}", impl_did); - let impl_hir_id = if let Some(n) = tcx.hir().as_local_hir_id(impl_did) { - n - } else { - debug!("visit_implementation_of_copy(): impl not in this crate"); - return; - }; + let impl_hir_id = tcx.hir().as_local_hir_id(impl_did); let self_type = tcx.type_of(impl_did); debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); @@ -152,7 +147,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef let dispatch_from_dyn_trait = tcx.lang_items().dispatch_from_dyn_trait().unwrap(); - let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).unwrap(); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_did); let span = tcx.hir().span(impl_hir_id); let source = tcx.type_of(impl_did); @@ -326,7 +321,7 @@ pub fn coerce_unsized_info(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedI }); // this provider should only get invoked for local def-ids - let impl_hir_id = tcx.hir().as_local_hir_id(impl_did.expect_local()).unwrap(); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_did.expect_local()); let source = tcx.type_of(impl_did); let trait_ref = tcx.impl_trait_ref(impl_did).unwrap(); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d3bb43f5eac9..a831beb2be25 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -269,7 +269,7 @@ impl ItemCtxt<'tcx> { } pub fn hir_id(&self) -> hir::HirId { - self.tcx.hir().as_local_hir_id(self.item_def_id.expect_local()).unwrap() + self.tcx.hir().as_local_hir_id(self.item_def_id.expect_local()) } pub fn node(&self) -> hir::Node<'tcx> { @@ -486,7 +486,7 @@ fn type_param_predicates( // written inline like `` or in a where-clause like // `where T: Foo`. - let param_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let param_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let param_owner = tcx.hir().ty_param_owner(param_id); let param_owner_def_id = tcx.hir().local_def_id(param_owner); let generics = tcx.generics_of(param_owner_def_id); @@ -508,7 +508,7 @@ fn type_param_predicates( .unwrap_or_default(); let mut extend = None; - let item_hir_id = tcx.hir().as_local_hir_id(item_def_id.expect_local()).unwrap(); + let item_hir_id = tcx.hir().as_local_hir_id(item_def_id.expect_local()); let ast_generics = match tcx.hir().get(item_hir_id) { Node::TraitItem(item) => &item.generics, @@ -814,7 +814,7 @@ fn convert_variant( parent_did: LocalDefId, ) -> ty::VariantDef { let mut seen_fields: FxHashMap = Default::default(); - let hir_id = tcx.hir().as_local_hir_id(variant_did.unwrap_or(parent_did)).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(variant_did.unwrap_or(parent_did)); let fields = def .fields() .iter() @@ -865,7 +865,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::AdtDef { use rustc_hir::*; let def_id = def_id.expect_local(); - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); let item = match tcx.hir().get(hir_id) { Node::Item(item) => item, _ => bug!(), @@ -952,7 +952,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::AdtDef { /// the transitive super-predicates are converted. fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredicates<'_> { debug!("super_predicates(trait_def_id={:?})", trait_def_id); - let trait_hir_id = tcx.hir().as_local_hir_id(trait_def_id.expect_local()).unwrap(); + let trait_hir_id = tcx.hir().as_local_hir_id(trait_def_id.expect_local()); let item = match tcx.hir().get(trait_hir_id) { Node::Item(item) => item, @@ -1003,7 +1003,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi } fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TraitDef { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let item = tcx.hir().expect_item(hir_id); let (is_auto, unsafety) = match item.kind { @@ -1161,7 +1161,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option, def_id: DefId) -> &ty::Generics { use rustc_hir::*; - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); let parent_def_id = match node { @@ -1459,7 +1459,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { use rustc_hir::Node::*; use rustc_hir::*; - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let icx = ItemCtxt::new(tcx, def_id); @@ -1557,7 +1557,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { let icx = ItemCtxt::new(tcx, def_id); - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); match tcx.hir().expect_item(hir_id).kind { hir::ItemKind::Impl { ref of_trait, .. } => of_trait.as_ref().map(|ast_trait_ref| { let selfty = tcx.type_of(def_id); @@ -1568,7 +1568,7 @@ fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { } fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl); let item = tcx.hir().expect_item(hir_id); match &item.kind { @@ -1702,7 +1702,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat } } - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); let mut is_trait = None; @@ -2557,7 +2557,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { if codegen_fn_attrs.flags.intersects(CodegenFnAttrFlags::NO_SANITIZE_ANY) { if codegen_fn_attrs.inline == InlineAttr::Always { if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) { - let hir_id = tcx.hir().as_local_hir_id(id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(id.expect_local()); tcx.struct_span_lint_hir( lint::builtin::INLINE_NO_SANITIZE, hir_id, diff --git a/src/librustc_typeck/collect/type_of.rs b/src/librustc_typeck/collect/type_of.rs index 4ff836855dd8..7fa55ecbeb91 100644 --- a/src/librustc_typeck/collect/type_of.rs +++ b/src/librustc_typeck/collect/type_of.rs @@ -21,7 +21,7 @@ use super::{bad_placeholder_type, is_suggestable_infer_ty}; pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { use rustc_hir::*; - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let icx = ItemCtxt::new(tcx, def_id); @@ -514,7 +514,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> { } } - let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id); let scope = tcx.hir().get_defining_scope(hir_id); let mut locator = ConstraintLocator { def_id: def_id.to_def_id(), tcx, found: None }; diff --git a/src/librustc_typeck/impl_wf_check/min_specialization.rs b/src/librustc_typeck/impl_wf_check/min_specialization.rs index f419f052b811..c7ef07bde30c 100644 --- a/src/librustc_typeck/impl_wf_check/min_specialization.rs +++ b/src/librustc_typeck/impl_wf_check/min_specialization.rs @@ -346,7 +346,7 @@ fn check_predicates<'tcx>( if let Some(obligations) = wf::obligations( infcx, tcx.param_env(impl1_def_id), - tcx.hir().as_local_hir_id(impl1_def_id).unwrap(), + tcx.hir().as_local_hir_id(impl1_def_id), ty, span, ) { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 0c922ff17ac8..7ca81e5d6b6c 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -153,7 +153,7 @@ fn require_same_types<'tcx>( } fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) { - let main_id = tcx.hir().as_local_hir_id(main_def_id).unwrap(); + let main_id = tcx.hir().as_local_hir_id(main_def_id); let main_span = tcx.def_span(main_def_id); let main_t = tcx.type_of(main_def_id); match main_t.kind { @@ -232,7 +232,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) { } fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) { - let start_id = tcx.hir().as_local_hir_id(start_def_id).unwrap(); + let start_id = tcx.hir().as_local_hir_id(start_def_id); let start_span = tcx.def_span(start_def_id); let start_t = tcx.type_of(start_def_id); match start_t.kind { diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 3c579538e64b..15c72f8704f6 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -57,7 +57,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { debug!("InferVisitor::visit_item(item={:?})", item_did); - let hir_id = self.tcx.hir().as_local_hir_id(item_did).expect("expected local def-id"); + let hir_id = self.tcx.hir().as_local_hir_id(item_did); let item = match self.tcx.hir().get(hir_id) { Node::Item(item) => item, _ => bug!(), diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index 71fcd9ddd6bc..15e0473bbf59 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -18,7 +18,7 @@ pub fn provide(providers: &mut Providers<'_>) { } fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate<'_>, Span)] { - let id = tcx.hir().as_local_hir_id(item_def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(item_def_id.expect_local()); match tcx.hir().get(id) { Node::Item(item) => match item.kind { diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 5b0ccc5169ee..3ec3ef2f30c9 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -137,7 +137,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { return; } - let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id); let inferred_start = self.terms_cx.inferred_starts[&id]; let current_item = &CurrentItem { inferred_start }; match tcx.type_of(def_id).kind { @@ -378,7 +378,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } let (local, remote) = if let Some(id) = - def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id)) { (Some(self.terms_cx.inferred_starts[&id]), None) } else { diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index f9e32c2a6b0c..2d78ac4b3c58 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -38,7 +38,7 @@ fn crate_variances(tcx: TyCtxt<'_>, crate_num: CrateNum) -> &CrateVariancesMap<' } fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] { - let id = tcx.hir().as_local_hir_id(item_def_id.expect_local()).unwrap(); + let id = tcx.hir().as_local_hir_id(item_def_id.expect_local()); let unsupported = || { // Variance not relevant. span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item") diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index c6cdac5d0ccf..fe585826d220 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -94,9 +94,7 @@ fn lang_items(tcx: TyCtxt<'_>) -> Vec<(hir::HirId, Vec)> { all.into_iter() // iterating over (Option, Variance) .filter(|&(ref d, _)| d.is_some()) .map(|(d, v)| (d.unwrap(), v)) // (DefId, Variance) - .filter_map(|(d, v)| { - d.as_local().map(|d| tcx.hir().as_local_hir_id(d).unwrap()).map(|n| (n, v)) - }) // (HirId, Variance) + .filter_map(|(d, v)| d.as_local().map(|d| tcx.hir().as_local_hir_id(d)).map(|n| (n, v))) // (HirId, Variance) .collect() } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index fc50a0ac2253..7a25f07bfe96 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -340,15 +340,14 @@ pub fn build_impl( } } - let for_ = - if let Some(hir_id) = did.as_local().map(|did| tcx.hir().as_local_hir_id(did).unwrap()) { - match tcx.hir().expect_item(hir_id).kind { - hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx), - _ => panic!("did given to build_impl was not an impl"), - } - } else { - tcx.type_of(did).clean(cx) - }; + let for_ = if let Some(hir_id) = did.as_local().map(|did| tcx.hir().as_local_hir_id(did)) { + match tcx.hir().expect_item(hir_id).kind { + hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx), + _ => panic!("did given to build_impl was not an impl"), + } + } else { + tcx.type_of(did).clean(cx) + }; // Only inline impl if the implementing type is // reachable in rustdoc generated documentation @@ -362,7 +361,7 @@ pub fn build_impl( let predicates = tcx.explicit_predicates_of(did); let (trait_items, generics) = if let Some(hir_id) = - did.as_local().map(|did| tcx.hir().as_local_hir_id(did).unwrap()) + did.as_local().map(|did| tcx.hir().as_local_hir_id(did)) { match tcx.hir().expect_item(hir_id).kind { hir::ItemKind::Impl { ref generics, ref items, .. } => ( @@ -489,7 +488,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet) } pub fn print_inlined_const(cx: &DocContext<'_>, did: DefId) -> String { - if let Some(hir_id) = did.as_local().map(|did| cx.tcx.hir().as_local_hir_id(did).unwrap()) { + if let Some(hir_id) = did.as_local().map(|did| cx.tcx.hir().as_local_hir_id(did)) { rustc_hir_pretty::id_to_string(&cx.tcx.hir(), hir_id) } else { cx.tcx.rendered_const(did) @@ -502,7 +501,7 @@ fn build_const(cx: &DocContext<'_>, did: DefId) -> clean::Constant { expr: print_inlined_const(cx, did), value: clean::utils::print_evaluated_const(cx, did), is_literal: did.as_local().map_or(false, |did| { - clean::utils::is_literal_expr(cx, cx.tcx.hir().as_local_hir_id(did).unwrap()) + clean::utils::is_literal_expr(cx, cx.tcx.hir().as_local_hir_id(did)) }), } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 751f3b868fd0..a685b4a73cd3 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1379,9 +1379,8 @@ impl Clean for hir::Ty<'_> { let mut alias = None; if let Res::Def(DefKind::TyAlias, def_id) = path.res { // Substitute private type aliases - if let Some(hir_id) = def_id - .as_local() - .map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap()) + if let Some(hir_id) = + def_id.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id)) { if !cx.renderinfo.borrow().access_levels.is_exported(def_id) { alias = Some(&cx.tcx.hir().expect_item(hir_id).kind); diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index ebb1838a83b1..de101a20fc59 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -474,7 +474,7 @@ pub fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String { match n.val { ty::ConstKind::Unevaluated(def_id, _, promoted) => { let mut s = if let Some(hir_id) = - def_id.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id)) { print_const_expr(cx, cx.tcx.hir().body_owned_by(hir_id)) } else { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index cc5bb335baee..91e60f81cec5 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -144,7 +144,7 @@ impl<'tcx> DocContext<'tcx> { if self.all_fake_def_ids.borrow().contains(&def_id) { None } else { - def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap()) + def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id)) } } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 675cc918490e..2f10171e616e 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -335,10 +335,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { fn fold_item(&mut self, mut item: Item) -> Option { let item_hir_id = if item.is_mod() { - if let Some(id) = item - .def_id - .as_local() - .map(|def_id| self.cx.tcx.hir().as_local_hir_id(def_id).unwrap()) + if let Some(id) = + item.def_id.as_local().map(|def_id| self.cx.tcx.hir().as_local_hir_id(def_id)) { Some(id) } else { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 6b9f3acf9e89..2050c6c57bab 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } let res_hir_id = match res_did.as_local() { - Some(n) => tcx.hir().as_local_hir_id(n).unwrap(), + Some(n) => tcx.hir().as_local_hir_id(n), None => return false, };