From df74c59a085a99591b613b3537db29361a7c5e9b Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Mon, 9 Oct 2023 16:45:44 -0700 Subject: [PATCH] analyze: rewrite::unlower: expand doc comment for peel_temp with an example --- c2rust-analyze/src/rewrite/expr/unlower.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/c2rust-analyze/src/rewrite/expr/unlower.rs b/c2rust-analyze/src/rewrite/expr/unlower.rs index 88c7f2ef32..419d4adf2f 100644 --- a/c2rust-analyze/src/rewrite/expr/unlower.rs +++ b/c2rust-analyze/src/rewrite/expr/unlower.rs @@ -127,7 +127,7 @@ impl<'a, 'tcx> UnlowerVisitor<'a, 'tcx> { } /// Special `record` variant for MIR [`Operand`]s. This sets the [`MirOriginDesc`] to - /// `LoadFromLocal` if `op` is a MIR temporary and otherwise sets it to `Expr`. + /// `LoadFromTemp` if `op` is a MIR temporary and otherwise sets it to `Expr`. /// /// [`Operand`]: mir::Operand fn record_operand( @@ -491,7 +491,23 @@ impl<'a, 'tcx> VisitExprState<'a, 'tcx> { /// If the current MIR is a temporary, and the previous `Location` is an assignment to /// that temporary, peel it off, leaving the temporary's initializer as the current - /// `Rvalue`. + /// `Rvalue`. This also adds `LoadFromTemp` and `StoreIntoLocal` entries in `self.temp_info` + /// for the temporary's use and definition. + /// + /// For example, starting from this position: + /// ```Rust,ignore + /// _temp = Add(_1, _2) + /// _3 = move _temp + /// ^^^^^ + /// ``` + /// A successful call to `peel_temp` will advance to this position: + /// ```Rust,ignore + /// _temp = Add(_1, _2) + /// ^^^^^^^^^^^ + /// _3 = move _temp + /// ``` + /// That is, it steps from a use of the temporary (an `Rvalue`, `Operand`, or `Place`) to the + /// `Rvalue` that was used to initialize that temporary. pub fn peel_temp(&mut self) -> Option<()> { // Run `peel_temp_inner`, and restore `self.cur` and `self.sub_loc` if it fails. let old_cur = self.cur;