Skip to content

Commit

Permalink
Fix tidy and respond to some feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Sep 24, 2021
1 parent ab8aef4 commit 3893656
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
33 changes: 32 additions & 1 deletion compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {}
Expand All @@ -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
),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ fn test_three() {
fn main() {
test_one();
test_two();
test_three();
test_three();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 3893656

Please sign in to comment.