@@ -88,6 +88,9 @@ define!(
88
88
fn Discriminant <T >( place: T ) -> <T as :: core:: marker:: DiscriminantKind >:: Discriminant
89
89
) ;
90
90
define ! ( "mir_set_discriminant" , fn SetDiscriminant <T >( place: T , index: u32 ) ) ;
91
+ define ! ( "mir_field" , fn Field <F >( place: ( ) , field: u32 ) -> F ) ;
92
+ define ! ( "mir_variant" , fn Variant <T >( place: T , index: u32 ) -> ( ) ) ;
93
+ define ! ( "mir_make_place" , fn __internal_make_place<T >( place: T ) -> * mut T ) ;
91
94
92
95
/// Convenience macro for generating custom MIR.
93
96
///
@@ -145,6 +148,25 @@ pub macro mir {
145
148
} }
146
149
}
147
150
151
+ /// Helper macro that allows you to treat a value expression like a place expression.
152
+ ///
153
+ /// This is necessary in combination with the [`Field`] and [`Variant`] methods. Specifically,
154
+ /// something like this won't compile on its own, reporting an error about not being able to assign
155
+ /// to such an expression:
156
+ ///
157
+ /// ```rust,ignore(syntax-highlighting-only)
158
+ /// Field(something, 0) = 5;
159
+ /// ```
160
+ ///
161
+ /// Instead, you'll need to write
162
+ ///
163
+ /// ```rust,ignore(syntax-highlighting-only)
164
+ /// place!(Field(something, 0)) = 5;
165
+ /// ```
166
+ pub macro place( $e: expr) {
167
+ ( * :: core:: intrinsics:: mir:: __internal_make_place ( $e) )
168
+ }
169
+
148
170
/// Helper macro that extracts the `let` declarations out of a bunch of statements.
149
171
///
150
172
/// This macro is written using the "statement muncher" strategy. Each invocation parses the first
0 commit comments