Skip to content

Commit 3893656

Browse files
committed
Fix tidy and respond to some feedback
1 parent ab8aef4 commit 3893656

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

compiler/rustc_typeck/src/check/upvar.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
617617
for (_, captures) in &mut root_var_min_capture_list {
618618
captures.sort_by(|capture1, capture2| {
619619
for (p1, p2) in capture1.place.projections.iter().zip(&capture2.place.projections) {
620+
// We do not need to look at the `Projection.ty` fields here because at each
621+
// step of the iteration, the projections will either be the same and therefore
622+
// the types must be as well or the current projection will be different and
623+
// we will return the result of comparing the field indexes.
620624
match (p1.kind, p2.kind) {
621625
// Paths are the same, continue to next loop.
622626
(ProjectionKind::Deref, ProjectionKind::Deref) => {}
@@ -628,7 +632,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
628632
return i1.cmp(&i2);
629633
}
630634

631-
(l, r) => bug!("ProjectionKinds were different: ({:?}, {:?})", l, r),
635+
// We should have either a pair of `Deref`s or a pair of `Field`s.
636+
// Anything else is a bug.
637+
(
638+
l @ (ProjectionKind::Deref | ProjectionKind::Field(..)),
639+
r @ (ProjectionKind::Deref | ProjectionKind::Field(..)),
640+
) => bug!(
641+
"ProjectionKinds Deref and Field were mismatched: ({:?}, {:?})",
642+
l,
643+
r
644+
),
645+
(
646+
l
647+
@
648+
(ProjectionKind::Index
649+
| ProjectionKind::Subslice
650+
| ProjectionKind::Deref
651+
| ProjectionKind::Field(..)),
652+
r
653+
@
654+
(ProjectionKind::Index
655+
| ProjectionKind::Subslice
656+
| ProjectionKind::Deref
657+
| ProjectionKind::Field(..)),
658+
) => bug!(
659+
"ProjectionKinds Index or Subslice were unexpected: ({:?}, {:?})",
660+
l,
661+
r
662+
),
632663
}
633664
}
634665

src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ fn test_three() {
9494
fn main() {
9595
test_one();
9696
test_two();
97-
test_three();
97+
test_three();
9898
}

src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ fn main() {
2323
let a = A { x: Dropable(format!("x")), y: Dropable(format!("y")) };
2424

2525
let c = move || println!("{:?} {:?}", a.y, a.x);
26-
26+
2727
c();
2828
}

0 commit comments

Comments
 (0)