-
Notifications
You must be signed in to change notification settings - Fork 14k
Document the let this = self; idiom used in MIR building
#149016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
|
Some changes occurred in match lowering cc @Nadrieril |
Collaborator
|
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
Member
Author
|
The lack of documentation has caused confusion in #148955, for example. |
Member
|
@bors r+ rollup |
Collaborator
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
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.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
rustc_mir_buildthere are a fewBuildermethods that start withlet this = self;, so that subsequent code can uniformly refer to the builder asthis, instead of having to choose betweenselfat the top level orthiswhen nested in closures that need to borrow the builder.There is some existing documentation of the idiom in
expr_into_dest:rust/compiler/rustc_mir_build/src/builder/expr/into.rs
Lines 32 to 35 in 69d4d5f
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 forrustc_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.