| 19 | } |
| 20 | |
| 21 | pub fn categorize(context: PlaceContext) -> Option<DefUse> { |
| 22 | match context { |
| 23 | /////////////////////////////////////////////////////////////////////////// |
| 24 | // DEFS |
| 25 | |
| 26 | PlaceContext::MutatingUse(MutatingUseContext::Store) | |
| 27 | |
| 28 | // We let Call define the result in both the success and |
| 29 | // unwind cases. This is not really correct, however it |
| 30 | // does not seem to be observable due to the way that we |
| 31 | // generate MIR. To do things properly, we would apply |
| 32 | // the def in call only to the input from the success |
| 33 | // path and not the unwind path. -nmatsakis |
| 34 | PlaceContext::MutatingUse(MutatingUseContext::Call) | |
| 35 | PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) | |
| 36 | PlaceContext::MutatingUse(MutatingUseContext::Yield) | |
| 37 | |
| 38 | // Storage live and storage dead aren't proper defines, but we can ignore |
| 39 | // values that come before them. |
| 40 | PlaceContext::NonUse(NonUseContext::StorageLive) | |
| 41 | PlaceContext::NonUse(NonUseContext::StorageDead) => Some(DefUse::Def), |
| 42 | |
| 43 | /////////////////////////////////////////////////////////////////////////// |
| 44 | // REGULAR USES |
| 45 | // |
| 46 | // These are uses that occur *outside* of a drop. For the |
| 47 | // purposes of NLL, these are special in that **all** the |
| 48 | // lifetimes appearing in the variable must be live for each regular use. |
| 49 | |
| 50 | PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) | |
| 51 | PlaceContext::MutatingUse(MutatingUseContext::Projection) | |
| 52 | |
| 53 | // Borrows only consider their local used at the point of the borrow. |
| 54 | // This won't affect the results since we use this analysis for generators |
| 55 | // and we only care about the result at suspension points. Borrows cannot |
| 56 | // cross suspension points so this behavior is unproblematic. |
| 57 | PlaceContext::MutatingUse(MutatingUseContext::Borrow) | |
| 58 | PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) | |
| 59 | PlaceContext::NonMutatingUse(NonMutatingUseContext::FakeBorrow) | |
| 60 | PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention)| |
| 61 | |
| 62 | PlaceContext::MutatingUse(MutatingUseContext::RawBorrow) | |
| 63 | PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow) | |
| 64 | PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) | |
| 65 | PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) | |
| 66 | PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) | |
| 67 | PlaceContext::NonUse(NonUseContext::AscribeUserTy(_)) | |
| 68 | PlaceContext::MutatingUse(MutatingUseContext::Retag) => |
| 69 | Some(DefUse::Use), |
| 70 | |
| 71 | /////////////////////////////////////////////////////////////////////////// |
| 72 | // DROP USES |
| 73 | // |
| 74 | // These are uses that occur in a DROP (a MIR drop, not a |
| 75 | // call to `std::mem::drop()`). For the purposes of NLL, |
| 76 | // uses in drop are special because `#[may_dangle]` |
| 77 | // attributes can affect whether lifetimes must be live. |
| 78 | |