1use rustc_middle::bug;
2use rustc_middle::mir::visit::{
3MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext,
4};
56#[derive(#[automatically_derived]
impl ::core::cmp::Eq for DefUse {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for DefUse {
#[inline]
fn eq(&self, other: &DefUse) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::clone::Clone for DefUse {
#[inline]
fn clone(&self) -> DefUse {
match self {
DefUse::Def => DefUse::Def,
DefUse::Use => DefUse::Use,
DefUse::Drop => DefUse::Drop,
}
}
}Clone)]
7pub(crate) enum DefUse {
8 Def,
9 Use,
10 Drop,
11}
1213pub(crate) fn categorize(context: PlaceContext) -> Option<DefUse> {
14match context {
15///////////////////////////////////////////////////////////////////////////
16 // DEFS
1718PlaceContext::MutatingUse(MutatingUseContext::Store) |
1920// We let Call define the result in both the success and
21 // unwind cases. This is not really correct, however it
22 // does not seem to be observable due to the way that we
23 // generate MIR. To do things properly, we would apply
24 // the def in call only to the input from the success
25 // path and not the unwind path. -nmatsakis
26PlaceContext::MutatingUse(MutatingUseContext::Call) |
27 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) |
28 PlaceContext::MutatingUse(MutatingUseContext::Yield) |
2930// Storage live and storage dead aren't proper defines, but we can ignore
31 // values that come before them.
32PlaceContext::NonUse(NonUseContext::StorageLive) |
33 PlaceContext::NonUse(NonUseContext::StorageDead) => Some(DefUse::Def),
3435///////////////////////////////////////////////////////////////////////////
36 // REGULAR USES
37 //
38 // These are uses that occur *outside* of a drop. For the
39 // purposes of NLL, these are special in that **all** the
40 // lifetimes appearing in the variable must be live for each regular use.
4142PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) |
43 PlaceContext::MutatingUse(MutatingUseContext::Projection) |
4445// Borrows only consider their local used at the point of the borrow.
46 // This won't affect the results since we use this analysis for coroutines
47 // and we only care about the result at suspension points. Borrows cannot
48 // cross suspension points so this behavior is unproblematic.
49PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
50 PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
51 PlaceContext::NonMutatingUse(NonMutatingUseContext::FakeBorrow) |
5253// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
54 // contain dangling references.
55PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
56 PlaceContext::NonUse(NonUseContext::AscribeUserTy(_)) |
5758 PlaceContext::MutatingUse(MutatingUseContext::RawBorrow) |
59 PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow) |
60 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
61 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
62 PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) |
63 PlaceContext::MutatingUse(MutatingUseContext::Retag) =>
64Some(DefUse::Use),
6566///////////////////////////////////////////////////////////////////////////
67 // DROP USES
68 //
69 // These are uses that occur in a DROP (a MIR drop, not a
70 // call to `std::mem::drop()`). For the purposes of NLL,
71 // uses in drop are special because `#[may_dangle]`
72 // attributes can affect whether lifetimes must be live.
7374PlaceContext::MutatingUse(MutatingUseContext::Drop) =>
75Some(DefUse::Drop),
7677// Debug info is neither def nor use.
78PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,
7980// Backwards incompatible drop hint is not a use, just a marker for linting.
81PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint) => None,
8283 PlaceContext::MutatingUse(MutatingUseContext::SetDiscriminant) => {
84::rustc_middle::util::bug::bug_fmt(format_args!("These statements are not allowed in this MIR phase"))bug!("These statements are not allowed in this MIR phase")85 }
86 }
87}