Skip to content
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

Delegation: support coercion for target expression #126699

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

Bryanskiy
Copy link
Contributor

@Bryanskiy Bryanskiy commented Jun 19, 2024

(solves #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

trait Trait {
  fn foo(&self) {}
}

reuse <u8 as Trait>::foo;

We would like to generate such a code:

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 19, 2024
@Bryanskiy
Copy link
Contributor Author

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2024
@petrochenkov petrochenkov added the F-fn_delegation `#![feature(fn_delegation)]` label Jun 24, 2024
@Bryanskiy Bryanskiy force-pushed the delegation-coercion branch from de488f2 to 1e5a473 Compare June 24, 2024 15:53
@Bryanskiy
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2024
tests/ui/delegation/glob-glob.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/late.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/method/probe.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/method/probe.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/delegation.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/delegation.rs Show resolved Hide resolved
compiler/rustc_ast_lowering/src/delegation.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/delegation.rs Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

The PR needs a high level description - how exactly does it solve #118212 (comment) (in a few sentences).
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2024
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 25, 2024
…ctoring, r=petrochenkov

Delegation: ast lowering refactor

refactoring changes for rust-lang#126699

r? `@petrochenkov`
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 25, 2024
…ctoring, r=petrochenkov

Delegation: ast lowering refactor

refactoring changes for rust-lang#126699

r? ``@petrochenkov``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 25, 2024
…ctoring, r=petrochenkov

Delegation: ast lowering refactor

refactoring changes for rust-lang#126699

r? ```@petrochenkov```
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 25, 2024
Rollup merge of rust-lang#126947 - Bryanskiy:delegation-lowering-refactoring, r=petrochenkov

Delegation: ast lowering refactor

refactoring changes for rust-lang#126699

r? ```@petrochenkov```
@bors

This comment was marked as resolved.

@Bryanskiy Bryanskiy force-pushed the delegation-coercion branch from 1e5a473 to 64d78b4 Compare June 27, 2024 14:22
@Bryanskiy
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2024
tests/ui/delegation/method-call-priority.rs Show resolved Hide resolved
tests/ui/delegation/target-expr.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/late.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/late.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/late.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/method/probe.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/method/probe.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/delegation.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/delegation.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/delegation.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 28, 2024
@Bryanskiy Bryanskiy force-pushed the delegation-coercion branch from 64d78b4 to 02a1f30 Compare June 28, 2024 14:31
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

@Bryanskiy Bryanskiy force-pushed the delegation-coercion branch from 9568e12 to 784f358 Compare July 16, 2024 13:38
@petrochenkov
Copy link
Contributor

r? @compiler-errors

@Bryanskiy
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 16, 2024
@compiler-errors
Copy link
Member

r=me after the nit

@Bryanskiy Bryanskiy force-pushed the delegation-coercion branch from 784f358 to 7ee97f9 Compare July 16, 2024 15:03
@Bryanskiy
Copy link
Contributor Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jul 16, 2024

@Bryanskiy: 🔑 Insufficient privileges: Not in reviewers

@compiler-errors
Copy link
Member

@bors r=compiler-errors,petrochenkov

@petrochenkov
Copy link
Contributor

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jul 16, 2024

📌 Commit 7ee97f9 has been approved by compiler-errors,petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2024
@bors
Copy link
Contributor

bors commented Jul 16, 2024

📌 Commit 7ee97f9 has been approved by compiler-errors

It is now in the queue for this repository.

@compiler-errors
Copy link
Member

lol race condition

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 16, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#124033 (Sync ar_archive_writer to LLVM 18.1.3)
 - rust-lang#126699 (Delegation: support coercion for target expression)
 - rust-lang#126762 (Deny keyword lifetimes pre-expansion)
 - rust-lang#126967 (Promote the `wasm32-wasip2` target to Tier 2)
 - rust-lang#127390 (Migrate `raw-dylib-inline-cross-dylib` and `raw-dylib-custom-dlltool` `run-make` tests to rmake)
 - rust-lang#127501 (Invert infer `error_reporting` mod struture)
 - rust-lang#127816 (Update method name to reflect changes to its internals)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 36ea068 into rust-lang:master Jul 17, 2024
6 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 17, 2024
Rollup merge of rust-lang#126699 - Bryanskiy:delegation-coercion, r=compiler-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`
@spastorino
Copy link
Member

Thanks for taking over this and sorry for not being able to look at this on time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-fn_delegation `#![feature(fn_delegation)]` 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. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants