Skip to content

Commit cd3ead1

Browse files
committed
Use delay_span_bug less often
1 parent 6394032 commit cd3ead1

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/librustc/traits/project.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::ty::subst::{Subst, InternalSubsts};
2323
use crate::ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
2424
use crate::ty::fold::{TypeFoldable, TypeFolder};
2525
use crate::util::common::FN_OUTPUT_NAME;
26+
use syntax_pos::DUMMY_SP;
2627

2728
/// Depending on the stage of compilation, we want projection to be
2829
/// more or less conservative.
@@ -1437,11 +1438,14 @@ fn confirm_impl_candidate<'cx, 'tcx>(
14371438
obligation: &ProjectionTyObligation<'tcx>,
14381439
impl_vtable: VtableImplData<'tcx, PredicateObligation<'tcx>>,
14391440
) -> Progress<'tcx> {
1441+
let tcx = selcx.tcx();
1442+
14401443
let VtableImplData { impl_def_id, substs, nested } = impl_vtable;
1444+
let assoc_item_id = obligation.predicate.item_def_id;
1445+
let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();
14411446

1442-
let tcx = selcx.tcx();
14431447
let param_env = obligation.param_env;
1444-
let assoc_ty = assoc_ty_def(selcx, impl_def_id, obligation.predicate.item_def_id);
1448+
let assoc_ty = assoc_ty_def(selcx, impl_def_id, assoc_item_id);
14451449

14461450
if !assoc_ty.item.defaultness.has_value() {
14471451
// This means that the impl is missing a definition for the
@@ -1456,16 +1460,28 @@ fn confirm_impl_candidate<'cx, 'tcx>(
14561460
obligations: nested,
14571461
};
14581462
}
1463+
let substs = obligation.predicate.substs.rebase_onto(tcx, trait_def_id, substs);
14591464
let substs = translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.node);
14601465
let ty = if let ty::AssocKind::OpaqueTy = assoc_ty.item.kind {
14611466
let item_substs = InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
14621467
tcx.mk_opaque(assoc_ty.item.def_id, item_substs)
14631468
} else {
14641469
tcx.type_of(assoc_ty.item.def_id)
14651470
};
1466-
Progress {
1467-
ty: ty.subst(tcx, substs),
1468-
obligations: nested,
1471+
if substs.len() != tcx.generics_of(assoc_ty.item.def_id).count() {
1472+
tcx.sess.delay_span_bug(
1473+
DUMMY_SP,
1474+
"impl item and trait item have different parameter counts",
1475+
);
1476+
Progress {
1477+
ty: tcx.types.err,
1478+
obligations: nested,
1479+
}
1480+
} else {
1481+
Progress {
1482+
ty: ty.subst(tcx, substs),
1483+
obligations: nested,
1484+
}
14691485
}
14701486
}
14711487

src/librustc/ty/subst.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
234234
ty::GenericParamDefKind::Const => {
235235
tcx.mk_const(ty::Const {
236236
val: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
237-
ty: tcx.type_of(def_id),
237+
ty: tcx.type_of(param.def_id),
238238
}).into()
239239
}
240240
}
@@ -533,8 +533,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
533533
data.name,
534534
self.root_ty,
535535
data.index);
536-
self.tcx.sess.delay_span_bug(span, &msg);
537-
r
536+
span_bug!(span, "{}", msg);
538537
}
539538
}
540539
}

0 commit comments

Comments
 (0)