From 91f87bc9bc29461513aaa6252905a7ac0ac303e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 13 Aug 2020 00:00:00 +0000 Subject: [PATCH 1/4] Set CMAKE_SYSTEM_NAME when cross-compiling Configure CMAKE_SYSTEM_NAME when cross-compiling in `configure_cmake`, to tell CMake about target system. Previously this was done only for LLVM step and now applies more generally to steps using cmake. --- src/bootstrap/native.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 48b2cc24d4cd8..e1e14893b9aa4 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -282,14 +282,6 @@ impl Step for Llvm { "LLVM_CONFIG_PATH", host_bin.join("llvm-config").with_extension(EXE_EXTENSION), ); - - if target.contains("netbsd") { - cfg.define("CMAKE_SYSTEM_NAME", "NetBSD"); - } else if target.contains("freebsd") { - cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD"); - } else if target.contains("windows") { - cfg.define("CMAKE_SYSTEM_NAME", "Windows"); - } } if let Some(ref suffix) = builder.config.llvm_version_suffix { @@ -378,6 +370,22 @@ fn configure_cmake( } cfg.target(&target.triple).host(&builder.config.build.triple); + if target != builder.config.build { + if target.contains("netbsd") { + cfg.define("CMAKE_SYSTEM_NAME", "NetBSD"); + } else if target.contains("freebsd") { + cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD"); + } else if target.contains("windows") { + cfg.define("CMAKE_SYSTEM_NAME", "Windows"); + } + // When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in + // that case like CMake we cannot easily determine system version either. + // + // Since, the LLVM itself makes rather limited use of version checks in + // CMakeFiles (and then only in tests), and so far no issues have been + // reported, the system version is currently left unset. + } + let sanitize_cc = |cc: &Path| { if target.contains("msvc") { OsString::from(cc.to_str().unwrap().replace("\\", "/")) From cd53760cc7751b65943feb6437af28d5ccb6e770 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 12 Aug 2020 12:22:56 +0200 Subject: [PATCH 2/4] merge `as_local_hir_id` with `local_def_id_to_hir_id` --- src/librustc_codegen_llvm/consts.rs | 2 +- .../back/symbol_export.rs | 2 +- src/librustc_hir/definitions.rs | 5 --- .../infer/error_reporting/mod.rs | 11 ++++--- .../nice_region_error/find_anon_type.rs | 2 +- .../trait_impl_difference.rs | 3 +- .../error_reporting/nice_region_error/util.rs | 2 +- src/librustc_lint/builtin.rs | 4 +-- src/librustc_lint/late.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 20 ++++++------ src/librustc_middle/dep_graph/mod.rs | 2 +- src/librustc_middle/hir/map/mod.rs | 11 ++----- src/librustc_middle/hir/mod.rs | 6 ++-- src/librustc_middle/mir/mod.rs | 4 +-- src/librustc_middle/mir/mono.rs | 13 ++++---- src/librustc_middle/query/mod.rs | 2 +- src/librustc_middle/ty/consts.rs | 2 +- src/librustc_middle/ty/context.rs | 6 ++-- src/librustc_middle/ty/error.rs | 11 ++++--- src/librustc_middle/ty/mod.rs | 10 +++--- src/librustc_middle/ty/print/pretty.rs | 4 +-- src/librustc_middle/ty/util.rs | 2 +- .../diagnostics/conflict_errors.rs | 6 ++-- .../borrow_check/diagnostics/mod.rs | 6 ++-- .../diagnostics/mutability_errors.rs | 4 +-- .../borrow_check/diagnostics/region_name.rs | 8 ++--- 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 +- .../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 | 6 ++-- .../transform/qualify_min_const_fn.rs | 2 +- src/librustc_mir_build/build/mod.rs | 2 +- src/librustc_mir_build/lints.rs | 4 +-- src/librustc_mir_build/thir/cx/expr.rs | 2 +- .../thir/pattern/check_match.rs | 2 +- src/librustc_passes/dead.rs | 8 ++--- src/librustc_passes/reachable.rs | 20 ++++++------ src/librustc_passes/region.rs | 2 +- src/librustc_passes/upvars.rs | 2 +- src/librustc_privacy/lib.rs | 18 +++++------ src/librustc_resolve/late/lifetimes.rs | 15 +++++---- src/librustc_symbol_mangling/lib.rs | 2 +- src/librustc_trait_selection/opaque_types.rs | 4 +-- .../traits/chalk_fulfill.rs | 2 +- .../traits/error_reporting/mod.rs | 3 +- .../traits/error_reporting/suggestions.rs | 6 ++-- .../traits/specialize/mod.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 | 32 +++++++++---------- src/librustc_typeck/check/dropck.rs | 4 +-- src/librustc_typeck/check/expr.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 10 +++--- src/librustc_typeck/check/mod.rs | 20 ++++++------ src/librustc_typeck/check/op.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 8 ++--- src/librustc_typeck/check/writeback.rs | 2 +- src/librustc_typeck/check_unused.rs | 4 +-- src/librustc_typeck/coherence/builtin.rs | 8 ++--- src/librustc_typeck/collect.rs | 28 ++++++++-------- src/librustc_typeck/collect/type_of.rs | 10 +++--- .../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 | 8 ++--- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/utils.rs | 2 +- src/librustdoc/core.rs | 6 ++-- src/librustdoc/html/markdown.rs | 2 +- .../passes/collect_intra_doc_links.rs | 4 +-- src/librustdoc/visit_ast.rs | 2 +- src/tools/clippy/clippy_lints/src/derive.rs | 8 ++--- .../clippy_lints/src/new_without_default.rs | 2 +- 82 files changed, 241 insertions(+), 237 deletions(-) diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 024834bfe2aa5..0c749657001a6 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -215,7 +215,7 @@ impl CodegenCx<'ll, 'tcx> { debug!("get_static: sym={} instance={:?}", sym, instance); let g = if let Some(def_id) = def_id.as_local() { - let id = self.tcx.hir().as_local_hir_id(def_id); + let id = self.tcx.hir().local_def_id_to_hir_id(def_id); let llty = self.layout_of(ty).llvm_type(self); // FIXME: refactor this to work without accessing the HIR 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 7d742e7a7afd2..a9ffd416485ca 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -370,7 +370,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)) + !tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().local_def_id_to_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 79b7068273932..caa86b54fdfd8 100644 --- a/src/librustc_hir/definitions.rs +++ b/src/librustc_hir/definitions.rs @@ -306,11 +306,6 @@ impl Definitions { }) } - #[inline] - pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId { - self.local_def_id_to_hir_id(def_id) - } - #[inline] pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId { self.def_id_to_hir_id[id].unwrap() diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index 063246f79fe36..2b2c42207e48b 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -144,7 +144,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()); + let node = tcx.hir().local_def_id_to_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), @@ -1707,7 +1707,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { .in_progress_typeck_results .map(|typeck_results| typeck_results.borrow().hir_owner) .map(|owner| { - let hir_id = hir.as_local_hir_id(owner); + let hir_id = hir.local_def_id_to_hir_id(owner); let parent_id = hir.get_parent_item(hir_id); ( // Parent item could be a `mod`, so we check the HIR before calling: @@ -1733,7 +1733,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); + let id = hir.local_def_id_to_hir_id(def_id); let mut has_bounds = false; if let Node::GenericParam(param) = hir.get(id) { has_bounds = !param.bounds.is_empty(); @@ -1786,7 +1786,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { .and_then(|(_, g)| g.params.first()) .and_then(|param| param.def_id.as_local()) .map(|def_id| { - (hir.span(hir.as_local_hir_id(def_id)).shrink_to_lo(), format!("{}, ", new_lt)) + ( + hir.span(hir.local_def_id_to_hir_id(def_id)).shrink_to_lo(), + format!("{}, ", new_lt), + ) }); let labeled_user_string = match bound_kind { 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 20617bb8bd8fc..eb1521f056576 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 @@ -28,7 +28,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { br: &ty::BoundRegion, ) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> { if let Some(anon_reg) = self.tcx().is_suitable_region(region) { - let hir_id = self.tcx().hir().as_local_hir_id(anon_reg.def_id); + let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id); let fndecl = match self.tcx().hir().get(hir_id) { Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) | Node::TraitItem(&hir::TraitItem { diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs index 1ddf88c030660..788eabf296d76 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -67,7 +67,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { match assoc_item.kind { ty::AssocKind::Fn => { let hir = self.tcx().hir(); - if let Some(hir_id) = assoc_item.def_id.as_local().map(|id| hir.as_local_hir_id(id)) + if let Some(hir_id) = + assoc_item.def_id.as_local().map(|id| hir.local_def_id_to_hir_id(id)) { if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) { visitor.visit_fn_decl(decl); 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 28e9dd90cfd67..6e2d49f1ad792 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 @@ -49,7 +49,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.local_def_id_to_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 c42794e00b41e..ac3a9937dbad8 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -440,7 +440,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { // reported for missing docs. let real_trait = trait_ref.path.res.def_id(); if let Some(def_id) = real_trait.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(def_id); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) { if let hir::VisibilityKind::Inherited = item.vis.node { for impl_item_ref in items { @@ -614,7 +614,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations { cx.tcx.for_each_impl(debug, |d| { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { if let Some(def_id) = ty_def.did.as_local() { - impls.insert(cx.tcx.hir().as_local_hir_id(def_id)); + impls.insert(cx.tcx.hir().local_def_id_to_hir_id(def_id)); } } }); diff --git a/src/librustc_lint/late.rs b/src/librustc_lint/late.rs index f43c197d2d201..4a612b89cac22 100644 --- a/src/librustc_lint/late.rs +++ b/src/librustc_lint/late.rs @@ -379,7 +379,7 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'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), + last_node_with_lint_attrs: tcx.hir().local_def_id_to_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 6723e236a1fe9..76e395f2f1e2c 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -733,7 +733,7 @@ impl EncodeContext<'a, 'tcx> { is_non_exhaustive: variant.is_field_list_non_exhaustive(), }; - let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local()); + let enum_id = tcx.hir().local_def_id_to_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))); @@ -780,7 +780,7 @@ impl EncodeContext<'a, '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()); + let enum_id = tcx.hir().local_def_id_to_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 { @@ -819,11 +819,11 @@ impl EncodeContext<'a, 'tcx> { let data = ModData { reexports: match tcx.module_exports(local_def_id) { Some(exports) => { - let hir_map = self.tcx.hir(); + let hir = self.tcx.hir(); self.lazy( exports .iter() - .map(|export| export.map_id(|id| hir_map.as_local_hir_id(id))), + .map(|export| export.map_id(|id| hir.local_def_id_to_hir_id(id))), ) } _ => Lazy::empty(), @@ -855,7 +855,7 @@ impl EncodeContext<'a, '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()); + let variant_id = tcx.hir().local_def_id_to_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); @@ -883,7 +883,7 @@ impl EncodeContext<'a, 'tcx> { is_non_exhaustive: variant.is_field_list_non_exhaustive(), }; - let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local()); + let struct_id = tcx.hir().local_def_id_to_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 { @@ -945,7 +945,7 @@ impl EncodeContext<'a, '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()); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let ast_item = tcx.hir().expect_trait_item(hir_id); let trait_item = tcx.associated_item(def_id); @@ -1034,7 +1034,7 @@ impl EncodeContext<'a, '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()); + let hir_id = self.tcx.hir().local_def_id_to_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); @@ -1438,7 +1438,7 @@ impl EncodeContext<'a, '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. - let hir_id = self.tcx.hir().as_local_hir_id(def_id); + let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let ty = self.tcx.typeck(def_id).node_type(hir_id); record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind { @@ -1465,7 +1465,7 @@ impl EncodeContext<'a, '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); + let id = self.tcx.hir().local_def_id_to_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 qualifs = self.tcx.mir_const_qualif(def_id); diff --git a/src/librustc_middle/dep_graph/mod.rs b/src/librustc_middle/dep_graph/mod.rs index 682b335c5d071..6697524279874 100644 --- a/src/librustc_middle/dep_graph/mod.rs +++ b/src/librustc_middle/dep_graph/mod.rs @@ -185,6 +185,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); + let hir_id = tcx.hir().local_def_id_to_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 250f4d5187f2f..0794caca1baa5 100644 --- a/src/librustc_middle/hir/map/mod.rs +++ b/src/librustc_middle/hir/map/mod.rs @@ -173,11 +173,6 @@ impl<'hir> Map<'hir> { self.tcx.definitions.opt_hir_id_to_local_def_id(hir_id) } - #[inline] - pub fn as_local_hir_id(&self, def_id: LocalDefId) -> HirId { - self.tcx.definitions.as_local_hir_id(def_id) - } - #[inline] pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId { self.tcx.definitions.local_def_id_to_hir_id(def_id) @@ -450,7 +445,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); + let hir_id = self.local_def_id_to_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), @@ -483,7 +478,7 @@ impl<'hir> Map<'hir> { } pub fn get_if_local(&self, id: DefId) -> Option> { - id.as_local().map(|id| self.get(self.as_local_hir_id(id))) + id.as_local().map(|id| self.get(self.local_def_id_to_hir_id(id))) } pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> { @@ -872,7 +867,7 @@ impl<'hir> Map<'hir> { } pub fn span_if_local(&self, id: DefId) -> Option { - id.as_local().map(|id| self.span(self.as_local_hir_id(id))) + id.as_local().map(|id| self.span(self.local_def_id_to_hir_id(id))) } pub fn res_span(&self, res: Res) -> Option { diff --git a/src/librustc_middle/hir/mod.rs b/src/librustc_middle/hir/mod.rs index b014f3c8eb794..ae3b30217cc4a 100644 --- a/src/librustc_middle/hir/mod.rs +++ b/src/librustc_middle/hir/mod.rs @@ -66,20 +66,20 @@ 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))) + hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_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); + let module = hir.local_def_id_to_hir_id(id); &tcx.untracked_crate.modules[&module] }; providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature; providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref(); providers.fn_arg_names = |tcx, id| { let hir = tcx.hir(); - let hir_id = hir.as_local_hir_id(id.expect_local()); + let hir_id = hir.local_def_id_to_hir_id(id.expect_local()); if let Some(body_id) = hir.maybe_body_owned_by(hir_id) { tcx.arena.alloc_from_iter(hir.body_param_names(body_id)) } else if let Node::TraitItem(&TraitItem { diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 3b0c480f6d400..0a253e777dd9b 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -2127,7 +2127,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| { if let Some(def_id) = def_id.as_local() { - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let name = if tcx.sess.opts.debugging_opts.span_free_formats { let substs = tcx.lift(&substs).unwrap(); format!( @@ -2155,7 +2155,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| { if let Some(def_id) = def_id.as_local() { - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_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 bb204223b6060..d240ae65b6dff 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)) + def.def_id().as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) } MonoItem::Static(def_id) => { - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) + def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) } MonoItem::GlobalAsm(hir_id) => Some(hir_id), } @@ -346,9 +346,10 @@ 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) => { - def.did.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) - } + InstanceDef::Item(def) => def + .did + .as_local() + .map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)), InstanceDef::VtableShim(..) | InstanceDef::ReifyShim(..) | InstanceDef::Intrinsic(..) @@ -360,7 +361,7 @@ impl<'tcx> CodegenUnit<'tcx> { } } MonoItem::Static(def_id) => { - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) + def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_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 a8f6723a35605..d364a46463821 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -352,7 +352,7 @@ rustc_queries! { /// per-type-parameter predicates for resolving `T::AssocTy`. query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> { desc { |tcx| "computing the bounds for type parameter `{}`", { - let id = tcx.hir().as_local_hir_id(key.1); + let id = tcx.hir().local_def_id_to_hir_id(key.1); tcx.hir().ty_param_name(id) }} } diff --git a/src/librustc_middle/ty/consts.rs b/src/librustc_middle/ty/consts.rs index c0b5693dc594e..2e10c79598450 100644 --- a/src/librustc_middle/ty/consts.rs +++ b/src/librustc_middle/ty/consts.rs @@ -88,7 +88,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()); + let hir_id = tcx.hir().local_def_id_to_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_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index d6bcfbf49cff1..4f990ece4d796 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1420,7 +1420,7 @@ impl<'tcx> TyCtxt<'tcx> { _ => return None, // not a free region }; - let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope); + let hir_id = self.hir().local_def_id_to_hir_id(suitable_region_binding_scope); let is_impl_item = match self.hir().find(hir_id) { Some(Node::Item(..) | Node::TraitItem(..)) => false, Some(Node::ImplItem(..)) => { @@ -1441,7 +1441,7 @@ impl<'tcx> TyCtxt<'tcx> { &self, scope_def_id: LocalDefId, ) -> Vec<&'tcx hir::Ty<'tcx>> { - let hir_id = self.hir().as_local_hir_id(scope_def_id); + let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id); let hir_output = match self.hir().get(hir_id) { Node::Item(hir::Item { kind: @@ -1486,7 +1486,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn return_type_impl_trait(&self, scope_def_id: LocalDefId) -> 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); + let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id); match self.hir().get(hir_id) { Node::Item(item) => { match item.kind { diff --git a/src/librustc_middle/ty/error.rs b/src/librustc_middle/ty/error.rs index 30ff5a2d9ebdf..438da832226d7 100644 --- a/src/librustc_middle/ty/error.rs +++ b/src/librustc_middle/ty/error.rs @@ -403,7 +403,7 @@ impl<'tcx> TyCtxt<'tcx> { .type_param(p, self) .def_id .as_local() - .map(|id| hir.as_local_hir_id(id)) + .map(|id| hir.local_def_id_to_hir_id(id)) .and_then(|id| self.hir().find(self.hir().get_parent_node(id))) .as_ref() .and_then(|node| node.generics()) @@ -791,10 +791,11 @@ fn foo(&self) -> Self::T { String::new() } body_owner_def_id: DefId, found: Ty<'tcx>, ) -> bool { - let hir_id = match body_owner_def_id.as_local().map(|id| self.hir().as_local_hir_id(id)) { - Some(hir_id) => hir_id, - None => return false, - }; + let hir_id = + match body_owner_def_id.as_local().map(|id| self.hir().local_def_id_to_hir_id(id)) { + Some(hir_id) => hir_id, + None => return false, + }; // When `body_owner` is an `impl` or `trait` item, look in its associated types for // `expected` and point at it. let parent_id = self.hir().get_parent_item(hir_id); diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 6798addb8aaa3..85c4cd91ebdac 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -2845,12 +2845,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)).ident()) + .and_then(|def_id| self.hir().get(self.hir().local_def_id_to_hir_id(def_id)).ident()) } pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> { 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)) { + match self.hir().get(self.hir().local_def_id_to_hir_id(def_id)) { Node::TraitItem(_) | Node::ImplItem(_) => true, _ => false, } @@ -3009,7 +3009,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)) + self.hir().attrs(self.hir().local_def_id_to_hir_id(did)) } else { self.item_attrs(did) } @@ -3048,7 +3048,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); + let hir_id = self.hir().local_def_id_to_hir_id(impl_did); Ok(self.hir().span(hir_id)) } else { Err(self.crate_name(impl_did.krate)) @@ -3109,7 +3109,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)) { + if let Node::Item(item) = tcx.hir().get(tcx.hir().local_def_id_to_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 87944db60de66..fc444d4cc5b52 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -610,7 +610,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) should use `def_span`. if let Some(did) = did.as_local() { - let hir_id = self.tcx().hir().as_local_hir_id(did); + let hir_id = self.tcx().hir().local_def_id_to_hir_id(did); let span = self.tcx().hir().span(hir_id); p!(write("@{}", self.tcx().sess.source_map().span_to_string(span))); @@ -656,7 +656,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) should use `def_span`. if let Some(did) = did.as_local() { - let hir_id = self.tcx().hir().as_local_hir_id(did); + let hir_id = self.tcx().hir().local_def_id_to_hir_id(did); if self.tcx().sess.opts.debugging_opts.span_free_formats { p!(write("@"), print_def_path(did.to_def_id(), substs)); } else { diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index 07221082048fb..3e5eaca5417f7 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -879,7 +879,7 @@ impl<'tcx> ty::TyS<'tcx> { let span = match field .did .as_local() - .map(|id| tcx.hir().as_local_hir_id(id)) + .map(|id| tcx.hir().local_def_id_to_hir_id(id)) .and_then(|id| tcx.hir().find(id)) { Some(hir::Node::Field(field)) => field.ty.span, diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index 8e7c97c4a1bac..7a50bdfeef625 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -263,7 +263,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let needs_note = match ty.kind { ty::Closure(id, _) => { let tables = self.infcx.tcx.typeck(id.expect_local()); - let hir_id = self.infcx.tcx.hir().as_local_hir_id(id.expect_local()); + let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(id.expect_local()); tables.closure_kind_origins().get(hir_id).is_none() } @@ -954,7 +954,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { format!("`{}` would have to be valid for `{}`...", name, region_name), ); - let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id); + let fn_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id); err.span_label( drop_span, format!( @@ -1863,7 +1863,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().local_def_id_to_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 ba74ffaa8d620..daffdec2a83be 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mod.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mod.rs @@ -104,7 +104,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 did = did.expect_local(); - let hir_id = self.infcx.tcx.hir().as_local_hir_id(did); + let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did); if let Some((span, name)) = self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id) @@ -127,7 +127,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if let Some(target) = target { if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind { let did = did.expect_local(); - let hir_id = self.infcx.tcx.hir().as_local_hir_id(did); + let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did); if let Some((span, name)) = self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id) @@ -937,7 +937,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().local_def_id_to_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 ef0fe71abecb2..d26436ff1de54 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); + let closure_id = hir.local_def_id_to_hir_id(self.mir_def_id); let fn_call_id = hir.get_parent_node(closure_id); let node = hir.get(fn_call_id); let item_id = hir.enclosing_body_owner(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().local_def_id_to_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 32195adc60ef8..2603b1e048d81 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_name.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_name.rs @@ -266,7 +266,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { } ty::BoundRegion::BrEnv => { - let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id); + let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id); let def_ty = self.regioncx.universal_regions().defining_ty; if let DefiningTy::Closure(_, substs) = def_ty { @@ -361,7 +361,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { &self, argument_index: usize, ) -> Option<&hir::Ty<'tcx>> { - let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id); + let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id); 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 { @@ -648,7 +648,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); + let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id); let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) { hir::Node::Expr(hir::Expr { @@ -700,7 +700,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); + let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id); 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 6e211b42a052e..f7031b2a59848 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -129,7 +129,7 @@ fn do_mir_borrowck<'a, 'tcx>( let tcx = infcx.tcx; let param_env = tcx.param_env(def.did); - let id = tcx.hir().as_local_hir_id(def.did); + let id = tcx.hir().local_def_id_to_hir_id(def.did); 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 c5aa5c5ebc7f2..cd6b75cf55602 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -231,7 +231,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.did); + let mir_hir_id = tcx.hir().local_def_id_to_hir_id(mir_def.did); UniversalRegionsBuilder { infcx, mir_def, 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 7fbe5c409d3ce..21915767057d0 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -347,7 +347,7 @@ pub fn const_eval_raw_provider<'tcx>( // validation thus preventing such a hard error from being a backwards // compatibility hazard DefKind::Const | DefKind::AssocConst => { - let hir_id = tcx.hir().as_local_hir_id(def.did); + let hir_id = tcx.hir().local_def_id_to_hir_id(def.did); err.report_as_lint( tcx.at(tcx.def_span(def.did)), "any use of this value will cause an error", @@ -370,7 +370,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.did), + tcx.hir().local_def_id_to_hir_id(def.did), Some(err.span), ) } diff --git a/src/librustc_mir/const_eval/fn_queries.rs b/src/librustc_mir/const_eval/fn_queries.rs index 70ddd79ee40b0..9ef63b3322dd5 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 has a `rustc_const_{un,}stable` attribute. fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool { - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index f64c72e7b362d..526c896df093c 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -215,7 +215,7 @@ impl Validator<'mir, 'tcx> { && !tcx.is_thread_local_static(def_id.to_def_id()); if should_check_for_sync { - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); 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 9c06e173bcd57..d2a5616b8ed34 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -483,7 +483,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)); + let body_id = tcx.hir().maybe_body_owned_by(tcx.hir().local_def_id_to_hir_id(def_id)); let body_id = match body_id { Some(body) => body, @@ -511,7 +511,7 @@ fn unsafety_check_result<'tcx>( let param_env = tcx.param_env(def.did); - let id = tcx.hir().as_local_hir_id(def.did); + let id = tcx.hir().local_def_id_to_hir_id(def.did); let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Closure => (false, false), hir::BodyOwnerKind::Fn => { @@ -532,7 +532,7 @@ fn unsafety_check_result<'tcx>( } fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) { - let lint_hir_id = tcx.hir().as_local_hir_id(def_id); + let lint_hir_id = tcx.hir().local_def_id_to_hir_id(def_id); 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 6cf296f2a3fda..8920cb44942d6 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -67,7 +67,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()); + let hir_id = tcx.hir().local_def_id_to_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 = tcx.def_kind(source.def_id()) == DefKind::AssocConst; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 92ea162e419db..315d4fa9d477d 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -75,7 +75,7 @@ impl Inliner<'tcx> { let param_env = self.tcx.param_env_reveal_all_normalized(self.source.def_id()); // Only do inlining into fn bodies. - let id = self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local()); + let id = self.tcx.hir().local_def_id_to_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) = @@ -101,9 +101,9 @@ impl Inliner<'tcx> { } 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 callee_hir_id = self.tcx.hir().local_def_id_to_hir_id(callee_def_id); let self_hir_id = - self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local()); + self.tcx.hir().local_def_id_to_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 dfd01e27d57c9..7abb09885ffd3 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -14,7 +14,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()); + let hir_id = tcx.hir().local_def_id_to_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_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index f3f3c3e33a46d..4d879469d48b8 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -35,7 +35,7 @@ crate fn mir_built<'tcx>( /// Construct the MIR for a given `DefId`. fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_> { - let id = tcx.hir().as_local_hir_id(def.did); + let id = tcx.hir().local_def_id_to_hir_id(def.did); // 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/lints.rs b/src/librustc_mir_build/lints.rs index ac5d128a1baa2..662b6c7735747 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: LocalDefId) { - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); 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: LocalDefId) { vis.reachable_recursive_calls.sort(); - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); 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_mir_build/thir/cx/expr.rs b/src/librustc_mir_build/thir/cx/expr.rs index ea41a66b3e43d..c51c3bcf56288 100644 --- a/src/librustc_mir_build/thir/cx/expr.rs +++ b/src/librustc_mir_build/thir/cx/expr.rs @@ -781,7 +781,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()); + let hir_id = cx.tcx.hir().local_def_id_to_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/thir/pattern/check_match.rs b/src/librustc_mir_build/thir/pattern/check_match.rs index 744f319205f94..1687286093d9c 100644 --- a/src/librustc_mir_build/thir/pattern/check_match.rs +++ b/src/librustc_mir_build/thir/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)), + Some(id) => tcx.hir().body_owned_by(tcx.hir().local_def_id_to_hir_id(id)), }; let mut visitor = MatchVisitor { diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index 0e5298acc2caf..29939c7cfafb0 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -62,7 +62,7 @@ impl<'tcx> MarkSymbolVisitor<'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); + let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); if should_explore(self.tcx, hir_id) || self.struct_constructors.contains_key(&hir_id) { self.worklist.push(hir_id); } @@ -72,7 +72,7 @@ impl<'tcx> MarkSymbolVisitor<'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); + let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); debug_assert!(!should_explore(self.tcx, hir_id)); self.live_symbols.insert(hir_id); } @@ -461,7 +461,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)), + tcx.entry_fn(LOCAL_CRATE).map(|(def_id, _)| tcx.hir().local_def_id_to_hir_id(def_id)), ) .collect::>(); @@ -546,7 +546,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(did) = item_did.as_local() { - let item_hir_id = self.tcx.hir().as_local_hir_id(did); + let item_hir_id = self.tcx.hir().local_def_id_to_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 c71dbdf515aa9..18fa4ada4dadd 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -53,7 +53,7 @@ fn method_might_be_inlined( return true; } } - match tcx.hir().find(tcx.hir().as_local_hir_id(impl_src)) { + match tcx.hir().find(tcx.hir().local_def_id_to_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"), } @@ -106,7 +106,9 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'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), def_id)) + def_id + .as_local() + .map(|def_id| (self.tcx.hir().local_def_id_to_hir_id(def_id), def_id)) }) { if self.def_id_represents_local_inlined_item(def_id.to_def_id()) { self.worklist.push(hir_id); @@ -149,7 +151,7 @@ impl<'tcx> ReachableContext<'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), + Some(def_id) => self.tcx.hir().local_def_id_to_hir_id(def_id), None => { return false; } @@ -181,7 +183,7 @@ impl<'tcx> ReachableContext<'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); + let impl_hir_id = self.tcx.hir().local_def_id_to_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); @@ -366,10 +368,10 @@ 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())), - ); + self.worklist + .extend(tcx.provided_trait_methods(trait_def_id).map(|assoc| { + tcx.hir().local_def_id_to_hir_id(assoc.def_id.expect_local()) + })); } } } @@ -406,7 +408,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)) { + if let Some(hir_id) = did.as_local().map(|did| tcx.hir().local_def_id_to_hir_id(did)) { reachable_context.worklist.push(hir_id); } } diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index b2a89651881e5..1af79abe4b911 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()); + let id = tcx.hir().local_def_id_to_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 3aed4942563dd..91b8ae07637df 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()); + let hir_id = tcx.hir().local_def_id_to_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 3ba5acd00a09a..a5536942581be 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -226,7 +226,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)) { + match def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) { Some(hir_id) => { let vis = match tcx.hir().get(hir_id) { Node::Item(item) => &item.vis, @@ -431,7 +431,7 @@ impl VisibilityLike for Option { fn new_min(find: &FindMin<'_, '_, Self>, def_id: DefId) -> Self { cmp::min( if let Some(def_id) = def_id.as_local() { - let hir_id = find.tcx.hir().as_local_hir_id(def_id); + let hir_id = find.tcx.hir().local_def_id_to_hir_id(def_id); find.access_levels.map.get(&hir_id).cloned() } else { Self::MAX @@ -533,7 +533,7 @@ impl EmbargoVisitor<'tcx> { if let Res::Def(def_kind, def_id) = export.res { let vis = def_id_visibility(self.tcx, def_id).0; if let Some(def_id) = def_id.as_local() { - let hir_id = self.tcx.hir().as_local_hir_id(def_id); + let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod); } } @@ -650,7 +650,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)) + def_id.as_local().map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id)) }) .map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id)) { @@ -913,7 +913,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { if export.vis == ty::Visibility::Public { if let Some(def_id) = export.res.opt_def_id() { if let Some(def_id) = def_id.as_local() { - let hir_id = self.tcx.hir().as_local_hir_id(def_id); + let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); self.update(hir_id, Some(AccessLevel::Exported)); } } @@ -1004,7 +1004,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); + let hir_id = self.ev.tcx.hir().local_def_id_to_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) @@ -1437,7 +1437,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)) { + match self.tcx.hir().find(self.tcx.hir().local_def_id_to_hir_id(did)) { Some(Node::Item(ref item)) => !item.vis.node.is_pub(), Some(_) | None => false, } @@ -1556,7 +1556,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)) + self.trait_is_public(self.tcx.hir().local_def_id_to_hir_id(did)) } else { true // external traits must be public } @@ -1815,7 +1815,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> { } let hir_id = match def_id.as_local() { - Some(def_id) => self.tcx.hir().as_local_hir_id(def_id), + Some(def_id) => self.tcx.hir().local_def_id_to_hir_id(def_id), None => return false, }; diff --git a/src/librustc_resolve/late/lifetimes.rs b/src/librustc_resolve/late/lifetimes.rs index 0b881b089deaa..bde72f751af8b 100644 --- a/src/librustc_resolve/late/lifetimes.rs +++ b/src/librustc_resolve/late/lifetimes.rs @@ -607,7 +607,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { let def = self.map.defs.get(&lifetime.hir_id).cloned(); if let Some(Region::LateBound(_, def_id, _)) = def { if let Some(def_id) = def_id.as_local() { - let hir_id = self.tcx.hir().as_local_hir_id(def_id); + let hir_id = self.tcx.hir().local_def_id_to_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); let parent_impl_id = hir::ImplItemId { hir_id: parent_id }; @@ -1146,7 +1146,8 @@ 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()); + let hir_id = + tcx.hir().local_def_id_to_hir_id(def.id().unwrap().expect_local()); signal_shadowing_problem( tcx, @@ -1517,7 +1518,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()); + let hir_id = self.tcx.hir().local_def_id_to_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(( @@ -1537,7 +1538,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { if let Some(parent_def_id) = self.tcx.parent(def_id) { if let Some(def_id) = parent_def_id.as_local() { - let parent_hir_id = self.tcx.hir().as_local_hir_id(def_id); + let parent_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); // lifetimes in `derive` expansions don't count (Issue #53738) if self.tcx.hir().attrs(parent_hir_id).iter().any(|attr| { self.tcx.sess.check_name(attr, sym::automatically_derived) @@ -1575,7 +1576,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()); + let hir_id = self.tcx.hir().local_def_id_to_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, @@ -1931,7 +1932,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let map = &self.map; let unsubst = if let Some(def_id) = def_id.as_local() { - let id = self.tcx.hir().as_local_hir_id(def_id); + let id = self.tcx.hir().local_def_id_to_hir_id(def_id); &map.object_lifetime_defaults[&id] } else { let tcx = self.tcx; @@ -2614,7 +2615,7 @@ 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()); + self.tcx.hir().local_def_id_to_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 2579cf53d3d50..32e5aef00f8b8 100644 --- a/src/librustc_symbol_mangling/lib.rs +++ b/src/librustc_symbol_mangling/lib.rs @@ -173,7 +173,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); + let hir_id = tcx.hir().local_def_id_to_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 b84ad93341e81..379c976df69e3 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -1039,7 +1039,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { // } // ``` if let Some(def_id) = def_id.as_local() { - let opaque_hir_id = tcx.hir().as_local_hir_id(def_id); + let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let parent_def_id = self.parent_def_id; let def_scope_default = || { let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id); @@ -1205,7 +1205,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); + let mut hir_id = tcx.hir().local_def_id_to_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/chalk_fulfill.rs b/src/librustc_trait_selection/traits/chalk_fulfill.rs index a75240042ad76..0097097707f32 100644 --- a/src/librustc_trait_selection/traits/chalk_fulfill.rs +++ b/src/librustc_trait_selection/traits/chalk_fulfill.rs @@ -41,7 +41,7 @@ fn environment<'tcx>( let clauses = predicates.into_iter().map(ChalkEnvironmentClause::Predicate); - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); enum NodeKind { diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index 349fa68a4da99..e597843e6ce91 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -568,7 +568,8 @@ 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()); + let hir_id = + self.tcx.hir().local_def_id_to_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 e29e740f13669..7513ff6b37ef8 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -535,7 +535,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.local_def_id_to_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), .. })) => { @@ -1383,7 +1383,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)) + .map(|def_id| hir.local_def_id_to_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(); @@ -1535,7 +1535,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { .tcx .parent(generator_did) .and_then(|parent_did| parent_did.as_local()) - .map(|parent_did| hir.as_local_hir_id(parent_did)) + .map(|parent_did| hir.local_def_id_to_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 9b737d464174a..4d81a3baa0edc 100644 --- a/src/librustc_trait_selection/traits/specialize/mod.rs +++ b/src/librustc_trait_selection/traits/specialize/mod.rs @@ -451,7 +451,7 @@ fn report_conflicting_impls( }; tcx.struct_span_lint_hir( lint, - tcx.hir().as_local_hir_id(impl_def_id), + tcx.hir().local_def_id_to_hir_id(impl_def_id), impl_span, decorate, ) diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index b31f9f3c7b14f..0f1dee7e2e006 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -126,7 +126,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()); + let id = tcx.hir().local_def_id_to_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); @@ -164,7 +164,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()); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let item = tcx.hir().expect_item(hir_id); if let hir::ItemKind::Impl { defaultness, .. } = item.kind { defaultness @@ -198,7 +198,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()); + let id = tcx.hir().local_def_id_to_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( @@ -268,7 +268,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)) + .map(|def_id| tcx.hir().local_def_id_to_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) }); @@ -360,7 +360,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()); + let hir_id = tcx.hir().local_def_id_to_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 2be100ae33662..b6730328a28a6 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -170,7 +170,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)); + let lifetime_name = |def_id| tcx.hir().name(tcx.hir().local_def_id_to_hir_id(def_id)); let r = match tcx.named_region(lifetime.hir_id) { Some(rl::Region::Static) => tcx.lifetimes.re_static, @@ -2099,7 +2099,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); + let param_hir_id = tcx.hir().local_def_id_to_hir_id(ty_param_def_id); let param_name = tcx.hir().ty_param_name(param_hir_id); self.one_bound_for_assoc_type( || { @@ -2483,7 +2483,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)) + def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) }) .map(|hir_id| tcx.hir().get_parent_did(hir_id).to_def_id()); @@ -2819,7 +2819,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()); + let hir_id = tcx.hir().local_def_id_to_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 db8cdfc5b20d6..f0802c45ae030 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -1502,7 +1502,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()); + let hir_id = fcx.tcx.hir().local_def_id_to_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 b739e2fe1fbc4..7adcd7b472e0d 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -77,7 +77,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()); + let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.expect_local()); // We sometimes modify the span further down. let mut cause = ObligationCause::new( @@ -401,7 +401,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()); + let impl_m_hir_id = tcx.hir().local_def_id_to_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()) @@ -412,7 +412,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( match *terr { TypeError::Mutability => { if let Some(def_id) = trait_m.def_id.as_local() { - let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id); + let trait_m_hir_id = tcx.hir().local_def_id_to_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(), _ => bug!("{:?} is not a TraitItemKind::Fn", trait_m), @@ -440,7 +440,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( } TypeError::Sorts(ExpectedFound { .. }) => { if let Some(def_id) = trait_m.def_id.as_local() { - let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id); + let trait_m_hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let (trait_m_output, trait_m_iter) = match tcx.hir().expect_trait_item(trait_m_hir_id).kind { TraitItemKind::Fn(ref trait_m_sig, _) => { @@ -589,7 +589,7 @@ fn compare_number_of_generics<'tcx>( err_occurred = true; let (trait_spans, impl_trait_spans) = if let Some(def_id) = trait_.def_id.as_local() { - let trait_hir_id = tcx.hir().as_local_hir_id(def_id); + let trait_hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let trait_item = tcx.hir().expect_trait_item(trait_hir_id); if trait_item.generics.params.is_empty() { (Some(vec![trait_item.generics.span]), vec![]) @@ -614,7 +614,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()); + let impl_hir_id = tcx.hir().local_def_id_to_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 @@ -706,7 +706,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); + let trait_id = tcx.hir().local_def_id_to_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 }; @@ -729,7 +729,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()); + let impl_m_hir_id = tcx.hir().local_def_id_to_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 }; @@ -811,7 +811,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()); + let impl_hir_id = tcx.hir().local_def_id_to_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!( @@ -832,10 +832,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().local_def_id_to_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().local_def_id_to_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 @@ -869,7 +869,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().local_def_id_to_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, @@ -962,7 +962,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()); + let impl_c_hir_id = tcx.hir().local_def_id_to_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)); + trait_c.def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_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 { @@ -1101,7 +1101,7 @@ fn compare_type_predicate_entailment<'tcx>( // 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()); + let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()); let cause = ObligationCause::new( impl_ty_span, impl_ty_hir_id, @@ -1240,7 +1240,7 @@ fn compare_projection_bounds<'tcx>( let infcx = &inh.infcx; let mut selcx = traits::SelectionContext::new(&infcx); - let impl_ty_hir_id = tcx.hir().as_local_hir_id(impl_ty.def_id.expect_local()); + let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()); let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_hir_id); let cause = ObligationCause::new( impl_ty_span, diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 9ef9164191675..434886538fb4d 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -70,7 +70,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); + let drop_impl_hir_id = tcx.hir().local_def_id_to_hir_id(drop_impl_did); // check that the impl type can be made to match the trait type. @@ -183,7 +183,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); + let self_type_hir_id = tcx.hir().local_def_id_to_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 e7eaca62bdd8e..e88f13a1f3ab6 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1606,7 +1606,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), + Some(x) => self.tcx.hir().local_def_id_to_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 e69102d1995d3..e941c844a6d90 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -579,7 +579,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { if let ty::Adt(def, _) = p.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)) + self.tcx + .hir() + .get(self.tcx.hir().local_def_id_to_hir_id(def_id)) }); if let Some(hir::Node::Item(hir::Item { kind, .. })) = node { if let Some(g) = kind.generics() { @@ -859,7 +861,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); + let module_id = self.tcx.hir().local_def_id_to_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 { @@ -975,7 +977,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let id = item .def_id .as_local() - .map(|def_id| self.tcx.hir().as_local_hir_id(def_id)); + .map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id)); if let Some(hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(fn_sig, method), .. @@ -1062,7 +1064,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let type_param = generics.type_param(param, self.tcx); let hir = &self.tcx.hir(); if let Some(def_id) = type_param.def_id.as_local() { - let id = hir.as_local_hir_id(def_id); + let id = hir.local_def_id_to_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`, // instead we suggest `T: Foo + Bar` in that case. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a40b6860f7765..66400743e9528 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -974,7 +974,7 @@ fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tc /// Currently only used for type inference of `static`s and `const`s to avoid type cycle errors. fn diagnostic_only_typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tcx> { let fallback = move || { - let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id)); + let span = tcx.hir().span(tcx.hir().local_def_id_to_hir_id(def_id)); tcx.ty_error_with_message(span, "diagnostic only typeck table used") }; typeck_with_fallback(tcx, def_id, fallback) @@ -992,7 +992,7 @@ fn typeck_with_fallback<'tcx>( return tcx.typeck(outer_def_id); } - let id = tcx.hir().as_local_hir_id(def_id); + let id = tcx.hir().local_def_id_to_hir_id(def_id); 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()).expect_local(); - let outer_hir_id = hir.as_local_hir_id(outer_def_id); + let outer_hir_id = hir.local_def_id_to_hir_id(outer_def_id); 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` @@ -1444,7 +1444,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); + let main_id = hir.local_def_id_to_hir_id(def_id); if main_id == fn_id { let substs = tcx.mk_substs_trait(declared_ret_ty, &[]); let trait_ref = ty::TraitRef::new(term_id, substs); @@ -1622,7 +1622,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)); + let item = tcx.hir().expect_item(tcx.hir().local_def_id_to_hir_id(def_id)); debug!( "check_opaque_for_inheriting_lifetimes: def_id={:?} span={:?} item={:?}", def_id, span, item @@ -1729,7 +1729,7 @@ fn get_owner_return_paths( tcx: TyCtxt<'tcx>, def_id: LocalDefId, ) -> Option<(hir::HirId, ReturnsVisitor<'tcx>)> { - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let id = tcx.hir().get_parent_item(hir_id); tcx.hir() .find(id) @@ -1833,7 +1833,7 @@ fn binding_opaque_type_cycle_error( let mut err = struct_span_err!(tcx.sess, span, E0720, "cannot resolve opaque type"); err.span_label(span, "cannot resolve opaque type"); // Find the the owner that declared this `impl Trait` type. - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let mut prev_hir_id = hir_id; let mut hir_id = tcx.hir().get_parent_node(hir_id); while let Some(node) = tcx.hir().find(hir_id) { @@ -1858,7 +1858,7 @@ fn binding_opaque_type_cycle_error( source: hir::LocalSource::Normal, .. }) => { - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let typeck_results = tcx.typeck(tcx.hir().local_def_id(tcx.hir().get_parent_item(hir_id))); if let Some(ty) = typeck_results.node_type_opt(expr.hir_id) { @@ -2874,7 +2874,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()); + let variant_i_hir_id = tcx.hir().local_def_id_to_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), @@ -2935,7 +2935,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()); + let hir_id = tcx.hir().local_def_id_to_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); diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index fd516c88ec61a..66fb01a54f574 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -933,7 +933,7 @@ fn suggest_constraining_param( let param_def_id = generics.type_param(&p, tcx).def_id; if let Some(generics) = param_def_id .as_local() - .map(|id| hir.as_local_hir_id(id)) + .map(|id| hir.local_def_id_to_hir_id(id)) .and_then(|id| hir.find(hir.get_parent_item(id))) .as_ref() .and_then(|node| node.generics()) diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 50d9a1ebd2c24..2bde5d2c78cc1 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); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let item = tcx.hir().expect_item(hir_id); debug!( @@ -190,7 +190,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); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let trait_item = tcx.hir().expect_trait_item(hir_id); let method_sig = match trait_item.kind { @@ -264,7 +264,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); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let impl_item = tcx.hir().expect_impl_item(hir_id); let method_sig = match impl_item.kind { @@ -902,7 +902,7 @@ fn check_opaque_types<'fcx, 'tcx>( let generics = tcx.generics_of(def_id); let opaque_hir_id = if let Some(local_id) = def_id.as_local() { - tcx.hir().as_local_hir_id(local_id) + tcx.hir().local_def_id_to_hir_id(local_id) } else { // Opaque types from other crates won't have defining uses in this crate. return ty; diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 82ee48f0b5346..50e2d6a94bb71 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -433,7 +433,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()); + let hir_id = self.tcx().hir().local_def_id_to_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 81daf064bb368..4fda8932e213b 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -88,7 +88,7 @@ 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 tcx.hir().find(tcx.hir().as_local_hir_id(def_id)).is_none() { + if tcx.hir().find(tcx.hir().local_def_id_to_hir_id(def_id)).is_none() { return false; } true @@ -113,7 +113,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { for extern_crate in &crates_to_lint { let def_id = extern_crate.def_id.expect_local(); - let id = tcx.hir().as_local_hir_id(def_id); + let id = tcx.hir().local_def_id_to_hir_id(def_id); 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 8c6161a626473..56a737964c047 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -54,7 +54,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) { return; } - let impl_hir_id = tcx.hir().as_local_hir_id(impl_did); + let impl_hir_id = tcx.hir().local_def_id_to_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"), @@ -73,7 +73,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 = tcx.hir().as_local_hir_id(impl_did); + let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did); let self_type = tcx.type_of(impl_did); debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); @@ -146,7 +146,7 @@ fn visit_implementation_of_coerce_unsized(tcx: TyCtxt<'tcx>, impl_did: LocalDefI fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDefId) { debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did); - let impl_hir_id = tcx.hir().as_local_hir_id(impl_did); + let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did); let span = tcx.hir().span(impl_hir_id); let dispatch_from_dyn_trait = tcx.require_lang_item(DispatchFromDynTraitLangItem, Some(span)); @@ -315,7 +315,7 @@ pub fn coerce_unsized_info(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedI debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did); // this provider should only get invoked for local def-ids - let impl_hir_id = tcx.hir().as_local_hir_id(impl_did.expect_local()); + let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did.expect_local()); let span = tcx.hir().span(impl_hir_id); let coerce_unsized_trait = tcx.require_lang_item(CoerceUnsizedTraitLangItem, Some(span)); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index b47ef34600404..da1f3ea62f239 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -275,7 +275,7 @@ impl ItemCtxt<'tcx> { } pub fn hir_id(&self) -> hir::HirId { - self.tcx.hir().as_local_hir_id(self.item_def_id.expect_local()) + self.tcx.hir().local_def_id_to_hir_id(self.item_def_id.expect_local()) } pub fn node(&self) -> hir::Node<'tcx> { @@ -490,7 +490,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); + let param_id = tcx.hir().local_def_id_to_hir_id(def_id); 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); @@ -512,7 +512,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()); + let item_hir_id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()); let ast_generics = match tcx.hir().get(item_hir_id) { Node::TraitItem(item) => &item.generics, @@ -824,7 +824,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)); + let hir_id = tcx.hir().local_def_id_to_hir_id(variant_did.unwrap_or(parent_did)); let fields = def .fields() .iter() @@ -878,7 +878,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); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let item = match tcx.hir().get(hir_id) { Node::Item(item) => item, _ => bug!(), @@ -965,7 +965,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()); + let trait_hir_id = tcx.hir().local_def_id_to_hir_id(trait_def_id.expect_local()); let item = match tcx.hir().get(trait_hir_id) { Node::Item(item) => item, @@ -1016,7 +1016,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()); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let item = tcx.hir().expect_item(hir_id); let (is_auto, unsafety) = match item.kind { @@ -1194,7 +1194,7 @@ impl<'v> Visitor<'v> for AnonConstInParamListDetector { fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { use rustc_hir::*; - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); let parent_def_id = match node { @@ -1499,7 +1499,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { use rustc_hir::*; let def_id = def_id.expect_local(); - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let icx = ItemCtxt::new(tcx, def_id.to_def_id()); @@ -1597,7 +1597,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()); + let hir_id = tcx.hir().local_def_id_to_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); @@ -1608,7 +1608,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()); + let hir_id = tcx.hir().local_def_id_to_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 { @@ -1738,7 +1738,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()); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let node = tcx.hir().get(hir_id); let mut is_trait = None; @@ -2590,7 +2590,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { if !codegen_fn_attrs.no_sanitize.is_empty() { 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()); + let hir_id = tcx.hir().local_def_id_to_hir_id(id.expect_local()); tcx.struct_span_lint_hir( lint::builtin::INLINE_NO_SANITIZE, hir_id, @@ -2718,7 +2718,7 @@ fn check_target_feature_safe_fn(tcx: TyCtxt<'_>, id: DefId, attr_span: Span) { /// Checks the function annotated with `#[target_feature]` is not a safe /// trait method implementation, reporting an error if it is. fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) { - let hir_id = tcx.hir().as_local_hir_id(id); + let hir_id = tcx.hir().local_def_id_to_hir_id(id); let node = tcx.hir().get(hir_id); if let Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) = node { let parent_id = tcx.hir().get_parent_item(hir_id); diff --git a/src/librustc_typeck/collect/type_of.rs b/src/librustc_typeck/collect/type_of.rs index 17444c6d0ac95..f1478c8c952f8 100644 --- a/src/librustc_typeck/collect/type_of.rs +++ b/src/librustc_typeck/collect/type_of.rs @@ -23,7 +23,7 @@ use super::{bad_placeholder_type, is_suggestable_infer_ty}; pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { use hir::*; - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); if let Node::AnonConst(_) = tcx.hir().get(hir_id) { let parent_node_id = tcx.hir().get_parent_node(hir_id); @@ -138,7 +138,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { let def_id = def_id.expect_local(); use rustc_hir::*; - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let icx = ItemCtxt::new(tcx, def_id.to_def_id()); @@ -564,7 +564,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> { } } - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_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 }; @@ -617,7 +617,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> { /// by the time we borrow check, and it's not clear how we should handle /// those. fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty<'_> { - let scope = tcx.hir().get_defining_scope(tcx.hir().as_local_hir_id(opaque_ty_id)); + let scope = tcx.hir().get_defining_scope(tcx.hir().local_def_id_to_hir_id(opaque_ty_id)); let scope_def_id = tcx.hir().local_def_id(scope); let opaque_ty_def_id = opaque_ty_id.to_def_id(); @@ -653,7 +653,7 @@ fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty if concrete_ty.has_erased_regions() { // FIXME(impl_trait_in_bindings) Handle this case. tcx.sess.span_fatal( - tcx.hir().span(tcx.hir().as_local_hir_id(opaque_ty_id)), + tcx.hir().span(tcx.hir().local_def_id_to_hir_id(opaque_ty_id)), "lifetimes in impl Trait types in bindings are not currently supported", ); } diff --git a/src/librustc_typeck/impl_wf_check/min_specialization.rs b/src/librustc_typeck/impl_wf_check/min_specialization.rs index 8257c6ce92547..3746e5778aacd 100644 --- a/src/librustc_typeck/impl_wf_check/min_specialization.rs +++ b/src/librustc_typeck/impl_wf_check/min_specialization.rs @@ -336,7 +336,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), + tcx.hir().local_def_id_to_hir_id(impl1_def_id), arg, span, ) { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 49843fa43dd8c..41639c53b7991 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); + let main_id = tcx.hir().local_def_id_to_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 { @@ -249,7 +249,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); + let start_id = tcx.hir().local_def_id_to_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 15c72f8704f65..762d4216f7060 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); + let hir_id = self.tcx.hir().local_def_id_to_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 5dc7ac9fa0d4e..94926f480e23e 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()); + let id = tcx.hir().local_def_id_to_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 b810c9824ce66..535530a2ed494 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); + let id = tcx.hir().local_def_id_to_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 { @@ -375,7 +375,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } let (local, remote) = if let Some(def_id) = def_id.as_local() { - let id = self.tcx().hir().as_local_hir_id(def_id); + let id = self.tcx().hir().local_def_id_to_hir_id(def_id); (Some(self.terms_cx.inferred_starts[&id]), None) } else { (None, Some(self.tcx().variances_of(def_id))) diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index b307363dc3ab0..a893f69c48ada 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -39,7 +39,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()); + let id = tcx.hir().local_def_id_to_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 6e15485756d98..f61a783de694b 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -94,7 +94,9 @@ 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)).map(|n| (n, v))) // (HirId, Variance) + .filter_map(|(d, v)| { + d.as_local().map(|d| tcx.hir().local_def_id_to_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 1f576a17dd9d6..cb7c62e3a5ac6 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -356,7 +356,7 @@ pub fn build_impl( } let for_ = if let Some(did) = did.as_local() { - let hir_id = tcx.hir().as_local_hir_id(did); + let hir_id = tcx.hir().local_def_id_to_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"), @@ -377,7 +377,7 @@ pub fn build_impl( let predicates = tcx.explicit_predicates_of(did); let (trait_items, generics) = if let Some(did) = did.as_local() { - let hir_id = tcx.hir().as_local_hir_id(did); + let hir_id = tcx.hir().local_def_id_to_hir_id(did); match tcx.hir().expect_item(hir_id).kind { hir::ItemKind::Impl { ref generics, ref items, .. } => ( items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::>(), @@ -500,7 +500,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet) pub fn print_inlined_const(cx: &DocContext<'_>, did: DefId) -> String { if let Some(did) = did.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(did); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(did); rustc_hir_pretty::id_to_string(&cx.tcx.hir(), hir_id) } else { cx.tcx.rendered_const(did) @@ -513,7 +513,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)) + clean::utils::is_literal_expr(cx, cx.tcx.hir().local_def_id_to_hir_id(did)) }), } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 801d06e610169..3ad357e583cf1 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1382,7 +1382,7 @@ impl Clean for hir::Ty<'_> { if let Res::Def(DefKind::TyAlias, def_id) = path.res { // Substitute private type aliases if let Some(def_id) = def_id.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(def_id); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); if !cx.renderinfo.borrow().access_levels.is_exported(def_id.to_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 c22538f21f69f..e46c6c46cecae 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -471,7 +471,7 @@ pub fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String { match n.val { ty::ConstKind::Unevaluated(def, _, promoted) => { let mut s = if let Some(def) = def.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(def.did); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did); print_const_expr(cx, cx.tcx.hir().body_owned_by(hir_id)) } else { inline::print_inlined_const(cx, def.did) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b13acaae1bf23..c21fd8da0ed9a 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -143,13 +143,13 @@ impl<'tcx> DocContext<'tcx> { def_id } - /// Like the function of the same name on the HIR map, but skips calling it on fake DefIds. + /// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds. /// (This avoids a slice-index-out-of-bounds panic.) pub fn as_local_hir_id(&self, def_id: DefId) -> Option { 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)) + def_id.as_local().map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id)) } } @@ -400,7 +400,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt } let hir = tcx.hir(); - let body = hir.body(hir.body_owned_by(hir.as_local_hir_id(def_id))); + let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(def_id))); debug!("visiting body for {:?}", def_id); EmitIgnoredResolutionErrors::new(tcx).visit_body(body); (rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 4cfd81ffbce9d..b2589e5b806e8 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -655,7 +655,7 @@ impl<'a, 'b> ExtraInfo<'a, 'b> { (Some(h), _) => h, (None, Some(item_did)) => { match item_did.as_local() { - Some(item_did) => self.tcx.hir().as_local_hir_id(item_did), + Some(item_did) => self.tcx.hir().local_def_id_to_hir_id(item_did), None => { // If non-local, no need to check anything. return; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 062bd61a7d002..f7fc3579d67a7 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -813,8 +813,8 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { { use rustc_hir::def_id::LOCAL_CRATE; - let hir_src = self.cx.tcx.hir().as_local_hir_id(src_id); - let hir_dst = self.cx.tcx.hir().as_local_hir_id(dst_id); + let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id); + let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id); if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src) && !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index cf57ffd0b4b30..be80193db8c3b 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -323,7 +323,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), + Some(n) => tcx.hir().local_def_id_to_hir_id(n), None => return false, }; diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 80a0675898240..58b0704294b56 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -224,7 +224,7 @@ fn check_hash_peq<'tcx>( mess, |diag| { if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); diag.span_note( cx.tcx.hir().span(hir_id), "`PartialEq` implemented here" @@ -278,7 +278,7 @@ fn check_ord_partial_ord<'tcx>( mess, |diag| { if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); diag.span_note( cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here" @@ -341,7 +341,7 @@ fn check_unsafe_derive_deserialize<'tcx>( ty: Ty<'tcx>, ) { fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { - let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local()); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); cx.tcx.hir().expect_item(hir_id) } @@ -355,7 +355,7 @@ fn check_unsafe_derive_deserialize<'tcx>( if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE); if let ty::Adt(def, _) = ty.kind; if let Some(local_def_id) = def.did.as_local(); - let adt_hir_id = cx.tcx.hir().as_local_hir_id(local_def_id); + let adt_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); if !is_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id); if cx.tcx.inherent_impls(def.did) .iter() diff --git a/src/tools/clippy/clippy_lints/src/new_without_default.rs b/src/tools/clippy/clippy_lints/src/new_without_default.rs index 621ebdef2f0b1..28d1322e94626 100644 --- a/src/tools/clippy/clippy_lints/src/new_without_default.rs +++ b/src/tools/clippy/clippy_lints/src/new_without_default.rs @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { cx.tcx.for_each_impl(default_trait_id, |d| { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { if let Some(local_def_id) = ty_def.did.as_local() { - impls.insert(cx.tcx.hir().as_local_hir_id(local_def_id)); + impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); } } }); From 2e9b45e1dd8d3a248e2aea60314787650e3abcc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 13 Aug 2020 21:15:36 -0700 Subject: [PATCH 3/4] Recover gracefully from `struct ` parse errors --- src/librustc_parse/parser/item.rs | 2 +- .../mismatched-braces/missing-close-brace-in-struct.rs | 1 - .../missing-close-brace-in-struct.stderr | 10 ++-------- src/test/ui/parser/removed-syntax-field-let.rs | 1 - src/test/ui/parser/removed-syntax-field-let.stderr | 8 +------- 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 10d214e52abdb..bba65534f1be3 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1313,7 +1313,7 @@ impl<'a> Parser<'a> { vis: Visibility, attrs: Vec, ) -> PResult<'a, StructField> { - let name = self.parse_ident()?; + let name = self.parse_ident_common(false)?; self.expect(&token::Colon)?; let ty = self.parse_ty()?; Ok(StructField { diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs index 0d53315839ceb..090a17b413dda 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs @@ -2,7 +2,6 @@ pub(crate) struct Bar { foo: T, trait T { //~ ERROR expected identifier, found keyword `trait` -//~^ ERROR expected `:`, found `T` fn foo(&self); } diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr index ac8dd48a58879..a47d5506ef0b8 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr @@ -1,5 +1,5 @@ error: this file contains an unclosed delimiter - --> $DIR/missing-close-brace-in-struct.rs:14:65 + --> $DIR/missing-close-brace-in-struct.rs:13:65 | LL | pub(crate) struct Bar { | - unclosed delimiter @@ -13,11 +13,5 @@ error: expected identifier, found keyword `trait` LL | trait T { | ^^^^^ expected identifier, found keyword -error: expected `:`, found `T` - --> $DIR/missing-close-brace-in-struct.rs:4:7 - | -LL | trait T { - | ^ expected `:` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/parser/removed-syntax-field-let.rs b/src/test/ui/parser/removed-syntax-field-let.rs index 9fe4a148a56aa..6d64de296f150 100644 --- a/src/test/ui/parser/removed-syntax-field-let.rs +++ b/src/test/ui/parser/removed-syntax-field-let.rs @@ -1,7 +1,6 @@ struct S { let foo: (), //~^ ERROR expected identifier, found keyword `let` - //~^^ ERROR expected `:`, found `foo` } fn main() {} diff --git a/src/test/ui/parser/removed-syntax-field-let.stderr b/src/test/ui/parser/removed-syntax-field-let.stderr index 7de2c730a7069..10be2e045b2b8 100644 --- a/src/test/ui/parser/removed-syntax-field-let.stderr +++ b/src/test/ui/parser/removed-syntax-field-let.stderr @@ -4,11 +4,5 @@ error: expected identifier, found keyword `let` LL | let foo: (), | ^^^ expected identifier, found keyword -error: expected `:`, found `foo` - --> $DIR/removed-syntax-field-let.rs:2:9 - | -LL | let foo: (), - | ^^^ expected `:` - -error: aborting due to 2 previous errors +error: aborting due to previous error From a7ad899f9dbce1b4a0beb56650bc72732f204d24 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 15 Aug 2020 02:41:41 +0300 Subject: [PATCH 4/4] std/sys/unix/time: make it easier for LLVM to optimize `Instant` subtraction. --- library/std/src/sys/unix/time.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 6707f790cab0a..f2a9cb5a0e879 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -20,17 +20,29 @@ impl Timespec { fn sub_timespec(&self, other: &Timespec) -> Result { if self >= other { - Ok(if self.t.tv_nsec >= other.t.tv_nsec { - Duration::new( - (self.t.tv_sec - other.t.tv_sec) as u64, - (self.t.tv_nsec - other.t.tv_nsec) as u32, - ) + // NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM + // to optimize it into a branchless form (see also #75545): + // + // 1. `self.t.tv_sec - other.t.tv_sec` shows up as a common expression + // in both branches, i.e. the `else` must have its `- 1` + // subtraction after the common one, not interleaved with it + // (it used to be `self.t.tv_sec - 1 - other.t.tv_sec`) + // + // 2. the `Duration::new` call (or any other additional complexity) + // is outside of the `if`-`else`, not duplicated in both branches + // + // Ideally this code could be rearranged such that it more + // directly expresses the lower-cost behavior we want from it. + let (secs, nsec) = if self.t.tv_nsec >= other.t.tv_nsec { + ((self.t.tv_sec - other.t.tv_sec) as u64, (self.t.tv_nsec - other.t.tv_nsec) as u32) } else { - Duration::new( - (self.t.tv_sec - 1 - other.t.tv_sec) as u64, + ( + (self.t.tv_sec - other.t.tv_sec - 1) as u64, self.t.tv_nsec as u32 + (NSEC_PER_SEC as u32) - other.t.tv_nsec as u32, ) - }) + }; + + Ok(Duration::new(secs, nsec)) } else { match other.sub_timespec(self) { Ok(d) => Err(d),