delegation: support proper interaction of user-specified args and impl Traits#155096
Conversation
|
HIR ty lowering was modified cc @fmease |
|
r=me after squashing commits. |
|
Reminder, once the PR becomes ready for a review, use |
|
@bors delegate+ |
|
✌️ @aerooneqq, you can now approve this pull request! If @petrochenkov told you to " |
21818db to
51888a1
Compare
|
@bors r=petrochenkov |
…d-args-impl-traits, r=petrochenkov
delegation: support proper interaction of user-specified args and impl Traits
This PR supports usages of user-specified args with impl Traits. When there are user-specified args in child we still need to generate synthetic generic params and use them during signature inheritance:
```rust
fn foo<T, const N: usize>(f: impl FnOnce()) {}
reuse foo::<String, 123> as bar;
//desugaring
fn bar<TSynth: impl FnOnce()>(f: _) {
foo::<String, 123>(f)
}
```
When inheriting predicates we process impl Trait ones, so we need generic params to instantiate them. Other approach may involve not generating synthetic generic params and try to filter out those predicates, but fairly generating synthetic params seems more consistent?.
Fixes rust-lang#154780, part of rust-lang#118212.
r? @petrochenkov
…uwer Rollup of 10 pull requests Successful merges: - #155227 (`rust-analyzer` subtree update) - #153335 (Add #![unstable_removed(..)] attribute to track removed features) - #154932 (Handle RTN projections in assoc type restriction diagnostics) - #155096 (delegation: support proper interaction of user-specified args and impl Traits) - #155106 (cg_llvm: scalable vectors with `simd_cast` and `simd_select`) - #155140 (add regression test for OpenOptionsExt downstream compat) - #155182 (Make the expansion of guard metavars begin guard non-terminals) - #155226 (delegation: revert execution of hir_crate_items before delayed lowering) - #153997 (Use closures more consistently in `dep_graph.rs`.) - #155003 (update thin-vec)
Rollup merge of #155096 - aerooneqq:delegation-user-specified-args-impl-traits, r=petrochenkov delegation: support proper interaction of user-specified args and impl Traits This PR supports usages of user-specified args with impl Traits. When there are user-specified args in child we still need to generate synthetic generic params and use them during signature inheritance: ```rust fn foo<T, const N: usize>(f: impl FnOnce()) {} reuse foo::<String, 123> as bar; //desugaring fn bar<TSynth: impl FnOnce()>(f: _) { foo::<String, 123>(f) } ``` When inheriting predicates we process impl Trait ones, so we need generic params to instantiate them. Other approach may involve not generating synthetic generic params and try to filter out those predicates, but fairly generating synthetic params seems more consistent?. Fixes #154780, part of #118212. r? @petrochenkov
…uwer Rollup of 10 pull requests Successful merges: - rust-lang/rust#155227 (`rust-analyzer` subtree update) - rust-lang/rust#153335 (Add #![unstable_removed(..)] attribute to track removed features) - rust-lang/rust#154932 (Handle RTN projections in assoc type restriction diagnostics) - rust-lang/rust#155096 (delegation: support proper interaction of user-specified args and impl Traits) - rust-lang/rust#155106 (cg_llvm: scalable vectors with `simd_cast` and `simd_select`) - rust-lang/rust#155140 (add regression test for OpenOptionsExt downstream compat) - rust-lang/rust#155182 (Make the expansion of guard metavars begin guard non-terminals) - rust-lang/rust#155226 (delegation: revert execution of hir_crate_items before delayed lowering) - rust-lang/rust#153997 (Use closures more consistently in `dep_graph.rs`.) - rust-lang/rust#155003 (update thin-vec)
…uwer Rollup of 10 pull requests Successful merges: - rust-lang/rust#155227 (`rust-analyzer` subtree update) - rust-lang/rust#153335 (Add #![unstable_removed(..)] attribute to track removed features) - rust-lang/rust#154932 (Handle RTN projections in assoc type restriction diagnostics) - rust-lang/rust#155096 (delegation: support proper interaction of user-specified args and impl Traits) - rust-lang/rust#155106 (cg_llvm: scalable vectors with `simd_cast` and `simd_select`) - rust-lang/rust#155140 (add regression test for OpenOptionsExt downstream compat) - rust-lang/rust#155182 (Make the expansion of guard metavars begin guard non-terminals) - rust-lang/rust#155226 (delegation: revert execution of hir_crate_items before delayed lowering) - rust-lang/rust#153997 (Use closures more consistently in `dep_graph.rs`.) - rust-lang/rust#155003 (update thin-vec)
| } else if synthetic { | ||
| Ty::new_param(tcx, param.index, param.name).into() |
There was a problem hiding this comment.
This is not correct. It's injecting type parameters into a whole different context, it's uprooting a parameter from the def site and planting it at the use site (semi related: things like EarlyBinder solely exist to force people to think about this context change..).
I guess it only happens to work for delegation specifically because the generated delegate either reuses or has a copy of the generic parameters of the delegated function.
It's basically doing this:
fn f() {
g();
// ==>
g::<T>(); // but `T` is not in scope!
}
fn g<T>() {}Example fallout: #158152.
This PR supports usages of user-specified args with impl Traits. When there are user-specified args in child we still need to generate synthetic generic params and use them during signature inheritance:
When inheriting predicates we process impl Trait ones, so we need generic params to instantiate them. Other approach may involve not generating synthetic generic params and try to filter out those predicates, but fairly generating synthetic params seems more consistent?.
Fixes #154780, part of #118212.
r? @petrochenkov