]>
Commit | Line | Data |
---|---|---|
17df50a5 | 1 | use rustc_middle::thir::*; |
e9174d1e SL |
2 | |
3 | #[derive(Debug, PartialEq)] | |
923072b8 | 4 | pub(crate) enum Category { |
e9174d1e SL |
5 | // An assignable memory location like `x`, `x.f`, `foo()[3]`, that |
6 | // sort of thing. Something that could appear on the LHS of an `=` | |
7 | // sign. | |
ff7c6d11 | 8 | Place, |
e9174d1e SL |
9 | |
10 | // A literal like `23` or `"foo"`. Does not include constant | |
11 | // expressions like `3 + 5`. | |
12 | Constant, | |
13 | ||
14 | // Something that generates a new value at runtime, like `x + y` | |
15 | // or `foo()`. | |
16 | Rvalue(RvalueFunc), | |
17 | } | |
18 | ||
19 | // Rvalues fall into different "styles" that will determine which fn | |
20 | // is best suited to generate them. | |
21 | #[derive(Debug, PartialEq)] | |
923072b8 | 22 | pub(crate) enum RvalueFunc { |
e9174d1e SL |
23 | // Best generated by `into`. This is generally exprs that |
24 | // cause branching, like `match`, but also includes calls. | |
25 | Into, | |
26 | ||
27 | // Best generated by `as_rvalue`. This is usually the case. | |
28 | AsRvalue, | |
29 | } | |
30 | ||
31 | /// Determines the category for a given expression. Note that scope | |
32 | /// and paren expressions have no category. | |
33 | impl Category { | |
923072b8 | 34 | pub(crate) fn of(ek: &ExprKind<'_>) -> Option<Category> { |
e9174d1e | 35 | match *ek { |
b039eaaf | 36 | ExprKind::Scope { .. } => None, |
e9174d1e | 37 | |
b7449926 XL |
38 | ExprKind::Field { .. } |
39 | | ExprKind::Deref { .. } | |
40 | | ExprKind::Index { .. } | |
fc512014 | 41 | | ExprKind::UpvarRef { .. } |
b7449926 | 42 | | ExprKind::VarRef { .. } |
0bf4aa26 XL |
43 | | ExprKind::PlaceTypeAscription { .. } |
44 | | ExprKind::ValueTypeAscription { .. } => Some(Category::Place), | |
e9174d1e | 45 | |
b7449926 | 46 | ExprKind::LogicalOp { .. } |
b7449926 | 47 | | ExprKind::Match { .. } |
5869c6ff | 48 | | ExprKind::If { .. } |
94222f64 | 49 | | ExprKind::Let { .. } |
b7449926 | 50 | | ExprKind::NeverToAny { .. } |
48663c56 | 51 | | ExprKind::Use { .. } |
60c5eb7d XL |
52 | | ExprKind::Adt { .. } |
53 | | ExprKind::Borrow { .. } | |
dfeec247 | 54 | | ExprKind::AddressOf { .. } |
74b04a01 | 55 | | ExprKind::Yield { .. } |
f9f354fc XL |
56 | | ExprKind::Call { .. } |
57 | | ExprKind::InlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::Into)), | |
e9174d1e | 58 | |
b7449926 XL |
59 | ExprKind::Array { .. } |
60 | | ExprKind::Tuple { .. } | |
b7449926 XL |
61 | | ExprKind::Closure { .. } |
62 | | ExprKind::Unary { .. } | |
63 | | ExprKind::Binary { .. } | |
64 | | ExprKind::Box { .. } | |
65 | | ExprKind::Cast { .. } | |
48663c56 | 66 | | ExprKind::Pointer { .. } |
b7449926 | 67 | | ExprKind::Repeat { .. } |
b7449926 XL |
68 | | ExprKind::Assign { .. } |
69 | | ExprKind::AssignOp { .. } | |
5099ac24 | 70 | | ExprKind::ThreadLocalRef(_) => Some(Category::Rvalue(RvalueFunc::AsRvalue)), |
e9174d1e | 71 | |
5e7ed085 FG |
72 | ExprKind::ConstBlock { .. } |
73 | | ExprKind::Literal { .. } | |
74 | | ExprKind::NonHirLiteral { .. } | |
75 | | ExprKind::ConstParam { .. } | |
76 | | ExprKind::StaticRef { .. } | |
77 | | ExprKind::NamedConst { .. } => Some(Category::Constant), | |
e9174d1e | 78 | |
b7449926 XL |
79 | ExprKind::Loop { .. } |
80 | | ExprKind::Block { .. } | |
81 | | ExprKind::Break { .. } | |
82 | | ExprKind::Continue { .. } | |
83 | | ExprKind::Return { .. } => | |
84 | // FIXME(#27840) these probably want their own | |
85 | // category, like "nonterminating" | |
86 | { | |
87 | Some(Category::Rvalue(RvalueFunc::Into)) | |
88 | } | |
e9174d1e SL |
89 | } |
90 | } | |
91 | } |