Skip to content

fix[154166]: closure debug capture print - #162154

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
joseph-isaacs:ji/issue-154166-mir-closure-debug
Sep 4, 2026
Merged

fix[154166]: closure debug capture print#162154
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
joseph-isaacs:ji/issue-154166-mir-closure-debug

Conversation

@joseph-isaacs

@joseph-isaacs joseph-isaacs commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Found and remove the // FIXME(project-rfc-2229#48) see in mir/pretty.rs used to Debug print mir.

Fix was to replace the old tcx.upvars_mentioned with tcx.closure_captures.
Added a test to check for printing of both in 2018 and 2021

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 1, 2026
@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @folkertdev (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir
  • compiler, mir expanded to 75 candidates
  • Random selection from 21 candidates

@folkertdev

Copy link
Copy Markdown
Contributor

r? types

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Sep 1, 2026
@rustbot rustbot assigned spastorino and unassigned folkertdev Sep 1, 2026
@spastorino

Copy link
Copy Markdown
Member

I think this is correct but can you share the before and after MIR of #154166

@joseph-isaacs

joseph-isaacs commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author
 $ diff -u mir_dump/issue-162074.mir.before mir_dump/issue-162074.mir.after
--- mir_dump/issue-162074.mir.before    2026-09-03 00:15:41
+++ mir_dump/issue-162074.mir.after     2026-09-03 00:12:38
@@ -12,7 +12,7 @@
 
     bb0: {
         _3 = &(_1.1: std::string::String);
-        _2 = {closure@tests/mir-opt/issues/issue_154166.rs:13:20: 13:22} { x: move (_1.0: std::string::String) };
+        _2 = {closure@tests/mir-opt/issues/issue_154166.rs:13:20: 13:22} { x__0: move (_1.0: std::string::String), x__1: move _3 };
         drop(_2) -> [return: bb1, unwind: bb4];
     }

Compiled using

rustc \                                          
    tests/mir-opt/issues/issue_154166.rs \
    --edition=2021 \
    -Zunpretty=mir
after MIR
 $ cat mir_dump/issue-162074.mir.after
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
// HINT: See also -Z dump-mir for MIR at specific points during compilation.
fn foo(_1: (String, String)) -> () {
    debug x => _1;
    let mut _0: ();
    let _2: {closure@tests/mir-opt/issues/issue_154166.rs:13:20: 13:22};
    let mut _3: &std::string::String;
    scope 1 {
        debug _closure => _2;
    }

    bb0: {
        _3 = &(_1.1: std::string::String);
        _2 = {closure@tests/mir-opt/issues/issue_154166.rs:13:20: 13:22} { x__0: move (_1.0: std::string::String), x__1: move _3 };
        drop(_2) -> [return: bb1, unwind: bb4];
    }

    bb1: {
        drop((_1.1: std::string::String)) -> [return: bb2, unwind continue];
    }

    bb2: {
        return;
    }

    bb3 (cleanup): {
        resume;
    }

    bb4 (cleanup): {
        drop((_1.1: std::string::String)) -> [return: bb3, unwind terminate(cleanup)];
    }
}

fn foo::{closure#0}(_1: {closure@tests/mir-opt/issues/issue_154166.rs:13:20: 13:22}) -> () {
    debug x__0 => (_1.0: std::string::String);
    debug x__1 => (*(_1.1: &std::string::String));
    let mut _0: ();
    let mut _2: bool;
    let _3: std::string::String;
    let mut _4: &std::string::String;
    let mut _5: bool;
    scope 1 {
        debug _a => _4;
    }
    scope 2 {
        debug _b => _3;
    }

    bb0: {
        _5 = const false;
        _5 = const true;
        _2 = std::hint::black_box::<bool>(const true) -> [return: bb1, unwind: bb9];
    }

    bb1: {
        switchInt(move _2) -> [0: bb3, otherwise: bb2];
    }

    bb2: {
        _4 = no_retag copy (_1.1: &std::string::String);
        goto -> bb4;
    }

    bb3: {
        _5 = const false;
        _3 = move (_1.0: std::string::String);
        drop(_3) -> [return: bb4, unwind: bb9];
    }

    bb4: {
        switchInt(copy _5) -> [0: bb5, otherwise: bb7];
    }

    bb5: {
        return;
    }

    bb6 (cleanup): {
        resume;
    }

    bb7: {
        drop((_1.0: std::string::String)) -> [return: bb5, unwind continue];
    }

    bb8 (cleanup): {
        drop((_1.0: std::string::String)) -> [return: bb6, unwind terminate(cleanup)];
    }

    bb9 (cleanup): {
        switchInt(copy _5) -> [0: bb6, otherwise: bb8];
    }
}

@spastorino

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8c4486b has been approved by spastorino

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 3, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 3, 2026
…closure-debug, r=spastorino

fix[154166]: closure debug capture print

Found and remove the `// FIXME(project-rfc-2229#48)` [see](rust-lang/rfcs#2229) in `mir/pretty.rs` used to Debug print mir.

Fix was to replace the old `tcx.upvars_mentioned` with `tcx.closure_captures`.
Added a test to check for printing of both in 2018 and 2021
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 3, 2026
…closure-debug, r=spastorino

fix[154166]: closure debug capture print

Found and remove the `// FIXME(project-rfc-2229#48)` [see](rust-lang/rfcs#2229) in `mir/pretty.rs` used to Debug print mir.

Fix was to replace the old `tcx.upvars_mentioned` with `tcx.closure_captures`.
Added a test to check for printing of both in 2018 and 2021
rust-bors Bot pushed a commit that referenced this pull request Sep 3, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #161227 (implement `Add` and `Sub` for `Complex`)
 - #161280 (make target feature ABI check a hard error on ARM)
 - #161893 (Add custom allocator support to `(try_)map` on `UniqueArc` and `UniqueRc`)
 - #162154 (fix[154166]: closure debug capture print)
 - #161951 (Windows: add fallback if `canonicalize` fails)
 - #162173 (fix supposedly unreachable `bug!` being reachable)
 - #162180 (remove outdated next-solver handling)
 - #162191 (core: mark float `ClampBounds` methods as `#[inline]`)
 - #162195 (docs(time): clarify exact seconds for week and day)
 - #162199 (docs(time): clarify exact seconds for hour and minute)
 - #162222 (coverage: Small cleanups in `extract_hir_info`)
 - #162230 (Pass -Z merge-functions=disabled in tests/codegen-llvm/intrinsics/unchecked_math.rs)
rust-bors Bot pushed a commit that referenced this pull request Sep 4, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #161227 (implement `Add` and `Sub` for `Complex`)
 - #161280 (make target feature ABI check a hard error on ARM)
 - #161893 (Add custom allocator support to `(try_)map` on `UniqueArc` and `UniqueRc`)
 - #162154 (fix[154166]: closure debug capture print)
 - #161951 (Windows: add fallback if `canonicalize` fails)
 - #162173 (fix supposedly unreachable `bug!` being reachable)
 - #162180 (remove outdated next-solver handling)
 - #162191 (core: mark float `ClampBounds` methods as `#[inline]`)
 - #162195 (docs(time): clarify exact seconds for week and day)
 - #162199 (docs(time): clarify exact seconds for hour and minute)
 - #162222 (coverage: Small cleanups in `extract_hir_info`)
 - #162230 (Pass -Z merge-functions=disabled in tests/codegen-llvm/intrinsics/unchecked_math.rs)
@rust-bors
rust-bors Bot merged commit 56b18c1 into rust-lang:main Sep 4, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 4, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 4, 2026
Rollup merge of #162154 - joseph-isaacs:ji/issue-154166-mir-closure-debug, r=spastorino

fix[154166]: closure debug capture print

Found and remove the `// FIXME(project-rfc-2229#48)` [see](rust-lang/rfcs#2229) in `mir/pretty.rs` used to Debug print mir.

Fix was to replace the old `tcx.upvars_mentioned` with `tcx.closure_captures`.
Added a test to check for printing of both in 2018 and 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants