]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/borrow_check/places_conflict.rs
Format the world
[rust.git] / src / librustc_mir / borrow_check / places_conflict.rs
1 use crate::borrow_check::ArtificialField;
2 use crate::borrow_check::Overlap;
3 use crate::borrow_check::{AccessDepth, Deep, Shallow};
4 use rustc::hir;
5 use rustc::mir::{
6     Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem, StaticKind,
7 };
8 use rustc::ty::{self, TyCtxt};
9 use std::cmp::max;
10
11 /// When checking if a place conflicts with another place, this enum is used to influence decisions
12 /// where a place might be equal or disjoint with another place, such as if `a[i] == a[j]`.
13 /// `PlaceConflictBias::Overlap` would bias toward assuming that `i` might equal `j` and that these
14 /// places overlap. `PlaceConflictBias::NoOverlap` assumes that for the purposes of the predicate
15 /// being run in the calling context, the conservative choice is to assume the compared indices
16 /// are disjoint (and therefore, do not overlap).
17 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
18 crate enum PlaceConflictBias {
19     Overlap,
20     NoOverlap,
21 }
22
23 /// Helper function for checking if places conflict with a mutable borrow and deep access depth.
24 /// This is used to check for places conflicting outside of the borrow checking code (such as in
25 /// dataflow).
26 crate fn places_conflict<'tcx>(
27     tcx: TyCtxt<'tcx>,
28     param_env: ty::ParamEnv<'tcx>,
29     body: &Body<'tcx>,
30     borrow_place: &Place<'tcx>,
31     access_place: &Place<'tcx>,
32     bias: PlaceConflictBias,
33 ) -> bool {
34     borrow_conflicts_with_place(
35         tcx,
36         param_env,
37         body,
38         borrow_place,
39         BorrowKind::Mut { allow_two_phase_borrow: true },
40         access_place.as_ref(),
41         AccessDepth::Deep,
42         bias,
43     )
44 }
45
46 /// Checks whether the `borrow_place` conflicts with the `access_place` given a borrow kind and
47 /// access depth. The `bias` parameter is used to determine how the unknowable (comparing runtime
48 /// array indices, for example) should be interpreted - this depends on what the caller wants in
49 /// order to make the conservative choice and preserve soundness.
50 pub(super) fn borrow_conflicts_with_place<'tcx>(
51     tcx: TyCtxt<'tcx>,
52     param_env: ty::ParamEnv<'tcx>,
53     body: &Body<'tcx>,
54     borrow_place: &Place<'tcx>,
55     borrow_kind: BorrowKind,
56     access_place: PlaceRef<'_, 'tcx>,
57     access: AccessDepth,
58     bias: PlaceConflictBias,
59 ) -> bool {
60     debug!(
61         "borrow_conflicts_with_place({:?}, {:?}, {:?}, {:?})",
62         borrow_place, access_place, access, bias,
63     );
64
65     // This Local/Local case is handled by the more general code below, but
66     // it's so common that it's a speed win to check for it first.
67     if let Some(l1) = borrow_place.as_local() {
68         if let Some(l2) = access_place.as_local() {
69             return l1 == l2;
70         }
71     }
72
73     place_components_conflict(
74         tcx,
75         param_env,
76         body,
77         borrow_place,
78         borrow_kind,
79         access_place,
80         access,
81         bias,
82     )
83 }
84
85 fn place_components_conflict<'tcx>(
86     tcx: TyCtxt<'tcx>,
87     param_env: ty::ParamEnv<'tcx>,
88     body: &Body<'tcx>,
89     borrow_place: &Place<'tcx>,
90     borrow_kind: BorrowKind,
91     access_place: PlaceRef<'_, 'tcx>,
92     access: AccessDepth,
93     bias: PlaceConflictBias,
94 ) -> bool {
95     // The borrowck rules for proving disjointness are applied from the "root" of the
96     // borrow forwards, iterating over "similar" projections in lockstep until
97     // we can prove overlap one way or another. Essentially, we treat `Overlap` as
98     // a monoid and report a conflict if the product ends up not being `Disjoint`.
99     //
100     // At each step, if we didn't run out of borrow or place, we know that our elements
101     // have the same type, and that they only overlap if they are the identical.
102     //
103     // For example, if we are comparing these:
104     // BORROW:  (*x1[2].y).z.a
105     // ACCESS:  (*x1[i].y).w.b
106     //
107     // Then our steps are:
108     //       x1         |   x1          -- places are the same
109     //       x1[2]      |   x1[i]       -- equal or disjoint (disjoint if indexes differ)
110     //       x1[2].y    |   x1[i].y     -- equal or disjoint
111     //      *x1[2].y    |  *x1[i].y     -- equal or disjoint
112     //     (*x1[2].y).z | (*x1[i].y).w  -- we are disjoint and don't need to check more!
113     //
114     // Because `zip` does potentially bad things to the iterator inside, this loop
115     // also handles the case where the access might be a *prefix* of the borrow, e.g.
116     //
117     // BORROW:  (*x1[2].y).z.a
118     // ACCESS:  x1[i].y
119     //
120     // Then our steps are:
121     //       x1         |   x1          -- places are the same
122     //       x1[2]      |   x1[i]       -- equal or disjoint (disjoint if indexes differ)
123     //       x1[2].y    |   x1[i].y     -- equal or disjoint
124     //
125     // -- here we run out of access - the borrow can access a part of it. If this
126     // is a full deep access, then we *know* the borrow conflicts with it. However,
127     // if the access is shallow, then we can proceed:
128     //
129     //       x1[2].y    | (*x1[i].y)    -- a deref! the access can't get past this, so we
130     //                                     are disjoint
131     //
132     // Our invariant is, that at each step of the iteration:
133     //  - If we didn't run out of access to match, our borrow and access are comparable
134     //    and either equal or disjoint.
135     //  - If we did run out of access, the borrow can access a part of it.
136
137     let borrow_base = &borrow_place.base;
138     let access_base = access_place.base;
139
140     match place_base_conflict(tcx, param_env, borrow_base, access_base) {
141         Overlap::Arbitrary => {
142             bug!("Two base can't return Arbitrary");
143         }
144         Overlap::EqualOrDisjoint => {
145             // This is the recursive case - proceed to the next element.
146         }
147         Overlap::Disjoint => {
148             // We have proven the borrow disjoint - further
149             // projections will remain disjoint.
150             debug!("borrow_conflicts_with_place: disjoint");
151             return false;
152         }
153     }
154
155     // loop invariant: borrow_c is always either equal to access_c or disjoint from it.
156     for (i, (borrow_c, access_c)) in
157         borrow_place.projection.iter().zip(access_place.projection.iter()).enumerate()
158     {
159         debug!("borrow_conflicts_with_place: borrow_c = {:?}", borrow_c);
160         let borrow_proj_base = &borrow_place.projection[..i];
161
162         debug!("borrow_conflicts_with_place: access_c = {:?}", access_c);
163
164         // Borrow and access path both have more components.
165         //
166         // Examples:
167         //
168         // - borrow of `a.(...)`, access to `a.(...)`
169         // - borrow of `a.(...)`, access to `b.(...)`
170         //
171         // Here we only see the components we have checked so
172         // far (in our examples, just the first component). We
173         // check whether the components being borrowed vs
174         // accessed are disjoint (as in the second example,
175         // but not the first).
176         match place_projection_conflict(
177             tcx,
178             body,
179             borrow_base,
180             borrow_proj_base,
181             borrow_c,
182             access_c,
183             bias,
184         ) {
185             Overlap::Arbitrary => {
186                 // We have encountered different fields of potentially
187                 // the same union - the borrow now partially overlaps.
188                 //
189                 // There is no *easy* way of comparing the fields
190                 // further on, because they might have different types
191                 // (e.g., borrows of `u.a.0` and `u.b.y` where `.0` and
192                 // `.y` come from different structs).
193                 //
194                 // We could try to do some things here - e.g., count
195                 // dereferences - but that's probably not a good
196                 // idea, at least for now, so just give up and
197                 // report a conflict. This is unsafe code anyway so
198                 // the user could always use raw pointers.
199                 debug!("borrow_conflicts_with_place: arbitrary -> conflict");
200                 return true;
201             }
202             Overlap::EqualOrDisjoint => {
203                 // This is the recursive case - proceed to the next element.
204             }
205             Overlap::Disjoint => {
206                 // We have proven the borrow disjoint - further
207                 // projections will remain disjoint.
208                 debug!("borrow_conflicts_with_place: disjoint");
209                 return false;
210             }
211         }
212     }
213
214     if borrow_place.projection.len() > access_place.projection.len() {
215         for (i, elem) in borrow_place.projection[access_place.projection.len()..].iter().enumerate()
216         {
217             // Borrow path is longer than the access path. Examples:
218             //
219             // - borrow of `a.b.c`, access to `a.b`
220             //
221             // Here, we know that the borrow can access a part of
222             // our place. This is a conflict if that is a part our
223             // access cares about.
224
225             let proj_base = &borrow_place.projection[..access_place.projection.len() + i];
226             let base_ty = Place::ty_from(borrow_base, proj_base, body, tcx).ty;
227
228             match (elem, &base_ty.kind, access) {
229                 (_, _, Shallow(Some(ArtificialField::ArrayLength)))
230                 | (_, _, Shallow(Some(ArtificialField::ShallowBorrow))) => {
231                     // The array length is like  additional fields on the
232                     // type; it does not overlap any existing data there.
233                     // Furthermore, if cannot actually be a prefix of any
234                     // borrowed place (at least in MIR as it is currently.)
235                     //
236                     // e.g., a (mutable) borrow of `a[5]` while we read the
237                     // array length of `a`.
238                     debug!("borrow_conflicts_with_place: implicit field");
239                     return false;
240                 }
241
242                 (ProjectionElem::Deref, _, Shallow(None)) => {
243                     // e.g., a borrow of `*x.y` while we shallowly access `x.y` or some
244                     // prefix thereof - the shallow access can't touch anything behind
245                     // the pointer.
246                     debug!("borrow_conflicts_with_place: shallow access behind ptr");
247                     return false;
248                 }
249                 (ProjectionElem::Deref, ty::Ref(_, _, hir::Mutability::Not), _) => {
250                     // Shouldn't be tracked
251                     bug!("Tracking borrow behind shared reference.");
252                 }
253                 (ProjectionElem::Deref, ty::Ref(_, _, hir::Mutability::Mut), AccessDepth::Drop) => {
254                     // Values behind a mutable reference are not access either by dropping a
255                     // value, or by StorageDead
256                     debug!("borrow_conflicts_with_place: drop access behind ptr");
257                     return false;
258                 }
259
260                 (ProjectionElem::Field { .. }, ty::Adt(def, _), AccessDepth::Drop) => {
261                     // Drop can read/write arbitrary projections, so places
262                     // conflict regardless of further projections.
263                     if def.has_dtor(tcx) {
264                         return true;
265                     }
266                 }
267
268                 (ProjectionElem::Deref, _, Deep)
269                 | (ProjectionElem::Deref, _, AccessDepth::Drop)
270                 | (ProjectionElem::Field { .. }, _, _)
271                 | (ProjectionElem::Index { .. }, _, _)
272                 | (ProjectionElem::ConstantIndex { .. }, _, _)
273                 | (ProjectionElem::Subslice { .. }, _, _)
274                 | (ProjectionElem::Downcast { .. }, _, _) => {
275                     // Recursive case. This can still be disjoint on a
276                     // further iteration if this a shallow access and
277                     // there's a deref later on, e.g., a borrow
278                     // of `*x.y` while accessing `x`.
279                 }
280             }
281         }
282     }
283
284     // Borrow path ran out but access path may not
285     // have. Examples:
286     //
287     // - borrow of `a.b`, access to `a.b.c`
288     // - borrow of `a.b`, access to `a.b`
289     //
290     // In the first example, where we didn't run out of
291     // access, the borrow can access all of our place, so we
292     // have a conflict.
293     //
294     // If the second example, where we did, then we still know
295     // that the borrow can access a *part* of our place that
296     // our access cares about, so we still have a conflict.
297     if borrow_kind == BorrowKind::Shallow
298         && borrow_place.projection.len() < access_place.projection.len()
299     {
300         debug!("borrow_conflicts_with_place: shallow borrow");
301         false
302     } else {
303         debug!("borrow_conflicts_with_place: full borrow, CONFLICT");
304         true
305     }
306 }
307
308 // Given that the bases of `elem1` and `elem2` are always either equal
309 // or disjoint (and have the same type!), return the overlap situation
310 // between `elem1` and `elem2`.
311 fn place_base_conflict<'tcx>(
312     tcx: TyCtxt<'tcx>,
313     param_env: ty::ParamEnv<'tcx>,
314     elem1: &PlaceBase<'tcx>,
315     elem2: &PlaceBase<'tcx>,
316 ) -> Overlap {
317     match (elem1, elem2) {
318         (PlaceBase::Local(l1), PlaceBase::Local(l2)) => {
319             if l1 == l2 {
320                 // the same local - base case, equal
321                 debug!("place_element_conflict: DISJOINT-OR-EQ-LOCAL");
322                 Overlap::EqualOrDisjoint
323             } else {
324                 // different locals - base case, disjoint
325                 debug!("place_element_conflict: DISJOINT-LOCAL");
326                 Overlap::Disjoint
327             }
328         }
329         (PlaceBase::Static(s1), PlaceBase::Static(s2)) => {
330             match (&s1.kind, &s2.kind) {
331                 (StaticKind::Static, StaticKind::Static) => {
332                     if s1.def_id != s2.def_id {
333                         debug!("place_element_conflict: DISJOINT-STATIC");
334                         Overlap::Disjoint
335                     } else if tcx.is_mutable_static(s1.def_id) {
336                         // We ignore mutable statics - they can only be unsafe code.
337                         debug!("place_element_conflict: IGNORE-STATIC-MUT");
338                         Overlap::Disjoint
339                     } else {
340                         debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
341                         Overlap::EqualOrDisjoint
342                     }
343                 }
344                 (StaticKind::Promoted(promoted_1, _), StaticKind::Promoted(promoted_2, _)) => {
345                     if promoted_1 == promoted_2 {
346                         if let ty::Array(_, len) = s1.ty.kind {
347                             if let Some(0) = len.try_eval_usize(tcx, param_env) {
348                                 // Ignore conflicts with promoted [T; 0].
349                                 debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
350                                 return Overlap::Disjoint;
351                             }
352                         }
353                         // the same promoted - base case, equal
354                         debug!("place_element_conflict: DISJOINT-OR-EQ-PROMOTED");
355                         Overlap::EqualOrDisjoint
356                     } else {
357                         // different promoteds - base case, disjoint
358                         debug!("place_element_conflict: DISJOINT-PROMOTED");
359                         Overlap::Disjoint
360                     }
361                 }
362                 (_, _) => {
363                     debug!("place_element_conflict: DISJOINT-STATIC-PROMOTED");
364                     Overlap::Disjoint
365                 }
366             }
367         }
368         (PlaceBase::Local(_), PlaceBase::Static(_))
369         | (PlaceBase::Static(_), PlaceBase::Local(_)) => {
370             debug!("place_element_conflict: DISJOINT-STATIC-LOCAL-PROMOTED");
371             Overlap::Disjoint
372         }
373     }
374 }
375
376 // Given that the bases of `elem1` and `elem2` are always either equal
377 // or disjoint (and have the same type!), return the overlap situation
378 // between `elem1` and `elem2`.
379 fn place_projection_conflict<'tcx>(
380     tcx: TyCtxt<'tcx>,
381     body: &Body<'tcx>,
382     pi1_base: &PlaceBase<'tcx>,
383     pi1_proj_base: &[PlaceElem<'tcx>],
384     pi1_elem: &PlaceElem<'tcx>,
385     pi2_elem: &PlaceElem<'tcx>,
386     bias: PlaceConflictBias,
387 ) -> Overlap {
388     match (pi1_elem, pi2_elem) {
389         (ProjectionElem::Deref, ProjectionElem::Deref) => {
390             // derefs (e.g., `*x` vs. `*x`) - recur.
391             debug!("place_element_conflict: DISJOINT-OR-EQ-DEREF");
392             Overlap::EqualOrDisjoint
393         }
394         (ProjectionElem::Field(f1, _), ProjectionElem::Field(f2, _)) => {
395             if f1 == f2 {
396                 // same field (e.g., `a.y` vs. `a.y`) - recur.
397                 debug!("place_element_conflict: DISJOINT-OR-EQ-FIELD");
398                 Overlap::EqualOrDisjoint
399             } else {
400                 let ty = Place::ty_from(pi1_base, pi1_proj_base, body, tcx).ty;
401                 match ty.kind {
402                     ty::Adt(def, _) if def.is_union() => {
403                         // Different fields of a union, we are basically stuck.
404                         debug!("place_element_conflict: STUCK-UNION");
405                         Overlap::Arbitrary
406                     }
407                     _ => {
408                         // Different fields of a struct (`a.x` vs. `a.y`). Disjoint!
409                         debug!("place_element_conflict: DISJOINT-FIELD");
410                         Overlap::Disjoint
411                     }
412                 }
413             }
414         }
415         (ProjectionElem::Downcast(_, v1), ProjectionElem::Downcast(_, v2)) => {
416             // different variants are treated as having disjoint fields,
417             // even if they occupy the same "space", because it's
418             // impossible for 2 variants of the same enum to exist
419             // (and therefore, to be borrowed) at the same time.
420             //
421             // Note that this is different from unions - we *do* allow
422             // this code to compile:
423             //
424             // ```
425             // fn foo(x: &mut Result<i32, i32>) {
426             //     let mut v = None;
427             //     if let Ok(ref mut a) = *x {
428             //         v = Some(a);
429             //     }
430             //     // here, you would *think* that the
431             //     // *entirety* of `x` would be borrowed,
432             //     // but in fact only the `Ok` variant is,
433             //     // so the `Err` variant is *entirely free*:
434             //     if let Err(ref mut a) = *x {
435             //         v = Some(a);
436             //     }
437             //     drop(v);
438             // }
439             // ```
440             if v1 == v2 {
441                 debug!("place_element_conflict: DISJOINT-OR-EQ-FIELD");
442                 Overlap::EqualOrDisjoint
443             } else {
444                 debug!("place_element_conflict: DISJOINT-FIELD");
445                 Overlap::Disjoint
446             }
447         }
448         (ProjectionElem::Index(..), ProjectionElem::Index(..))
449         | (ProjectionElem::Index(..), ProjectionElem::ConstantIndex { .. })
450         | (ProjectionElem::Index(..), ProjectionElem::Subslice { .. })
451         | (ProjectionElem::ConstantIndex { .. }, ProjectionElem::Index(..))
452         | (ProjectionElem::Subslice { .. }, ProjectionElem::Index(..)) => {
453             // Array indexes (`a[0]` vs. `a[i]`). These can either be disjoint
454             // (if the indexes differ) or equal (if they are the same).
455             match bias {
456                 PlaceConflictBias::Overlap => {
457                     // If we are biased towards overlapping, then this is the recursive
458                     // case that gives "equal *or* disjoint" its meaning.
459                     debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-INDEX");
460                     Overlap::EqualOrDisjoint
461                 }
462                 PlaceConflictBias::NoOverlap => {
463                     // If we are biased towards no overlapping, then this is disjoint.
464                     debug!("place_element_conflict: DISJOINT-ARRAY-INDEX");
465                     Overlap::Disjoint
466                 }
467             }
468         }
469         (
470             ProjectionElem::ConstantIndex { offset: o1, min_length: _, from_end: false },
471             ProjectionElem::ConstantIndex { offset: o2, min_length: _, from_end: false },
472         )
473         | (
474             ProjectionElem::ConstantIndex { offset: o1, min_length: _, from_end: true },
475             ProjectionElem::ConstantIndex { offset: o2, min_length: _, from_end: true },
476         ) => {
477             if o1 == o2 {
478                 debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-CONSTANT-INDEX");
479                 Overlap::EqualOrDisjoint
480             } else {
481                 debug!("place_element_conflict: DISJOINT-ARRAY-CONSTANT-INDEX");
482                 Overlap::Disjoint
483             }
484         }
485         (
486             ProjectionElem::ConstantIndex {
487                 offset: offset_from_begin,
488                 min_length: min_length1,
489                 from_end: false,
490             },
491             ProjectionElem::ConstantIndex {
492                 offset: offset_from_end,
493                 min_length: min_length2,
494                 from_end: true,
495             },
496         )
497         | (
498             ProjectionElem::ConstantIndex {
499                 offset: offset_from_end,
500                 min_length: min_length1,
501                 from_end: true,
502             },
503             ProjectionElem::ConstantIndex {
504                 offset: offset_from_begin,
505                 min_length: min_length2,
506                 from_end: false,
507             },
508         ) => {
509             // both patterns matched so it must be at least the greater of the two
510             let min_length = max(min_length1, min_length2);
511             // `offset_from_end` can be in range `[1..min_length]`, 1 indicates the last
512             // element (like -1 in Python) and `min_length` the first.
513             // Therefore, `min_length - offset_from_end` gives the minimal possible
514             // offset from the beginning
515             if *offset_from_begin >= *min_length - *offset_from_end {
516                 debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-CONSTANT-INDEX-FE");
517                 Overlap::EqualOrDisjoint
518             } else {
519                 debug!("place_element_conflict: DISJOINT-ARRAY-CONSTANT-INDEX-FE");
520                 Overlap::Disjoint
521             }
522         }
523         (
524             ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
525             ProjectionElem::Subslice { from, to, from_end: false },
526         )
527         | (
528             ProjectionElem::Subslice { from, to, from_end: false },
529             ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
530         ) => {
531             if (from..to).contains(&offset) {
532                 debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-CONSTANT-INDEX-SUBSLICE");
533                 Overlap::EqualOrDisjoint
534             } else {
535                 debug!("place_element_conflict: DISJOINT-ARRAY-CONSTANT-INDEX-SUBSLICE");
536                 Overlap::Disjoint
537             }
538         }
539         (
540             ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
541             ProjectionElem::Subslice { from, .. },
542         )
543         | (
544             ProjectionElem::Subslice { from, .. },
545             ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false },
546         ) => {
547             if offset >= from {
548                 debug!("place_element_conflict: DISJOINT-OR-EQ-SLICE-CONSTANT-INDEX-SUBSLICE");
549                 Overlap::EqualOrDisjoint
550             } else {
551                 debug!("place_element_conflict: DISJOINT-SLICE-CONSTANT-INDEX-SUBSLICE");
552                 Overlap::Disjoint
553             }
554         }
555         (
556             ProjectionElem::ConstantIndex { offset, min_length: _, from_end: true },
557             ProjectionElem::Subslice { to, from_end: true, .. },
558         )
559         | (
560             ProjectionElem::Subslice { to, from_end: true, .. },
561             ProjectionElem::ConstantIndex { offset, min_length: _, from_end: true },
562         ) => {
563             if offset > to {
564                 debug!(
565                     "place_element_conflict: \
566                        DISJOINT-OR-EQ-SLICE-CONSTANT-INDEX-SUBSLICE-FE"
567                 );
568                 Overlap::EqualOrDisjoint
569             } else {
570                 debug!("place_element_conflict: DISJOINT-SLICE-CONSTANT-INDEX-SUBSLICE-FE");
571                 Overlap::Disjoint
572             }
573         }
574         (
575             ProjectionElem::Subslice { from: f1, to: t1, from_end: false },
576             ProjectionElem::Subslice { from: f2, to: t2, from_end: false },
577         ) => {
578             if f2 >= t1 || f1 >= t2 {
579                 debug!("place_element_conflict: DISJOINT-ARRAY-SUBSLICES");
580                 Overlap::Disjoint
581             } else {
582                 debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-SUBSLICES");
583                 Overlap::EqualOrDisjoint
584             }
585         }
586         (ProjectionElem::Subslice { .. }, ProjectionElem::Subslice { .. }) => {
587             debug!("place_element_conflict: DISJOINT-OR-EQ-SLICE-SUBSLICES");
588             Overlap::EqualOrDisjoint
589         }
590         (ProjectionElem::Deref, _)
591         | (ProjectionElem::Field(..), _)
592         | (ProjectionElem::Index(..), _)
593         | (ProjectionElem::ConstantIndex { .. }, _)
594         | (ProjectionElem::Subslice { .. }, _)
595         | (ProjectionElem::Downcast(..), _) => bug!(
596             "mismatched projections in place_element_conflict: {:?} and {:?}",
597             pi1_elem,
598             pi2_elem
599         ),
600     }
601 }