Uh oh!
There was an error while loading. Please reload this page.
delegation: move statements out of the first arg - #157248
Merged
rust-bors[bot] merged 1 commit intoJun 3, 2026
Merged
Conversation
aerooneqqforce-pushed
the
delegation-statements-out-of-first-arg
branch
from
June 2, 2026 05:57
aff0ceb to
ba754c4Compareaerooneqq
marked this pull request as ready for review
June 2, 2026 05:59
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
aerooneqq
commented
Jun 3, 2026
ContributorAuthor
@rustbot ready |
petrochenkov
commented
Jun 3, 2026
Contributor
Contributor
✌️ @aerooneqq, you can now approve this pull request! If @petrochenkov told you to " |
rustbot
commented
Jun 3, 2026
Collaborator
Reminder, once the PR becomes ready for a review, use |
aerooneqqforce-pushed
the
delegation-statements-out-of-first-arg
branch
from
June 3, 2026 11:09
8f6baf5 to
28cfce7Compareaerooneqq
commented
Jun 3, 2026
ContributorAuthor
@bors r=petrochenkov |
Contributor
JonathanBrouwer added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jun 3, 2026
…t-of-first-arg, r=petrochenkov
delegation: move statements out of the first arg
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:
```rust
fn b<C>(e: C) {}
reuse b {}
// Desugaring:
fn b<C>(arg0: _) -> _ { b::<C>(arg0) }
```
So we generated the first arg and block is no-op.
In general scenario:
```rust
trait Trait: Sized { //~ WARN trait `Trait` is never used
fn by_value(self, x: i32) -> i32 { x }
fn by_ref(&self, x: i32) -> i32 { x }
fn by_mut_ref(&mut self, x: i32) -> i32 { x }
}
struct F; //~ WARN struct `F` is never constructed
impl Trait for F {}
struct S(F); //~ WARN struct `S` is never constructed
impl Trait for S {
reuse <F as Trait>::* {
println!();
// Final expression is adjusted even if it is in a block.
self.0
}
}
// Desugaring:
#[attr = Inline(Hint)]
fn by_value(self: _, arg1: _)
->
_ {
// Final expression is adjusted even if it is in a block.
{ ::std::io::_print(format_arguments::from_str("\n")); };
<F as Trait>::by_value(self.0, arg1)
}
#[attr = Inline(Hint)]
fn by_ref(self: _, arg1: _)
->
_ {
{ ::std::io::_print(format_arguments::from_str("\n")); };
<F as Trait>::by_ref(self.0, arg1)
}
#[attr = Inline(Hint)]
fn by_mut_ref(self: _, arg1: _)
->
_ {
{ ::std::io::_print(format_arguments::from_str("\n")); };
<F as Trait>::by_mut_ref(self.0, arg1)
}
```
If we change target expression to
```rust
reuse <F as Trait>::* {
println!();
let x = 1;
}
// Desugaring:
#[attr = Inline(Hint)]
fn by_value(self: _, arg1: _)
->
_ {
{ ::std::io::_print(format_arguments::from_str("\n")); };
let x = 1;
<F as Trait>::by_value(self, arg1)
}
```
Once again we generated default arguments for function and block is no-op now (meaning it does not affect callee arguments).
Part of rust-lang#118212.
r? @petrochenkovrust-borsBot
pushed a commit
that referenced
this pull request
Jun 3, 2026
…uwer Rollup of 15 pull requests Successful merges: - #155763 (Promotes 5 Thumb-mode bare-metal Arm targets to Tier 2) - #156953 (delegation: emit error when there is an infer lifetime in user-specified args) - #157248 (delegation: move statements out of the first arg) - #157263 (rustc_codegen_ssa: Refactor `ArchiveEntry` to include entry kind) - #157311 (Use weak linkage for EII defaults) - #156089 (Fix unused_parens for pinned reference patterns) - #156928 (Remove -Zemscripten-wasm-eh) - #157236 (Reorganize `tests/ui/issues` [3/N]) - #157287 (Const generics: remove AliasTerm::kind(), and small fixes) - #157294 (Split coroutine layout computation to its own file) - #157328 (windows: Elide division-by-zero checks in Instant::now()) - #157331 (Rewrite target checking for `#[link]`) - #157336 (Enable `clippy::mem_replace_with_default`) - #157362 (Fix trivial wf module argument/doc comment name mismatches) - #157364 (Rewrite target checking of `rustc_dummy`) Failed merges: - #157332 (Rewrite target checking for `#[sanitize]`)
Uh oh!
There was an error while loading. Please reload this page.
rust-timer added a commit
that referenced
this pull request
Jun 3, 2026
Rollup merge of #157248 - aerooneqq:delegation-statements-out-of-first-arg, r=petrochenkov delegation: move statements out of the first arg 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: ```rust fn b<C>(e: C) {} reuse b {} // Desugaring: fn b<C>(arg0: _) -> _ { b::<C>(arg0) } ``` So we generated the first arg and block is no-op. In general scenario: ```rust trait Trait: Sized { //~ WARN trait `Trait` is never used fn by_value(self, x: i32) -> i32 { x } fn by_ref(&self, x: i32) -> i32 { x } fn by_mut_ref(&mut self, x: i32) -> i32 { x } } struct F; //~ WARN struct `F` is never constructed impl Trait for F {} struct S(F); //~ WARN struct `S` is never constructed impl Trait for S { reuse <F as Trait>::* { println!(); // Final expression is adjusted even if it is in a block. self.0 } } // Desugaring: #[attr = Inline(Hint)] fn by_value(self: _, arg1: _) -> _ { // Final expression is adjusted even if it is in a block. { ::std::io::_print(format_arguments::from_str("\n")); }; <F as Trait>::by_value(self.0, arg1) } #[attr = Inline(Hint)] fn by_ref(self: _, arg1: _) -> _ { { ::std::io::_print(format_arguments::from_str("\n")); }; <F as Trait>::by_ref(self.0, arg1) } #[attr = Inline(Hint)] fn by_mut_ref(self: _, arg1: _) -> _ { { ::std::io::_print(format_arguments::from_str("\n")); }; <F as Trait>::by_mut_ref(self.0, arg1) } ``` If we change target expression to ```rust reuse <F as Trait>::* { println!(); let x = 1; } // Desugaring: #[attr = Inline(Hint)] fn by_value(self: _, arg1: _) -> _ { { ::std::io::_print(format_arguments::from_str("\n")); }; let x = 1; <F as Trait>::by_value(self, arg1) } ``` 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
flip1995 pushed a commit
to flip1995/rust-clippy
that referenced
this pull request
Aug 17, 2026
…uwer Rollup of 15 pull requests Successful merges: - rust-lang/rust#155763 (Promotes 5 Thumb-mode bare-metal Arm targets to Tier 2) - rust-lang/rust#156953 (delegation: emit error when there is an infer lifetime in user-specified args) - rust-lang/rust#157248 (delegation: move statements out of the first arg) - rust-lang/rust#157263 (rustc_codegen_ssa: Refactor `ArchiveEntry` to include entry kind) - rust-lang/rust#157311 (Use weak linkage for EII defaults) - rust-lang/rust#156089 (Fix unused_parens for pinned reference patterns) - rust-lang/rust#156928 (Remove -Zemscripten-wasm-eh) - rust-lang/rust#157236 (Reorganize `tests/ui/issues` [3/N]) - rust-lang/rust#157287 (Const generics: remove AliasTerm::kind(), and small fixes) - rust-lang/rust#157294 (Split coroutine layout computation to its own file) - rust-lang/rust#157328 (windows: Elide division-by-zero checks in Instant::now()) - rust-lang/rust#157331 (Rewrite target checking for `#[link]`) - rust-lang/rust#157336 (Enable `clippy::mem_replace_with_default`) - rust-lang/rust#157362 (Fix trivial wf module argument/doc comment name mismatches) - rust-lang/rust#157364 (Rewrite target checking of `rustc_dummy`) Failed merges: - rust-lang/rust#157332 (Rewrite target checking for `#[sanitize]`)
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 freeto 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