Skip to content

Conversation

@Zalathar
Copy link
Member

In rustc_mir_build there are a few Builder methods that start with let this = self;, so that subsequent code can uniformly refer to the builder as this, instead of having to choose between self at the top level or this when nested in closures that need to borrow the builder.

There is some existing documentation of the idiom in expr_into_dest:

// since we frequently have to reference `self` from within a
// closure, where `self` would be shadowed, it's easier to
// just use the name `this` uniformly
let this = self;

But that documentation is brief and hard to find, especially if one is unaware that such documentation even exists.


This PR therefore adds a longer explanation of the let this = self; idiom in the module documentation for rustc_mir_build::builder, and makes that documentation easier to find by adding a searchable tag (“LET_THIS_SELF”) to the documentation and to each occurrence of the idiom.

@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

Some changes occurred in match lowering

cc @Nadrieril

@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 Nov 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Zalathar
Copy link
Member Author

The lack of documentation has caused confusion in #148955, for example.

@Kivooeo
Copy link
Member

Kivooeo commented Nov 17, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 17, 2025

📌 Commit 34cccb2 has been approved by Kivooeo

It is now in the queue for this repository.

@bors bors 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 Nov 17, 2025
bors added a commit that referenced this pull request Nov 17, 2025
Rollup of 5 pull requests

Successful merges:

 - #145610 (Stabilize `char_max_len`)
 - #148504 (Fix link in c_longlong documentation)
 - #148698 (Fix query cycle when encounter unevaluated const)
 - #148865 (move GAT inference prevention hack)
 - #149016 (Document the `let this = self;` idiom used in MIR building)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6b8f2c7 into rust-lang:main Nov 17, 2025
11 checks passed
rust-timer added a commit that referenced this pull request Nov 17, 2025
Rollup merge of #149016 - Zalathar:let-this-self, r=Kivooeo

Document the `let this = self;` idiom used in MIR building

In `rustc_mir_build` there are a few `Builder` methods that start with `let this = self;`, so that subsequent code can uniformly refer to the builder as `this`, instead of having to choose between `self` at the top level or `this` when nested in closures that need to borrow the builder.

There is some existing documentation of the idiom in `expr_into_dest`:

https://github.com/rust-lang/rust/blob/69d4d5fc0e4db60272aac85ef27ecccef5764f3a/compiler/rustc_mir_build/src/builder/expr/into.rs#L32-L35

But that documentation is brief and hard to find, especially if one is unaware that such documentation even exists.

---

This PR therefore adds a longer explanation of the `let this = self;` idiom in the module documentation for `rustc_mir_build::builder`, and makes that documentation easier to find by adding a searchable tag (“LET_THIS_SELF”) to the documentation and to each occurrence of the idiom.
@rustbot rustbot added this to the 1.93.0 milestone Nov 17, 2025
@Zalathar Zalathar deleted the let-this-self branch November 17, 2025 22:52
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Nov 20, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#145610 (Stabilize `char_max_len`)
 - rust-lang/rust#148504 (Fix link in c_longlong documentation)
 - rust-lang/rust#148698 (Fix query cycle when encounter unevaluated const)
 - rust-lang/rust#148865 (move GAT inference prevention hack)
 - rust-lang/rust#149016 (Document the `let this = self;` idiom used in MIR building)

r? `@ghost`
`@rustbot` modify labels: rollup
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants