forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#126699 - Bryanskiy:delegation-coercion, r=c…
…ompiler-errors Delegation: support coercion for target expression (solves rust-lang#118212 (comment)) The implementation consist of 2 parts. Firstly, method call is generated instead of fully qualified call in AST->HIR lowering if there were no generic arguments or `Qpath` were provided. These restrictions are imposed due to the loss of information after desugaring. For example in ```rust trait Trait { fn foo(&self) {} } reuse <u8 as Trait>::foo; ``` We would like to generate such a code: ```rust fn foo<u8: Trait>(x: &u8) { x.foo(x) } ``` however, the signature is inherited during HIR analysis where `u8` was discarded. Then, we probe the single pre-resolved method. P.S In the future, we would like to avoid restrictions on the callee path by `Self` autoref/autoderef in fully qualified calls, but at the moment it didn't work out. r? `@petrochenkov`
- Loading branch information
Showing
13 changed files
with
264 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![feature(fn_delegation)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Trait { | ||
fn foo(&self) {} | ||
} | ||
|
||
struct F; | ||
impl Trait for F {} | ||
struct S(F); | ||
|
||
pub mod to_reuse { | ||
use crate::F; | ||
|
||
pub fn foo(_: &F) {} | ||
} | ||
|
||
impl Trait for S { | ||
// Make sure that the method call is not generated if the path resolution | ||
// does not have a `self` parameter. | ||
reuse to_reuse::foo { self.0 } | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn main() {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/method-call-choice.rs:21:27 | ||
| | ||
LL | reuse to_reuse::foo { self.0 } | ||
| --- ^^^^^^ expected `&F`, found `F` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
note: function defined here | ||
--> $DIR/method-call-choice.rs:15:12 | ||
| | ||
LL | pub fn foo(_: &F) {} | ||
| ^^^ ----- | ||
help: consider borrowing here | ||
| | ||
LL | reuse to_reuse::foo { &self.0 } | ||
| + | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Oops, something went wrong.