You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#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 rust-lang#118212.
r? @petrochenkov
0 commit comments