Skip to content

Commit ffd46d0

Browse files
committed
Re-use constness_for_typeck instead of rolling it ourselves
1 parent 8c0edca commit ffd46d0

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
@@ -446,30 +446,18 @@ impl<'hir> Map<'hir> {
446446
///
447447
/// Panics if `LocalDefId` does not have an associated body.
448448
pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind {
449-
match self.opt_body_owner_kind(id) {
450-
Ok(kind) => kind,
451-
Err(node) => bug!("{:#?} is not a body node", node),
452-
}
453-
}
454-
455-
/// Returns the `BodyOwnerKind` of this `LocalDefId`.
456-
///
457-
/// Returns the `Node` if `LocalDefId` does not have an associated body.
458-
pub fn opt_body_owner_kind(&self, id: HirId) -> Result<BodyOwnerKind, Node<'_>> {
459449
match self.get(id) {
460450
Node::Item(&Item { kind: ItemKind::Const(..), .. })
461451
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), .. })
462452
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Const(..), .. })
463-
| Node::AnonConst(_) => Ok(BodyOwnerKind::Const),
453+
| Node::AnonConst(_) => BodyOwnerKind::Const,
464454
Node::Ctor(..)
465455
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
466456
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
467-
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => Ok(BodyOwnerKind::Fn),
468-
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => {
469-
Ok(BodyOwnerKind::Static(m))
470-
}
471-
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => Ok(BodyOwnerKind::Closure),
472-
node => Err(node),
457+
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => BodyOwnerKind::Fn,
458+
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
459+
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
460+
node => bug!("{:#?} is not a body node", node),
473461
}
474462
}
475463

compiler/rustc_ty_utils/src/ty.rs

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

280280
let constness = match hir_id {
281-
Some(hir_id) => match tcx.hir().opt_body_owner_kind(hir_id) {
282-
Err(hir::Node::Item(&hir::Item {
283-
kind: hir::ItemKind::Impl(hir::Impl { constness, .. }),
284-
..
285-
})) => constness,
286-
Err(_) => hir::Constness::NotConst,
287-
Ok(_) => match tcx.hir().body_const_context(local_did.unwrap()) {
288-
Some(_) => hir::Constness::Const,
289-
None => hir::Constness::NotConst,
290-
},
291-
},
281+
Some(hir_id) => tcx.hir().get(hir_id).constness_for_typeck(),
292282
None => hir::Constness::NotConst,
293283
};
294284

0 commit comments

Comments
 (0)