]>
git.proxmox.com Git - rustc.git/blob - compiler/rustc_borrowck/src/def_use.rs
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 // We let Call define the result in both the success and
20 // unwind cases. This is not really correct, however it
21 // does not seem to be observable due to the way that we
22 // generate MIR. To do things properly, we would apply
23 // the def in call only to the input from the success
24 // path and not the unwind path. -nmatsakis
25 PlaceContext
::MutatingUse(MutatingUseContext
::Call
) |
26 PlaceContext
::MutatingUse(MutatingUseContext
::AsmOutput
) |
27 PlaceContext
::MutatingUse(MutatingUseContext
::Yield
) |
29 // Storage live and storage dead aren't proper defines, but we can ignore
30 // values that come before them.
31 PlaceContext
::NonUse(NonUseContext
::StorageLive
) |
32 PlaceContext
::NonUse(NonUseContext
::StorageDead
) => Some(DefUse
::Def
),
34 ///////////////////////////////////////////////////////////////////////////
37 // These are uses that occur *outside* of a drop. For the
38 // purposes of NLL, these are special in that **all** the
39 // lifetimes appearing in the variable must be live for each regular use.
41 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::Projection
) |
42 PlaceContext
::MutatingUse(MutatingUseContext
::Projection
) |
44 // Borrows only consider their local used at the point of the borrow.
45 // This won't affect the results since we use this analysis for generators
46 // and we only care about the result at suspension points. Borrows cannot
47 // cross suspension points so this behavior is unproblematic.
48 PlaceContext
::MutatingUse(MutatingUseContext
::Borrow
) |
49 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::SharedBorrow
) |
50 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::ShallowBorrow
) |
51 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::UniqueBorrow
) |
53 PlaceContext
::MutatingUse(MutatingUseContext
::AddressOf
) |
54 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::AddressOf
) |
55 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::Inspect
) |
56 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::Copy
) |
57 PlaceContext
::NonMutatingUse(NonMutatingUseContext
::Move
) |
58 PlaceContext
::NonUse(NonUseContext
::AscribeUserTy
) |
59 PlaceContext
::MutatingUse(MutatingUseContext
::Retag
) =>
62 ///////////////////////////////////////////////////////////////////////////
65 // These are uses that occur in a DROP (a MIR drop, not a
66 // call to `std::mem::drop()`). For the purposes of NLL,
67 // uses in drop are special because `#[may_dangle]`
68 // attributes can affect whether lifetimes must be live.
70 PlaceContext
::MutatingUse(MutatingUseContext
::Drop
) =>
73 // Debug info is neither def nor use.
74 PlaceContext
::NonUse(NonUseContext
::VarDebugInfo
) => None
,
76 PlaceContext
::MutatingUse(MutatingUseContext
::Deinit
| MutatingUseContext
::SetDiscriminant
) => {
77 bug
!("These statements are not allowed in this MIR phase")