Improve subst error when parameter kinds mismatch
This commit is contained in:
parent
d0a6ddfe10
commit
0439efbbee
1 changed files with 40 additions and 13 deletions
|
@ -550,17 +550,32 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
|
||||||
let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack());
|
let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack());
|
||||||
let ty = match opt_ty {
|
let ty = match opt_ty {
|
||||||
Some(UnpackedKind::Type(ty)) => ty,
|
Some(UnpackedKind::Type(ty)) => ty,
|
||||||
_ => {
|
Some(kind) => {
|
||||||
let span = self.span.unwrap_or(DUMMY_SP);
|
let span = self.span.unwrap_or(DUMMY_SP);
|
||||||
span_bug!(
|
span_bug!(
|
||||||
span,
|
span,
|
||||||
"Type parameter `{:?}` ({:?}/{}) out of range \
|
"expected type for `{:?}` ({:?}/{}) but found {:?} \
|
||||||
|
when substituting (root type={:?}) substs={:?}",
|
||||||
|
p,
|
||||||
|
source_ty,
|
||||||
|
p.idx,
|
||||||
|
kind,
|
||||||
|
self.root_ty,
|
||||||
|
self.substs,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let span = self.span.unwrap_or(DUMMY_SP);
|
||||||
|
span_bug!(
|
||||||
|
span,
|
||||||
|
"type parameter `{:?}` ({:?}/{}) out of range \
|
||||||
when substituting (root type={:?}) substs={:?}",
|
when substituting (root type={:?}) substs={:?}",
|
||||||
p,
|
p,
|
||||||
source_ty,
|
source_ty,
|
||||||
p.idx,
|
p.idx,
|
||||||
self.root_ty,
|
self.root_ty,
|
||||||
self.substs);
|
self.substs,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -570,29 +585,41 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
|
||||||
fn const_for_param(
|
fn const_for_param(
|
||||||
&self,
|
&self,
|
||||||
p: ParamConst,
|
p: ParamConst,
|
||||||
source_cn: &'tcx ty::Const<'tcx>
|
source_ct: &'tcx ty::Const<'tcx>
|
||||||
) -> &'tcx ty::Const<'tcx> {
|
) -> &'tcx ty::Const<'tcx> {
|
||||||
// Look up the const in the substitutions. It really should be in there.
|
// Look up the const in the substitutions. It really should be in there.
|
||||||
let opt_cn = self.substs.get(p.index as usize).map(|k| k.unpack());
|
let opt_ct = self.substs.get(p.index as usize).map(|k| k.unpack());
|
||||||
let cn = match opt_cn {
|
let ct = match opt_ct {
|
||||||
Some(UnpackedKind::Const(cn)) => cn,
|
Some(UnpackedKind::Const(ct)) => ct,
|
||||||
_ => {
|
Some(kind) => {
|
||||||
let span = self.span.unwrap_or(DUMMY_SP);
|
let span = self.span.unwrap_or(DUMMY_SP);
|
||||||
span_bug!(
|
span_bug!(
|
||||||
span,
|
span,
|
||||||
"Const parameter `{:?}` ({:?}/{}) out of range \
|
"expected const for `{:?}` ({:?}/{}) but found {:?} \
|
||||||
when substituting (root type={:?}) substs={:?}",
|
when substituting substs={:?}",
|
||||||
p,
|
p,
|
||||||
source_cn,
|
source_ct,
|
||||||
|
p.index,
|
||||||
|
kind,
|
||||||
|
self.substs,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let span = self.span.unwrap_or(DUMMY_SP);
|
||||||
|
span_bug!(
|
||||||
|
span,
|
||||||
|
"const parameter `{:?}` ({:?}/{}) out of range \
|
||||||
|
when substituting substs={:?}",
|
||||||
|
p,
|
||||||
|
source_ct,
|
||||||
p.index,
|
p.index,
|
||||||
self.root_ty,
|
|
||||||
self.substs,
|
self.substs,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME(const_generics): shift const through binders
|
// FIXME(const_generics): shift const through binders
|
||||||
cn
|
ct
|
||||||
}
|
}
|
||||||
|
|
||||||
/// It is sometimes necessary to adjust the De Bruijn indices during substitution. This occurs
|
/// It is sometimes necessary to adjust the De Bruijn indices during substitution. This occurs
|
||||||
|
|
Loading…
Reference in a new issue