Skip to content

Commit

Permalink
Use is_const_fn_raw query for HIR const-checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Apr 9, 2020
1 parent 93dc97a commit d8047f8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/librustc_passes/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ enum ConstKind {
}

impl ConstKind {
fn for_body(body: &hir::Body<'_>, hir_map: Map<'_>) -> Option<Self> {
let is_const_fn = |id| hir_map.fn_sig_by_hir_id(id).unwrap().header.is_const();

let owner = hir_map.body_owner(body.id());
let const_kind = match hir_map.body_owner_kind(owner) {
fn for_body(body: &hir::Body<'_>, tcx: TyCtxt<'_>) -> Option<Self> {
let owner = tcx.hir().body_owner(body.id());
let const_kind = match tcx.hir().body_owner_kind(owner) {
hir::BodyOwnerKind::Const => Self::Const,
hir::BodyOwnerKind::Static(Mutability::Mut) => Self::StaticMut,
hir::BodyOwnerKind::Static(Mutability::Not) => Self::Static,

hir::BodyOwnerKind::Fn if is_const_fn(owner) => Self::ConstFn,
hir::BodyOwnerKind::Fn if tcx.is_const_fn_raw(tcx.hir().local_def_id(owner)) => {
Self::ConstFn
}
hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => return None,
};

Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
}

fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
let kind = ConstKind::for_body(body, self.tcx.hir());
let kind = ConstKind::for_body(body, self.tcx);
self.recurse_into(kind, |this| intravisit::walk_body(this, body));
}

Expand Down

0 comments on commit d8047f8

Please sign in to comment.