Assert in apply_substs that the number of parameters doesn't change

... and fix a small bug revealed by that.
This commit is contained in:
Florian Diebold 2019-03-21 22:39:31 +01:00
parent cbb418ebb8
commit 1ee779d1f7
2 changed files with 7 additions and 2 deletions

View File

@ -148,6 +148,10 @@ impl Substs {
self.0.iter()
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) {
// Without an Arc::make_mut_slice, we can't avoid the clone here:
let mut v: Vec<_> = self.0.iter().cloned().collect();
@ -286,7 +290,8 @@ impl Ty {
/// `Option<u32>` afterwards.)
pub fn apply_substs(self, substs: Substs) -> Ty {
match self {
Ty::Apply(ApplicationTy { ctor, .. }) => {
Ty::Apply(ApplicationTy { ctor, parameters: previous_substs }) => {
assert_eq!(previous_substs.len(), substs.len());
Ty::Apply(ApplicationTy { ctor, parameters: substs })
}
_ => self,

View File

@ -817,7 +817,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
Some(func.generic_params(self.db)),
)
}
None => (Ty::Unknown, receiver_ty, None),
None => (receiver_ty, Ty::Unknown, None),
};
let substs = self.substs_for_method_call(def_generics, generic_args);
let method_ty = method_ty.apply_substs(substs);