Skip to content

Commit eaf0621

Browse files
committed
Dont duplicate entries in user annotations vector for every projection of a type.
This is a slight modification of PR 55937 and perhaps could/should be cherry-picked to that PR. Note that I am not doing this as a space optimization. I am doing it for its semantic effect: having a single entry in the annotations vector means that the different projections share that entry, and thus share the inferred region variables for it. Prior to this change, each projection would get its own set of inferred regions, which made it hard to resolve issue 55748.
1 parent 194e25d commit eaf0621

File tree

1 file changed

+6
-1
lines changed
  • src/librustc_mir/hair/pattern

1 file changed

+6
-1
lines changed

src/librustc_mir/hair/pattern/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ impl<'tcx> PatternTypeProjection<'tcx> {
179179
annotations: &mut CanonicalUserTypeAnnotations<'tcx>,
180180
span: Span,
181181
) -> UserTypeProjection<'tcx> {
182-
let annotation_index = annotations.push((span, self.base));
182+
let annotation = (span, self.base);
183+
let annotation_index = if let Some(index) = annotations.position(|a| a == &annotation) {
184+
index
185+
} else {
186+
annotations.push(annotation)
187+
};
183188
UserTypeProjection {
184189
base: annotation_index,
185190
projs: self.projs

0 commit comments

Comments
 (0)