delegation: remove method call generation#156541
Conversation
Is there specific motivation for this? I wouldn't expect this to work. I actually think we need to change the design to ignore the target expression entirely if there's no reuse Trait::{method, static_fn} { self.field }=> fn method(&self, a: A, b: B) {
self.field.method(a, b) // behavior, not exact desugaring
}
fn static_fn(a: A, b: B) {
Trait::static_fn(a, b) // no self, so the target expr is ignored
} |
Or rather generate something like fn static_fn(a: A, b: B) {
target_expr; // usually dead code and noop
Trait::static_fn(a, b) // no self, so the target expr is ignored
}to avoid issues like #154363 (comment). |
| hir::InferDelegationSig::Output(self.arena.alloc(hir::DelegationGenerics { | ||
| hir::InferDelegationSig::Output(self.arena.alloc(hir::DelegationInfo { | ||
| call_expr_id, | ||
| call_path_res: self.get_resolution_id(call_path_node_id), |
There was a problem hiding this comment.
Isn't this the same thing as sig_id already evaluated above?
There was a problem hiding this comment.
We need path resolution (delegation.id) as we checking call.
| let formal_input_ty: Ty<'tcx> = formal_input_tys[idx]; | ||
| let expected_input_ty: Ty<'tcx> = expected_input_tys[idx]; | ||
| let provided_arg = &provided_args[idx]; | ||
| let provided_arg: &hir::Expr<'tcx> = &provided_args[idx]; |
There was a problem hiding this comment.
It's strange that this type annotation is required.
There was a problem hiding this comment.
Seems like because it is first used in unwrap_or_else(|| self.check_expr_with_expectation(provided_arg, expectation));, if you insert a normal statement before (let _ = self.check_expr(provided_arg);) or remove unwrap_or_else then it infers type correctly.
| fn_sig.output() | ||
| } | ||
|
|
||
| fn execute_delegation_aware_arguments_check( |
There was a problem hiding this comment.
Can check_expr_method_call be reused here in some form?
I'd expect the logic here to contain two steps
-
- determine that this
ExprKind::Callneeds to be treated asExprKind::MethodCall
- from HIR, if we merge these two
ExprKindvariants into one later, or fromget_delegation_infonow
- determine that this
-
- reuse
check_expr_method_callas closely as possible if it needs, or usecheck_argument_typesotherwise
- reuse
The second step shouldn't need to know anything about delegation.
This PR removes method call generation from delegations, now we always generate default call. Part of #118212.
We reuse methods probing engine for finding needed adjustments, thus extending number of supported cases. In this PR adjustments are applied to trait methods (was supported before) and static functions (new feature). Free functions can be supported later.
Example of static trait functions reuses that are now working:
Finally this PR solves issues from parent generics propagation from #155906.
r? @petrochenkov