Skip to content

Commit e37947f

Browse files
oli-obkfee1-dead
authored andcommitted
Re-use constness_for_typeck instead of rolling it ourselves
1 parent 1761d88 commit e37947f

File tree

2 files changed

+6
-28
lines changed
  • compiler

2 files changed

+6
-28
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -454,30 +454,18 @@ impl<'hir> Map<'hir> {
454454
///
455455
/// Panics if `LocalDefId` does not have an associated body.
456456
pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind {
457-
match self.opt_body_owner_kind(id) {
458-
Ok(kind) => kind,
459-
Err(node) => bug!("{:#?} is not a body node", node),
460-
}
461-
}
462-
463-
/// Returns the `BodyOwnerKind` of this `LocalDefId`.
464-
///
465-
/// Returns the `Node` if `LocalDefId` does not have an associated body.
466-
pub fn opt_body_owner_kind(&self, id: HirId) -> Result<BodyOwnerKind, Node<'_>> {
467457
match self.get(id) {
468458
Node::Item(&Item { kind: ItemKind::Const(..), .. })
469459
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), .. })
470460
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Const(..), .. })
471-
| Node::AnonConst(_) => Ok(BodyOwnerKind::Const),
461+
| Node::AnonConst(_) => BodyOwnerKind::Const,
472462
Node::Ctor(..)
473463
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
474464
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
475-
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => Ok(BodyOwnerKind::Fn),
476-
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => {
477-
Ok(BodyOwnerKind::Static(m))
478-
}
479-
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => Ok(BodyOwnerKind::Closure),
480-
node => Err(node),
465+
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => BodyOwnerKind::Fn,
466+
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
467+
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
468+
node => bug!("{:#?} is not a body node", node),
481469
}
482470
}
483471

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
289289
let hir_id = local_did.map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id));
290290

291291
let constness = match hir_id {
292-
Some(hir_id) => match tcx.hir().opt_body_owner_kind(hir_id) {
293-
Err(hir::Node::Item(&hir::Item {
294-
kind: hir::ItemKind::Impl(hir::Impl { constness, .. }),
295-
..
296-
})) => constness,
297-
Err(_) => hir::Constness::NotConst,
298-
Ok(_) => match tcx.hir().body_const_context(local_did.unwrap()) {
299-
Some(_) => hir::Constness::Const,
300-
None => hir::Constness::NotConst,
301-
},
302-
},
292+
Some(hir_id) => tcx.hir().get(hir_id).constness_for_typeck(),
303293
None => hir::Constness::NotConst,
304294
};
305295

0 commit comments

Comments
 (0)