rust-lang/rust-clippy · error

some moved values might need to be renamed to avoid wrong…

Error message

some moved values might need to be renamed to avoid wrong references

What it means

A note attached to the branches_sharing_code lint's move-after-if suggestion: after hoisting duplicated tail statements out of the branches, bindings moved into the extracted code may still be referenced by name in the branches (or vice versa), so the same identifier can now refer to the pre-move binding while the value actually lives in the moved statement. The suggestion is emitted with Applicability::Unspecified precisely because identifiers may need renaming; the note additionally warns when the if expression's value is consumed (e.g. assigned), making the end-suggestion riskier.

Solutions

  1. Apply the move suggestion, then rename the affected variables so each reference points at the intended binding
  2. Re-run cargo check after the move to catch any borrow/move errors introduced by the hoisting
  3. If the statement order or value flow is too entangled, skip the automated suggestion and refactor manually
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at clippy_lints/src/ifs/branches_sharing_code.rs:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rust-lang/rust-clippy@13aece1138 (2026-09-07). Data as JSON: /api/errors/54a93e7b039bda7e. Report an issue: GitHub.

Appendix: source

Thrown at clippy_lints/src/ifs/branches_sharing_code.rs:101

                span,
                "consider moving these statements before the if",
                sugg,
                Applicability::Unspecified,
            );
        }
        if let Some((span, sugg)) = end_suggestion {
            diag.span_suggestion(
                span,
                "consider moving these statements after the if",
                sugg,
                Applicability::Unspecified,
            );
            if is_expr_parent_assignment(cx, expr) || !cx.typeck_results().expr_ty(expr).is_unit() {
                diag.note("the end suggestion probably needs some adjustments to use the expression result correctly");
            }
        }
        if check_for_warn_of_moved_symbol(cx, &res.moved_locals, expr) {
            diag.warn("some moved values might need to be renamed to avoid wrong references");
        }
    });
}

/// Detects `match` expressions where every arm's body is a block ending in the same trailing
/// expression, so that expression can be hoisted out below the `match`.
///
/// ```ignore
/// match mode {
///     Mode::A => { a(); Ok(()) }
///     Mode::B => { b(); Ok(()) }
/// }
/// ```
/// can become
/// ```ignore
/// match mode {
///     Mode::A => a(),
///     Mode::B => b(),

View on GitHub (pinned to 13aece1138)