Skip to content

Commit 0439efb

Browse files
committed
Improve subst error when parameter kinds mismatch
1 parent d0a6ddf commit 0439efb

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

src/librustc/ty/subst.rs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -550,17 +550,32 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
550550
let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack());
551551
let ty = match opt_ty {
552552
Some(UnpackedKind::Type(ty)) => ty,
553-
_ => {
553+
Some(kind) => {
554554
let span = self.span.unwrap_or(DUMMY_SP);
555555
span_bug!(
556556
span,
557-
"Type parameter `{:?}` ({:?}/{}) out of range \
557+
"expected type for `{:?}` ({:?}/{}) but found {:?} \
558558
when substituting (root type={:?}) substs={:?}",
559559
p,
560560
source_ty,
561561
p.idx,
562+
kind,
562563
self.root_ty,
563-
self.substs);
564+
self.substs,
565+
);
566+
}
567+
None => {
568+
let span = self.span.unwrap_or(DUMMY_SP);
569+
span_bug!(
570+
span,
571+
"type parameter `{:?}` ({:?}/{}) out of range \
572+
when substituting (root type={:?}) substs={:?}",
573+
p,
574+
source_ty,
575+
p.idx,
576+
self.root_ty,
577+
self.substs,
578+
);
564579
}
565580
};
566581

@@ -570,29 +585,41 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
570585
fn const_for_param(
571586
&self,
572587
p: ParamConst,
573-
source_cn: &'tcx ty::Const<'tcx>
588+
source_ct: &'tcx ty::Const<'tcx>
574589
) -> &'tcx ty::Const<'tcx> {
575590
// Look up the const in the substitutions. It really should be in there.
576-
let opt_cn = self.substs.get(p.index as usize).map(|k| k.unpack());
577-
let cn = match opt_cn {
578-
Some(UnpackedKind::Const(cn)) => cn,
579-
_ => {
591+
let opt_ct = self.substs.get(p.index as usize).map(|k| k.unpack());
592+
let ct = match opt_ct {
593+
Some(UnpackedKind::Const(ct)) => ct,
594+
Some(kind) => {
580595
let span = self.span.unwrap_or(DUMMY_SP);
581596
span_bug!(
582597
span,
583-
"Const parameter `{:?}` ({:?}/{}) out of range \
584-
when substituting (root type={:?}) substs={:?}",
598+
"expected const for `{:?}` ({:?}/{}) but found {:?} \
599+
when substituting substs={:?}",
585600
p,
586-
source_cn,
601+
source_ct,
602+
p.index,
603+
kind,
604+
self.substs,
605+
);
606+
}
607+
None => {
608+
let span = self.span.unwrap_or(DUMMY_SP);
609+
span_bug!(
610+
span,
611+
"const parameter `{:?}` ({:?}/{}) out of range \
612+
when substituting substs={:?}",
613+
p,
614+
source_ct,
587615
p.index,
588-
self.root_ty,
589616
self.substs,
590617
);
591618
}
592619
};
593620

594621
// FIXME(const_generics): shift const through binders
595-
cn
622+
ct
596623
}
597624

598625
/// It is sometimes necessary to adjust the De Bruijn indices during substitution. This occurs

0 commit comments

Comments
 (0)