@@ -88,6 +88,9 @@ define!(
8888 fn Discriminant <T >( place: T ) -> <T as :: core:: marker:: DiscriminantKind >:: Discriminant
8989) ;
9090define ! ( "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 ) ;
9194
9295/// Convenience macro for generating custom MIR.
9396///
@@ -145,6 +148,25 @@ pub macro mir {
145148 } }
146149}
147150
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+
148170/// Helper macro that extracts the `let` declarations out of a bunch of statements.
149171///
150172/// This macro is written using the "statement muncher" strategy. Each invocation parses the first
0 commit comments