1 use rustc_middle
::thir
::*;
3 #[derive(Debug, PartialEq)]
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 `=`
10 // A literal like `23` or `"foo"`. Does not include constant
11 // expressions like `3 + 5`.
14 // Something that generates a new value at runtime, like `x + y`
19 // Rvalues fall into different "styles" that will determine which fn
20 // is best suited to generate them.
21 #[derive(Debug, PartialEq)]
22 crate enum RvalueFunc
{
23 // Best generated by `into`. This is generally exprs that
24 // cause branching, like `match`, but also includes calls.
27 // Best generated by `as_rvalue`. This is usually the case.
31 /// Determines the category for a given expression. Note that scope
32 /// and paren expressions have no category.
34 crate fn of(ek
: &ExprKind
<'_
>) -> Option
<Category
> {
36 ExprKind
::Scope { .. }
=> None
,
38 ExprKind
::Field { .. }
39 | ExprKind
::Deref { .. }
40 | ExprKind
::Index { .. }
41 | ExprKind
::UpvarRef { .. }
42 | ExprKind
::VarRef { .. }
43 | ExprKind
::PlaceTypeAscription { .. }
44 | ExprKind
::ValueTypeAscription { .. }
=> Some(Category
::Place
),
46 ExprKind
::LogicalOp { .. }
47 | ExprKind
::Match { .. }
49 | ExprKind
::NeverToAny { .. }
50 | ExprKind
::Use { .. }
51 | ExprKind
::Adt { .. }
52 | ExprKind
::Borrow { .. }
53 | ExprKind
::AddressOf { .. }
54 | ExprKind
::Yield { .. }
55 | ExprKind
::Call { .. }
56 | ExprKind
::InlineAsm { .. }
=> Some(Category
::Rvalue(RvalueFunc
::Into
)),
58 ExprKind
::Array { .. }
59 | ExprKind
::Tuple { .. }
60 | ExprKind
::Closure { .. }
61 | ExprKind
::Unary { .. }
62 | ExprKind
::Binary { .. }
63 | ExprKind
::Box { .. }
64 | ExprKind
::Cast { .. }
65 | ExprKind
::Pointer { .. }
66 | ExprKind
::Repeat { .. }
67 | ExprKind
::Assign { .. }
68 | ExprKind
::AssignOp { .. }
69 | ExprKind
::ThreadLocalRef(_
)
70 | ExprKind
::LlvmInlineAsm { .. }
=> Some(Category
::Rvalue(RvalueFunc
::AsRvalue
)),
72 ExprKind
::ConstBlock { .. }
| ExprKind
::Literal { .. }
| ExprKind
::StaticRef { .. }
=> {
73 Some(Category
::Constant
)
77 | ExprKind
::Block { .. }
78 | ExprKind
::Break { .. }
79 | ExprKind
::Continue { .. }
80 | ExprKind
::Return { .. }
=>
81 // FIXME(#27840) these probably want their own
82 // category, like "nonterminating"
84 Some(Category
::Rvalue(RvalueFunc
::Into
))