diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2021-10-21 15:28:26 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2021-11-29 21:19:46 +0800 |
| commit | e37947f0973aa9927809d102b00264c207f5e530 (patch) | |
| tree | b926aadfd423045e314a366698264fc6b6779484 | |
| parent | 1761d88f4a39302ddc0c961811cb03ac02e01cf9 (diff) | |
| download | rust-e37947f0973aa9927809d102b00264c207f5e530.tar.gz rust-e37947f0973aa9927809d102b00264c207f5e530.zip | |
Re-use `constness_for_typeck` instead of rolling it ourselves
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/ty.rs | 12 |
2 files changed, 6 insertions, 28 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index bde566d4c31..c3d2fd4e15c 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -454,30 +454,18 @@ impl<'hir> Map<'hir> { /// /// Panics if `LocalDefId` does not have an associated body. pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind { - match self.opt_body_owner_kind(id) { - Ok(kind) => kind, - Err(node) => bug!("{:#?} is not a body node", node), - } - } - - /// Returns the `BodyOwnerKind` of this `LocalDefId`. - /// - /// Returns the `Node` if `LocalDefId` does not have an associated body. - pub fn opt_body_owner_kind(&self, id: HirId) -> Result<BodyOwnerKind, Node<'_>> { match self.get(id) { Node::Item(&Item { kind: ItemKind::Const(..), .. }) | Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), .. }) | Node::ImplItem(&ImplItem { kind: ImplItemKind::Const(..), .. }) - | Node::AnonConst(_) => Ok(BodyOwnerKind::Const), + | Node::AnonConst(_) => BodyOwnerKind::Const, Node::Ctor(..) | Node::Item(&Item { kind: ItemKind::Fn(..), .. }) | Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. }) - | Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => Ok(BodyOwnerKind::Fn), - Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => { - Ok(BodyOwnerKind::Static(m)) - } - Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => Ok(BodyOwnerKind::Closure), - node => Err(node), + | Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => BodyOwnerKind::Fn, + Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m), + Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure, + node => bug!("{:#?} is not a body node", node), } } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index dccb74c03f7..4bcc80c8302 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -289,17 +289,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { let hir_id = local_did.map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)); let constness = match hir_id { - Some(hir_id) => match tcx.hir().opt_body_owner_kind(hir_id) { - Err(hir::Node::Item(&hir::Item { - kind: hir::ItemKind::Impl(hir::Impl { constness, .. }), - .. - })) => constness, - Err(_) => hir::Constness::NotConst, - Ok(_) => match tcx.hir().body_const_context(local_did.unwrap()) { - Some(_) => hir::Constness::Const, - None => hir::Constness::NotConst, - }, - }, + Some(hir_id) => tcx.hir().get(hir_id).constness_for_typeck(), None => hir::Constness::NotConst, }; |
