From 389365631d3e6d2f533f896635e7768f26359575 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 23 Sep 2021 22:15:12 -0400 Subject: [PATCH] Fix tidy and respond to some feedback --- compiler/rustc_typeck/src/check/upvar.rs | 33 ++++++++++++++++++- .../preserve_field_drop_order.rs | 2 +- .../preserve_field_drop_order2.rs | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 036e1037383..917bf4ecd8c 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 ecc265208c5..ca3bfff2cf3 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 bc5c92122c6..3d39cb7ed48 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(); }