mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
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:
parent
cbb418ebb8
commit
1ee779d1f7
@ -148,6 +148,10 @@ impl Substs {
|
|||||||
self.0.iter()
|
self.0.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.0.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) {
|
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:
|
// Without an Arc::make_mut_slice, we can't avoid the clone here:
|
||||||
let mut v: Vec<_> = self.0.iter().cloned().collect();
|
let mut v: Vec<_> = self.0.iter().cloned().collect();
|
||||||
@ -286,7 +290,8 @@ impl Ty {
|
|||||||
/// `Option<u32>` afterwards.)
|
/// `Option<u32>` afterwards.)
|
||||||
pub fn apply_substs(self, substs: Substs) -> Ty {
|
pub fn apply_substs(self, substs: Substs) -> Ty {
|
||||||
match self {
|
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 })
|
Ty::Apply(ApplicationTy { ctor, parameters: substs })
|
||||||
}
|
}
|
||||||
_ => self,
|
_ => self,
|
||||||
|
@ -817,7 +817,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||||||
Some(func.generic_params(self.db)),
|
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 substs = self.substs_for_method_call(def_generics, generic_args);
|
||||||
let method_ty = method_ty.apply_substs(substs);
|
let method_ty = method_ty.apply_substs(substs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user