diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index 994936351ff..5cb2b90fe11 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -16,12 +16,10 @@ pub enum AssocItemContainer { } impl AssocItemContainer { - /// Asserts that this is the `DefId` of an associated item declared - /// in an impl, and returns the trait `DefId`. - pub fn assert_impl(&self) -> DefId { + pub fn impl_def_id(&self) -> Option { match *self { - ImplContainer(id) => id, - _ => bug!("associated item has wrong container type: {:?}", self), + ImplContainer(id) => Some(id), + _ => None, } } diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 0ce2746b128..a2ffb30f43b 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -1293,7 +1293,12 @@ pub fn check_type_bounds<'tcx>( tcx.infer_ctxt().enter(move |infcx| { // 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 { hir::Constness::NotConst => |p, _| p, hir::Constness::Const => |p: ty::Predicate<'tcx>, tcx: TyCtxt<'tcx>| {