Skip to content

Commit ebfc2b0

Browse files
jieyouxugitbot
authored and
gitbot
committed
Rollup merge of rust-lang#133625 - RalfJung:custom-mir-debug-info, r=compiler-errors
custom MIR: add doc comment for debuginfo This is a revival of rust-lang#117015
2 parents 3b7cfff + 81ded22 commit ebfc2b0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

core/src/intrinsics/mir.rs

+33
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,39 @@
249249
//! `Call(ret_val = function(arg1, arg2, ...), ReturnTo(next_block), UnwindContinue())`.
250250
//! - [`TailCall`] does not have a return destination or next block, so its syntax is just
251251
//! `TailCall(function(arg1, arg2, ...))`.
252+
//!
253+
//! #### Debuginfo
254+
//!
255+
//! Debuginfo associates source code variable names (of variables that may not exist any more) with
256+
//! MIR expressions that indicate where the value of that variable is stored. The syntax to do so
257+
//! is:
258+
//! ```text
259+
//! debug source_var_name => expression;
260+
//! ```
261+
//! Both places and constants are supported in the `expression`.
262+
//!
263+
//! ```rust
264+
//! #![allow(internal_features)]
265+
//! #![feature(core_intrinsics, custom_mir)]
266+
//!
267+
//! use core::intrinsics::mir::*;
268+
//!
269+
//! #[custom_mir(dialect = "built")]
270+
//! fn debuginfo(arg: Option<&i32>) {
271+
//! mir!(
272+
//! // Debuginfo for a source variable `plain_local` that just duplicates `arg`.
273+
//! debug plain_local => arg;
274+
//! // Debuginfo for a source variable `projection` that can be computed by dereferencing
275+
//! // a field of `arg`.
276+
//! debug projection => *Field::<&i32>(Variant(arg, 1), 0);
277+
//! // Debuginfo for a source variable `constant` that always holds the value `5`.
278+
//! debug constant => 5_usize;
279+
//! {
280+
//! Return()
281+
//! }
282+
//! )
283+
//! }
284+
//! ```
252285
253286
#![unstable(
254287
feature = "custom_mir",

0 commit comments

Comments
 (0)