delegation: move statements out of the first arg#157248
Open
aerooneqq wants to merge 2 commits into
Open
Conversation
aff0ceb to
ba754c4
Compare
petrochenkov
reviewed
Jun 2, 2026
| this.ident_and_label_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id); | ||
| this.lower_target_expr(&block) | ||
|
|
||
| // Lower with `HirId::INVALID` as we will use only expr. and stmts. |
Contributor
There was a problem hiding this comment.
Suggested change
| // Lower with `HirId::INVALID` as we will use only expr. and stmts. | |
| // Lower with `HirId::INVALID` as we will use only expr and stmts. |
|
|
||
| statements = Some(block.stmts); | ||
|
|
||
| arg |
Contributor
There was a problem hiding this comment.
Suggested change
| arg | |
| if let Some(&expr) = block.expr { expr } else { generate_arg(this) } |
| // https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2197170600. | ||
| let block = this.lower_block_noalloc(HirId::INVALID, block, false); | ||
|
|
||
| let arg = if let Some(&expr) = block.expr { expr } else { generate_arg(this) }; |
Contributor
There was a problem hiding this comment.
The new semantics "no trailing statement means the first argument is passed through" needs to be written out in a comment.
It differs from the usual behavior, which is "no trailing statement means an empty tuple is passed".
| let block_id = self.lower_body(|this| { | ||
| let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count); | ||
| let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count); | ||
| let mut statements = None; |
Contributor
There was a problem hiding this comment.
Suggested change
| let mut statements = None; | |
| let mut statements = &[]; |
No need for an option.
| let callee_path = this.arena.alloc(this.mk_expr(hir::ExprKind::Path(path), span)); | ||
| let args = if let Some(block) = delegation.body.as_ref() { | ||
| this.arena.alloc_slice(&[this.lower_target_expr(block)]) | ||
| this.arena.alloc_slice(&[this.lower_block_expr(block)]) |
Contributor
There was a problem hiding this comment.
It's a bit unfortunate that the behavior in the erroneous cases (here and in "If we have no params in signature...") differs from the good case, but not a big deal.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR moves statements that precede final block expression out of the first argument, so we can apply adjustments to final block expression in more cases.
This changes behavior a bit, for example if we specify an empty block:
So we generated the first arg and block is no-op.
In general scenario:
If we change target expression to
Once again we generated default arguments for function and block is no-op now (meaning it does not affect callee arguments).
Part of #118212.
r? @petrochenkov