diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 036e103738364..917bf4ecd8c4a 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -617,6 +617,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for (_, captures) in &mut root_var_min_capture_list { captures.sort_by(|capture1, capture2| { for (p1, p2) in capture1.place.projections.iter().zip(&capture2.place.projections) { + // We do not need to look at the `Projection.ty` fields here because at each + // step of the iteration, the projections will either be the same and therefore + // the types must be as well or the current projection will be different and + // we will return the result of comparing the field indexes. match (p1.kind, p2.kind) { // Paths are the same, continue to next loop. (ProjectionKind::Deref, ProjectionKind::Deref) => {} @@ -628,7 +632,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return i1.cmp(&i2); } - (l, r) => bug!("ProjectionKinds were different: ({:?}, {:?})", l, r), + // We should have either a pair of `Deref`s or a pair of `Field`s. + // Anything else is a bug. + ( + l @ (ProjectionKind::Deref | ProjectionKind::Field(..)), + r @ (ProjectionKind::Deref | ProjectionKind::Field(..)), + ) => bug!( + "ProjectionKinds Deref and Field were mismatched: ({:?}, {:?})", + l, + r + ), + ( + l + @ + (ProjectionKind::Index + | ProjectionKind::Subslice + | ProjectionKind::Deref + | ProjectionKind::Field(..)), + r + @ + (ProjectionKind::Index + | ProjectionKind::Subslice + | ProjectionKind::Deref + | ProjectionKind::Field(..)), + ) => bug!( + "ProjectionKinds Index or Subslice were unexpected: ({:?}, {:?})", + l, + r + ), } } diff --git a/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs b/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs index ecc265208c56e..ca3bfff2cf30a 100644 --- a/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs +++ b/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs @@ -94,5 +94,5 @@ fn test_three() { fn main() { test_one(); test_two(); - test_three(); + test_three(); } diff --git a/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order2.rs b/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order2.rs index bc5c92122c6c8..3d39cb7ed481b 100644 --- a/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order2.rs +++ b/src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order2.rs @@ -23,6 +23,6 @@ fn main() { let a = A { x: Dropable(format!("x")), y: Dropable(format!("y")) }; let c = move || println!("{:?} {:?}", a.y, a.x); - + c(); }