ParamEnv
should be const when ImplItem
is within a const impl.
This commit is contained in:
parent
8710a2e169
commit
87cd1ce6c1
4 changed files with 58 additions and 30 deletions
|
@ -287,7 +287,43 @@ 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) => tcx.hir().get(hir_id).constness_for_typeck(),
|
||||
Some(hir_id) => match tcx.hir().get(hir_id) {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(..), .. })
|
||||
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Static(..), .. })
|
||||
| hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Const(..), .. })
|
||||
| hir::Node::AnonConst(_)
|
||||
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. })
|
||||
| hir::Node::ImplItem(hir::ImplItem {
|
||||
kind: hir::ImplItemKind::Fn(hir::FnSig { header: hir::FnHeader { constness: hir::Constness::Const, .. }, .. }, ..),
|
||||
..
|
||||
}) => hir::Constness::Const,
|
||||
|
||||
hir::Node::ImplItem(hir::ImplItem {
|
||||
kind: hir::ImplItemKind::TyAlias(..) | hir::ImplItemKind::Fn(..),
|
||||
..
|
||||
}) => {
|
||||
let parent_hir_id = tcx.hir().get_parent_node(hir_id);
|
||||
match tcx.hir().get(parent_hir_id) {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(hir::Impl { constness, .. }), .. }) => *constness,
|
||||
_ => span_bug!(
|
||||
tcx.def_span(parent_hir_id.owner),
|
||||
"impl item's parent node is not an impl",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Fn(hir::FnSig { header: hir::FnHeader { constness, .. }, .. }, ..),
|
||||
..
|
||||
})
|
||||
| hir::Node::TraitItem(hir::TraitItem {
|
||||
kind: hir::TraitItemKind::Fn(hir::FnSig { header: hir::FnHeader { constness, .. }, .. }, ..),
|
||||
..
|
||||
})
|
||||
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(hir::Impl { constness, .. }), .. }) => *constness,
|
||||
|
||||
_ => hir::Constness::NotConst,
|
||||
},
|
||||
None => hir::Constness::NotConst,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue