Skip to content

Commit 779041e

Browse files
committed
Streamline place_projection_conflict.
1 parent 19e5d0c commit 779041e

File tree

1 file changed

+36
-65
lines changed

1 file changed

+36
-65
lines changed

compiler/rustc_borrowck/src/places_conflict.rs

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,19 @@ fn place_projection_conflict<'tcx>(
295295
pi2_elem: PlaceElem<'tcx>,
296296
bias: PlaceConflictBias,
297297
) -> Overlap {
298+
use ProjectionElem::*;
298299
match (pi1_elem, pi2_elem) {
299-
(ProjectionElem::Deref, ProjectionElem::Deref) => {
300+
(Deref, Deref) => {
300301
// derefs (e.g., `*x` vs. `*x`) - recur.
301302
debug!("place_element_conflict: DISJOINT-OR-EQ-DEREF");
302303
Overlap::EqualOrDisjoint
303304
}
304-
(ProjectionElem::OpaqueCast(_), ProjectionElem::OpaqueCast(_)) => {
305+
(OpaqueCast(_), OpaqueCast(_)) => {
305306
// casts to other types may always conflict irrespective of the type being cast to.
306307
debug!("place_element_conflict: DISJOINT-OR-EQ-OPAQUE");
307308
Overlap::EqualOrDisjoint
308309
}
309-
(ProjectionElem::Field(f1, _), ProjectionElem::Field(f2, _)) => {
310+
(Field(f1, _), Field(f2, _)) => {
310311
if f1 == f2 {
311312
// same field (e.g., `a.y` vs. `a.y`) - recur.
312313
debug!("place_element_conflict: DISJOINT-OR-EQ-FIELD");
@@ -324,7 +325,7 @@ fn place_projection_conflict<'tcx>(
324325
}
325326
}
326327
}
327-
(ProjectionElem::Downcast(_, v1), ProjectionElem::Downcast(_, v2)) => {
328+
(Downcast(_, v1), Downcast(_, v2)) => {
328329
// different variants are treated as having disjoint fields,
329330
// even if they occupy the same "space", because it's
330331
// impossible for 2 variants of the same enum to exist
@@ -357,16 +358,8 @@ fn place_projection_conflict<'tcx>(
357358
Overlap::Disjoint
358359
}
359360
}
360-
(
361-
ProjectionElem::Index(..),
362-
ProjectionElem::Index(..)
363-
| ProjectionElem::ConstantIndex { .. }
364-
| ProjectionElem::Subslice { .. },
365-
)
366-
| (
367-
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. },
368-
ProjectionElem::Index(..),
369-
) => {
361+
(Index(..), Index(..) | ConstantIndex { .. } | Subslice { .. })
362+
| (ConstantIndex { .. } | Subslice { .. }, Index(..)) => {
370363
// Array indexes (`a[0]` vs. `a[i]`). These can either be disjoint
371364
// (if the indexes differ) or equal (if they are the same).
372365
match bias {
@@ -384,12 +377,12 @@ fn place_projection_conflict<'tcx>(
384377
}
385378
}
386379
(
387-
ProjectionElem::ConstantIndex { offset: o1, min_length: _, from_end: false },
388-
ProjectionElem::ConstantIndex { offset: o2, min_length: _, from_end: false },
380+
ConstantIndex { offset: o1, min_length: _, from_end: false },
381+
ConstantIndex { offset: o2, min_length: _, from_end: false },
389382
)
390383
| (
391-
ProjectionElem::ConstantIndex { offset: o1, min_length: _, from_end: true },
392-
ProjectionElem::ConstantIndex { offset: o2, min_length: _, from_end: true },
384+
ConstantIndex { offset: o1, min_length: _, from_end: true },
385+
ConstantIndex { offset: o2, min_length: _, from_end: true },
393386
) => {
394387
if o1 == o2 {
395388
debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-CONSTANT-INDEX");
@@ -400,28 +393,12 @@ fn place_projection_conflict<'tcx>(
400393
}
401394
}
402395
(
403-
ProjectionElem::ConstantIndex {
404-
offset: offset_from_begin,
405-
min_length: min_length1,
406-
from_end: false,
407-
},
408-
ProjectionElem::ConstantIndex {
409-
offset: offset_from_end,
410-
min_length: min_length2,
411-
from_end: true,
412-
},
396+
ConstantIndex { offset: offset_from_begin, min_length: min_length1, from_end: false },
397+
ConstantIndex { offset: offset_from_end, min_length: min_length2, from_end: true },
413398
)
414399
| (
415-
ProjectionElem::ConstantIndex {
416-
offset: offset_from_end,
417-
min_length: min_length1,
418-
from_end: true,
419-
},
420-
ProjectionElem::ConstantIndex {
421-
offset: offset_from_begin,
422-
min_length: min_length2,
423-
from_end: false,
424-
},
400+
ConstantIndex { offset: offset_from_end, min_length: min_length1, from_end: true },
401+
ConstantIndex { offset: offset_from_begin, min_length: min_length2, from_end: false },
425402
) => {
426403
// both patterns matched so it must be at least the greater of the two
427404
let min_length = max(min_length1, min_length2);
@@ -438,12 +415,12 @@ fn place_projection_conflict<'tcx>(
438415
}
439416
}
440417
(
441-
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
442-
ProjectionElem::Subslice { from, to, from_end: false },
418+
ConstantIndex { offset, min_length: _, from_end: false },
419+
Subslice { from, to, from_end: false },
443420
)
444421
| (
445-
ProjectionElem::Subslice { from, to, from_end: false },
446-
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
422+
Subslice { from, to, from_end: false },
423+
ConstantIndex { offset, min_length: _, from_end: false },
447424
) => {
448425
if (from..to).contains(&offset) {
449426
debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-CONSTANT-INDEX-SUBSLICE");
@@ -453,14 +430,8 @@ fn place_projection_conflict<'tcx>(
453430
Overlap::Disjoint
454431
}
455432
}
456-
(
457-
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
458-
ProjectionElem::Subslice { from, .. },
459-
)
460-
| (
461-
ProjectionElem::Subslice { from, .. },
462-
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
463-
) => {
433+
(ConstantIndex { offset, min_length: _, from_end: false }, Subslice { from, .. })
434+
| (Subslice { from, .. }, ConstantIndex { offset, min_length: _, from_end: false }) => {
464435
if offset >= from {
465436
debug!("place_element_conflict: DISJOINT-OR-EQ-SLICE-CONSTANT-INDEX-SUBSLICE");
466437
Overlap::EqualOrDisjoint
@@ -470,12 +441,12 @@ fn place_projection_conflict<'tcx>(
470441
}
471442
}
472443
(
473-
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: true },
474-
ProjectionElem::Subslice { to, from_end: true, .. },
444+
ConstantIndex { offset, min_length: _, from_end: true },
445+
Subslice { to, from_end: true, .. },
475446
)
476447
| (
477-
ProjectionElem::Subslice { to, from_end: true, .. },
478-
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: true },
448+
Subslice { to, from_end: true, .. },
449+
ConstantIndex { offset, min_length: _, from_end: true },
479450
) => {
480451
if offset > to {
481452
debug!(
@@ -489,8 +460,8 @@ fn place_projection_conflict<'tcx>(
489460
}
490461
}
491462
(
492-
ProjectionElem::Subslice { from: f1, to: t1, from_end: false },
493-
ProjectionElem::Subslice { from: f2, to: t2, from_end: false },
463+
Subslice { from: f1, to: t1, from_end: false },
464+
Subslice { from: f2, to: t2, from_end: false },
494465
) => {
495466
if f2 >= t1 || f1 >= t2 {
496467
debug!("place_element_conflict: DISJOINT-ARRAY-SUBSLICES");
@@ -500,19 +471,19 @@ fn place_projection_conflict<'tcx>(
500471
Overlap::EqualOrDisjoint
501472
}
502473
}
503-
(ProjectionElem::Subslice { .. }, ProjectionElem::Subslice { .. }) => {
474+
(Subslice { .. }, Subslice { .. }) => {
504475
debug!("place_element_conflict: DISJOINT-OR-EQ-SLICE-SUBSLICES");
505476
Overlap::EqualOrDisjoint
506477
}
507478
(
508-
ProjectionElem::Deref
509-
| ProjectionElem::Field(..)
510-
| ProjectionElem::Index(..)
511-
| ProjectionElem::ConstantIndex { .. }
512-
| ProjectionElem::Subtype(_)
513-
| ProjectionElem::OpaqueCast { .. }
514-
| ProjectionElem::Subslice { .. }
515-
| ProjectionElem::Downcast(..),
479+
Deref
480+
| Field(..)
481+
| Index(..)
482+
| ConstantIndex { .. }
483+
| Subtype(_)
484+
| OpaqueCast { .. }
485+
| Subslice { .. }
486+
| Downcast(..),
516487
_,
517488
) => bug!(
518489
"mismatched projections in place_element_conflict: {:?} and {:?}",

0 commit comments

Comments
 (0)