1 use rustc_middle::mir::visit::{
2 MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext,
5 #[derive(Eq, PartialEq, Clone)]
12 pub fn categorize(context: PlaceContext) -> Option<DefUse> {
14 ///////////////////////////////////////////////////////////////////////////
17 PlaceContext::MutatingUse(MutatingUseContext::Store) |
19 // This is potentially both a def and a use...
20 PlaceContext::MutatingUse(MutatingUseContext::LlvmAsmOutput) |
22 // We let Call define the result in both the success and
23 // unwind cases. This is not really correct, however it
24 // does not seem to be observable due to the way that we
25 // generate MIR. To do things properly, we would apply
26 // the def in call only to the input from the success
27 // path and not the unwind path. -nmatsakis
28 PlaceContext::MutatingUse(MutatingUseContext::Call) |
29 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) |
30 PlaceContext::MutatingUse(MutatingUseContext::Yield) |
32 // Storage live and storage dead aren't proper defines, but we can ignore
33 // values that come before them.
34 PlaceContext::NonUse(NonUseContext::StorageLive) |
35 PlaceContext::NonUse(NonUseContext::StorageDead) => Some(DefUse::Def),
37 ///////////////////////////////////////////////////////////////////////////
40 // These are uses that occur *outside* of a drop. For the
41 // purposes of NLL, these are special in that **all** the
42 // lifetimes appearing in the variable must be live for each regular use.
44 PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) |
45 PlaceContext::MutatingUse(MutatingUseContext::Projection) |
47 // Borrows only consider their local used at the point of the borrow.
48 // This won't affect the results since we use this analysis for generators
49 // and we only care about the result at suspension points. Borrows cannot
50 // cross suspension points so this behavior is unproblematic.
51 PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
52 PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
53 PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
54 PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
56 PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |
57 PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf) |
58 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
59 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
60 PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) |
61 PlaceContext::NonUse(NonUseContext::AscribeUserTy) |
62 PlaceContext::MutatingUse(MutatingUseContext::Retag) =>
65 ///////////////////////////////////////////////////////////////////////////
68 // These are uses that occur in a DROP (a MIR drop, not a
69 // call to `std::mem::drop()`). For the purposes of NLL,
70 // uses in drop are special because `#[may_dangle]`
71 // attributes can affect whether lifetimes must be live.
73 PlaceContext::MutatingUse(MutatingUseContext::Drop) =>
76 // Debug info is neither def nor use.
77 PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,