Skip to content

Commit 24da940

Browse files
authored
Rollup merge of rust-lang#129320 - jder:issue-128848, r=compiler-errors
Fix crash when labeling arguments for call_once and friends When calling a method on Fn* traits explicitly, argument diagnostics should point at the called method (eg Fn::call_once), not the underlying callee. This PR makes 3 main changes: * It uses TupleArguments to detect if the user called a Fn* method directly (`my_fn.call_once(…)`) or implicitly (`my_fn(…)`). If it was explicit, argument diagnostics should point at the call_once method, not the underlying callable. * The previous state was causing confusion between the two arguments lists (which could be different lengths), causing an out-of-bounds slice indexing in rust-lang#128848. I added a length assert to capture the requirement in case this regresses or happens in another case. * Unfortunately, this assert tripped when the required arguments information was not available (`self.get_hir_params_with_generics` was returning an empty Vec), so I've updated that to return None when that information is not available. (cc `@strottos` if you have any comments, since you added this function in rust-lang#121595) Sorry this causes a bunch of indentation changes, recommend reviewing [ignoring whitespace](https://github.com/rust-lang/rust/pull/129320/files?w=1).) This is my first rustc PR, so please call out if you'd like this split into more commits (or PRs), style nits, etc. I will add a few comments/questions inline. Thank you! Fixes rust-lang#128848
2 parents 473ae00 + 57de750 commit 24da940

File tree

5 files changed

+245
-201
lines changed

5 files changed

+245
-201
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn check_legal_trait_for_method_call(
5858
enum CallStep<'tcx> {
5959
Builtin(Ty<'tcx>),
6060
DeferredClosure(LocalDefId, ty::FnSig<'tcx>),
61-
/// E.g., enum variant constructors.
61+
/// Call overloading when callee implements one of the Fn* traits.
6262
Overloaded(MethodCallee<'tcx>),
6363
}
6464

0 commit comments

Comments
 (0)