Skip to content

Commit

Permalink
Dont duplicate entries in user annotations vector for every projectio…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
pnkfelix committed Dec 19, 2018
1 parent 194e25d commit eaf0621
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ impl<'tcx> PatternTypeProjection<'tcx> {
annotations: &mut CanonicalUserTypeAnnotations<'tcx>,
span: Span,
) -> UserTypeProjection<'tcx> {
let annotation_index = annotations.push((span, self.base));
let annotation = (span, self.base);
let annotation_index = if let Some(index) = annotations.position(|a| a == &annotation) {
index
} else {
annotations.push(annotation)
};
UserTypeProjection {
base: annotation_index,
projs: self.projs
Expand Down

0 comments on commit eaf0621

Please sign in to comment.