Use is_const_fn_raw query for HIR const-checking
This commit is contained in:
@@ -74,16 +74,16 @@ enum ConstKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ConstKind {
|
impl ConstKind {
|
||||||
fn for_body(body: &hir::Body<'_>, hir_map: Map<'_>) -> Option<Self> {
|
fn for_body(body: &hir::Body<'_>, tcx: TyCtxt<'_>) -> Option<Self> {
|
||||||
let is_const_fn = |id| hir_map.fn_sig_by_hir_id(id).unwrap().header.is_const();
|
let owner = tcx.hir().body_owner(body.id());
|
||||||
|
let const_kind = match tcx.hir().body_owner_kind(owner) {
|
||||||
let owner = hir_map.body_owner(body.id());
|
|
||||||
let const_kind = match hir_map.body_owner_kind(owner) {
|
|
||||||
hir::BodyOwnerKind::Const => Self::Const,
|
hir::BodyOwnerKind::Const => Self::Const,
|
||||||
hir::BodyOwnerKind::Static(Mutability::Mut) => Self::StaticMut,
|
hir::BodyOwnerKind::Static(Mutability::Mut) => Self::StaticMut,
|
||||||
hir::BodyOwnerKind::Static(Mutability::Not) => Self::Static,
|
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,
|
hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_body(&mut self, body: &'tcx hir::Body<'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));
|
self.recurse_into(kind, |this| intravisit::walk_body(this, body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user