rustc_mir_build/builder/expr/
category.rs1use rustc_middle::thir::*;
2
3#[derive(Debug, PartialEq)]
4pub(crate) enum Category {
5 Place,
9
10 Constant,
13
14 Rvalue(RvalueFunc),
17}
18
19#[derive(Debug, PartialEq)]
22pub(crate) enum RvalueFunc {
23 Into,
26
27 AsRvalue,
29}
30
31impl Category {
32 pub(crate) fn of(ek: &ExprKind<'_>) -> Option<Category> {
35 match *ek {
36 ExprKind::Scope { .. } => None,
37
38 ExprKind::Field { .. }
39 | ExprKind::Deref { .. }
40 | ExprKind::Index { .. }
41 | ExprKind::UpvarRef { .. }
42 | ExprKind::VarRef { .. }
43 | ExprKind::PlaceTypeAscription { .. }
44 | ExprKind::ValueTypeAscription { .. }
45 | ExprKind::PlaceUnwrapUnsafeBinder { .. }
46 | ExprKind::ValueUnwrapUnsafeBinder { .. } => Some(Category::Place),
47
48 ExprKind::LogicalOp { .. }
49 | ExprKind::Match { .. }
50 | ExprKind::If { .. }
51 | ExprKind::Let { .. }
52 | ExprKind::NeverToAny { .. }
53 | ExprKind::Use { .. }
54 | ExprKind::Adt { .. }
55 | ExprKind::Borrow { .. }
56 | ExprKind::RawBorrow { .. }
57 | ExprKind::Yield { .. }
58 | ExprKind::Call { .. }
59 | ExprKind::ByUse { .. }
60 | ExprKind::InlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
61
62 ExprKind::Array { .. }
63 | ExprKind::Tuple { .. }
64 | ExprKind::Closure { .. }
65 | ExprKind::Unary { .. }
66 | ExprKind::Binary { .. }
67 | ExprKind::Box { .. }
68 | ExprKind::Cast { .. }
69 | ExprKind::PointerCoercion { .. }
70 | ExprKind::Repeat { .. }
71 | ExprKind::Assign { .. }
72 | ExprKind::AssignOp { .. }
73 | ExprKind::ThreadLocalRef(_)
74 | ExprKind::OffsetOf { .. }
75 | ExprKind::WrapUnsafeBinder { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)),
76
77 ExprKind::ConstBlock { .. }
78 | ExprKind::Literal { .. }
79 | ExprKind::NonHirLiteral { .. }
80 | ExprKind::ZstLiteral { .. }
81 | ExprKind::ConstParam { .. }
82 | ExprKind::StaticRef { .. }
83 | ExprKind::NamedConst { .. } => Some(Category::Constant),
84
85 ExprKind::Loop { .. }
86 | ExprKind::LoopMatch { .. }
87 | ExprKind::Block { .. }
88 | ExprKind::Break { .. }
89 | ExprKind::Continue { .. }
90 | ExprKind::ConstContinue { .. }
91 | ExprKind::Return { .. }
92 | ExprKind::Become { .. } =>
93 {
96 Some(Category::Rvalue(RvalueFunc::Into))
97 }
98 }
99 }
100}