Move impl constness into impl trait header
This commit is contained in:
parent
c0e0d8f874
commit
2ffe3b1e70
8 changed files with 35 additions and 33 deletions
|
@ -746,7 +746,8 @@ rustc_queries! {
|
|||
desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
|
||||
}
|
||||
|
||||
/// Returns the constness of functions and impls.
|
||||
/// Returns the constness of function-like things (tuple struct/variant constructors, functions,
|
||||
/// methods)
|
||||
///
|
||||
/// Will ICE if used on things that are always const or never const.
|
||||
///
|
||||
|
|
|
@ -3141,7 +3141,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// Whether the trait impl is marked const. This does not consider stability or feature gates.
|
||||
pub fn is_const_trait_impl(self, def_id: DefId) -> bool {
|
||||
self.def_kind(def_id) == DefKind::Impl { of_trait: true }
|
||||
&& self.constness(def_id) == hir::Constness::Const
|
||||
&& self.impl_trait_header(def_id).unwrap().constness == hir::Constness::Const
|
||||
}
|
||||
|
||||
pub fn intrinsic(self, def_id: impl IntoQueryParam<DefId> + Copy) -> Option<ty::IntrinsicDef> {
|
||||
|
|
|
@ -253,6 +253,7 @@ pub struct ImplTraitHeader<'tcx> {
|
|||
pub trait_ref: ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>,
|
||||
pub polarity: ImplPolarity,
|
||||
pub safety: hir::Safety,
|
||||
pub constness: hir::Constness,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]
|
||||
|
@ -2004,11 +2005,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let def_id: DefId = def_id.into();
|
||||
match self.def_kind(def_id) {
|
||||
DefKind::Impl { of_trait: true } => {
|
||||
self.constness(def_id) == hir::Constness::Const
|
||||
&& self.is_const_trait(
|
||||
self.trait_id_of_impl(def_id)
|
||||
.expect("expected trait for trait implementation"),
|
||||
)
|
||||
let header = self.impl_trait_header(def_id).unwrap();
|
||||
header.constness == hir::Constness::Const
|
||||
&& self.is_const_trait(header.trait_ref.skip_binder().def_id)
|
||||
}
|
||||
DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) => {
|
||||
self.constness(def_id) == hir::Constness::Const
|
||||
|
|
|
@ -389,7 +389,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
.delay_as_bug();
|
||||
}
|
||||
|
||||
dtor_candidate = Some((*item_id, self.constness(impl_did)));
|
||||
dtor_candidate = Some((*item_id, self.impl_trait_header(impl_did).unwrap().constness));
|
||||
});
|
||||
|
||||
let (did, constness) = dtor_candidate?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue