Skip to content

Commit

Permalink
analyze: rewrite::unlower: expand doc comment for peel_temp with an e…
Browse files Browse the repository at this point in the history
…xample
  • Loading branch information
spernsteiner committed Oct 9, 2023
1 parent 60aa23e commit df74c59
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions c2rust-analyze/src/rewrite/expr/unlower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit df74c59

Please sign in to comment.