From 1f3d18718cd03c57c829b0c523981be25f7595e5 Mon Sep 17 00:00:00 2001 From: hkalbasi Date: Tue, 15 Mar 2022 22:34:05 +0330 Subject: [PATCH] fix const generic panic --- crates/hir_ty/src/infer/expr.rs | 17 ++++++++++++++--- crates/hir_ty/src/tests/regression.rs | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index e78a6377e5..ebbce33e01 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -1088,9 +1088,20 @@ impl<'a> InferenceContext<'a> { } } }; - let supplied_params = substs.len(); - for _ in supplied_params..total_len { - substs.push(GenericArgData::Ty(self.table.new_type_var()).intern(Interner)); + for (id, data) in def_generics.iter().skip(substs.len()) { + match data { + TypeOrConstParamData::TypeParamData(_) => { + substs.push(GenericArgData::Ty(self.table.new_type_var()).intern(Interner)) + } + TypeOrConstParamData::ConstParamData(_) => { + substs.push( + GenericArgData::Const(self.table.new_const_var( + self.db.const_param_ty(ConstParamId::from_unchecked(id)), + )) + .intern(Interner), + ) + } + } } assert_eq!(substs.len(), total_len); Substitution::from_iter(Interner, substs) diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 4a65b927ba..63faecbfaf 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs @@ -1431,3 +1431,26 @@ fn nalgebra_factorial() { "#, ) } + +#[test] +fn regression_11688_1() { + check_no_mismatches( + r#" + pub struct Buffer(T); + type Writer = Buffer; + impl Buffer { + fn extend_from_array(&mut self, xs: &[T; N]) { + loop {} + } + } + trait Encode { + fn encode(self, w: &mut Writer, s: &mut S); + } + impl Encode for u8 { + fn encode(self, w: &mut Writer, _: &mut S) { + w.extend_from_array(&self.to_le_bytes()); + } + } + "#, + ); +}