Skip to content

Commit 266efb5

Browse files
committed
handle the case when container is not impl
1 parent 9ddb958 commit 266efb5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

compiler/rustc_middle/src/ty/assoc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ pub enum AssocItemContainer {
1616
}
1717

1818
impl AssocItemContainer {
19-
/// Asserts that this is the `DefId` of an associated item declared
20-
/// in an impl, and returns the trait `DefId`.
21-
pub fn assert_impl(&self) -> DefId {
19+
pub fn impl_def_id(&self) -> Option<DefId> {
2220
match *self {
23-
ImplContainer(id) => id,
24-
_ => bug!("associated item has wrong container type: {:?}", self),
21+
ImplContainer(id) => Some(id),
22+
_ => None,
2523
}
2624
}
2725

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,12 @@ pub fn check_type_bounds<'tcx>(
12931293

12941294
tcx.infer_ctxt().enter(move |infcx| {
12951295
// if the item is inside a const impl, we transform the predicates to be const.
1296-
let constness = tcx.impl_constness(impl_ty.container.assert_impl());
1296+
let constness = impl_ty
1297+
.container
1298+
.impl_def_id()
1299+
.map(|did| tcx.impl_constness(did))
1300+
.unwrap_or(hir::Constness::NotConst);
1301+
12971302
let pred_map = match constness {
12981303
hir::Constness::NotConst => |p, _| p,
12991304
hir::Constness::Const => |p: ty::Predicate<'tcx>, tcx: TyCtxt<'tcx>| {

0 commit comments

Comments
 (0)