handle the case when container is not impl

This commit is contained in:
Deadbeef 2021-07-26 11:34:43 +08:00
parent bcf0e2f528
commit c6d0a20f7b
No known key found for this signature in database
GPG Key ID: 027DF9338862ADDD
2 changed files with 9 additions and 6 deletions

View File

@ -16,12 +16,10 @@ pub enum AssocItemContainer {
} }
impl AssocItemContainer { impl AssocItemContainer {
/// Asserts that this is the `DefId` of an associated item declared pub fn impl_def_id(&self) -> Option<DefId> {
/// in an impl, and returns the trait `DefId`.
pub fn assert_impl(&self) -> DefId {
match *self { match *self {
ImplContainer(id) => id, ImplContainer(id) => Some(id),
_ => bug!("associated item has wrong container type: {:?}", self), _ => None,
} }
} }

View File

@ -1293,7 +1293,12 @@ pub fn check_type_bounds<'tcx>(
tcx.infer_ctxt().enter(move |infcx| { tcx.infer_ctxt().enter(move |infcx| {
// if the item is inside a const impl, we transform the predicates to be const. // if the item is inside a const impl, we transform the predicates to be const.
let constness = tcx.impl_constness(impl_ty.container.assert_impl()); let constness = impl_ty
.container
.impl_def_id()
.map(|did| tcx.impl_constness(did))
.unwrap_or(hir::Constness::NotConst);
let pred_map = match constness { let pred_map = match constness {
hir::Constness::NotConst => |p, _| p, hir::Constness::NotConst => |p, _| p,
hir::Constness::Const => |p: ty::Predicate<'tcx>, tcx: TyCtxt<'tcx>| { hir::Constness::Const => |p: ty::Predicate<'tcx>, tcx: TyCtxt<'tcx>| {