From 1ee779d1f74f48d9f3098001c63108b794dbc0b5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 21 Mar 2019 22:39:31 +0100 Subject: Assert in apply_substs that the number of parameters doesn't change ... and fix a small bug revealed by that. --- crates/ra_hir/src/ty.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/ty.rs') diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 5cd766b85..7d25ade47 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -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` 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, -- cgit v1.2.3