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