rustc_mir_build/builder/expr/
category.rs1use rustc_middle::thir::*;
2
3#[derive(#[automatically_derived]impl ::core::fmt::Debug for Category {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Place => ::core::fmt::Formatter::write_str(f, "Place"),
Self::Constant =>
::core::fmt::Formatter::write_str(f, "Constant"),
Self::Rvalue(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Rvalue", &__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Category
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for Category {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Rvalue(__self_0), Self::Rvalue(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq)]
4pub(crate) enum Category {
5 Place,
9
10 Constant,
13
14 Rvalue(RvalueFunc),
17}
18
19#[derive(#[automatically_derived]impl ::core::fmt::Debug for RvalueFunc {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RvalueFunc::Into => "Into",
RvalueFunc::AsRvalue => "AsRvalue",
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
RvalueFunc {
}
#[automatically_derived]impl ::core::cmp::PartialEq for RvalueFunc {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}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 {
38 ExprKind::Scope { .. } => None,
39
40 ExprKind::Field { .. }
41 | ExprKind::Deref { .. }
42 | ExprKind::Index { .. }
43 | ExprKind::UpvarRef { .. }
44 | ExprKind::VarRef { .. }
45 | ExprKind::PlaceTypeAscription { .. }
46 | ExprKind::ValueTypeAscription { .. }
47 | ExprKind::PlaceUnwrapUnsafeBinder { .. }
48 | ExprKind::ValueUnwrapUnsafeBinder { .. } => Some(Category::Place),
49
50 ExprKind::LogicalOp { .. }
51 | ExprKind::Match { .. }
52 | ExprKind::If { .. }
53 | ExprKind::Let { .. }
54 | ExprKind::NeverToAny { .. }
55 | ExprKind::ValueExpr { .. }
56 | ExprKind::Adt { .. }
57 | ExprKind::Borrow { .. }
58 | ExprKind::RawBorrow { .. }
59 | ExprKind::Yield { .. }
60 | ExprKind::Call { .. }
61 | ExprKind::ByUse { .. }
62 | ExprKind::InlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
63
64 ExprKind::Array { .. }
65 | ExprKind::Tuple { .. }
66 | ExprKind::Closure { .. }
67 | ExprKind::Unary { .. }
68 | ExprKind::Binary { .. }
69 | ExprKind::Cast { .. }
70 | ExprKind::PointerCoercion { .. }
71 | ExprKind::Repeat { .. }
72 | ExprKind::Assign { .. }
73 | ExprKind::AssignOp { .. }
74 | ExprKind::Reborrow { .. }
78 | ExprKind::ThreadLocalRef(_)
79 | ExprKind::WrapUnsafeBinder { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)),
80
81 ExprKind::ConstBlock { .. }
82 | ExprKind::Literal { .. }
83 | ExprKind::NonHirLiteral { .. }
84 | ExprKind::ZstLiteral { .. }
85 | ExprKind::ConstParam { .. }
86 | ExprKind::StaticRef { .. }
87 | ExprKind::NamedConst { .. } => Some(Category::Constant),
88
89 ExprKind::Loop { .. }
90 | ExprKind::LoopMatch { .. }
91 | ExprKind::Block { .. }
92 | ExprKind::Break { .. }
93 | ExprKind::Continue { .. }
94 | ExprKind::ConstContinue { .. }
95 | ExprKind::Return { .. }
96 | ExprKind::Become { .. } =>
97 {
100 Some(Category::Rvalue(RvalueFunc::Into))
101 }
102 }
103 }
104}