Avoid a useless clone of UserTypeProjection

This commit is contained in:
Zalathar 2025-02-16 21:49:33 +11:00
parent bf3bb5fd37
commit a64efc72d0
2 changed files with 4 additions and 7 deletions

View File

@ -1516,8 +1516,8 @@ impl<'tcx> UserTypeProjections {
self.contents.iter().map(|&(ref user_type, _span)| user_type)
}
pub fn push_projection(mut self, user_ty: &UserTypeProjection, span: Span) -> Self {
self.contents.push((user_ty.clone(), span));
pub fn push_user_type(mut self, base_user_ty: UserTypeAnnotationIndex, span: Span) -> Self {
self.contents.push((UserTypeProjection { base: base_user_ty, projs: vec![] }, span));
self
}

View File

@ -926,12 +926,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Note that the variance doesn't apply here, as we are tracking the effect
// of `user_ty` on any bindings contained with subpattern.
let projection = UserTypeProjection {
base: self.canonical_user_type_annotations.push(annotation.clone()),
projs: Vec::new(),
};
let base_user_ty = self.canonical_user_type_annotations.push(annotation.clone());
let subpattern_user_ty =
pattern_user_ty.push_projection(&projection, annotation.span);
pattern_user_ty.push_user_type(base_user_ty, annotation.span);
self.visit_primary_bindings(subpattern, subpattern_user_ty, f)
}