1
Fork 0

Rollup merge of #134745 - compiler-errors:better-arg-span-in-typeck, r=BoxyUwU

Normalize each signature input/output in `typeck_with_fallback` with its own span

Applies the same hack as #106582 but to the args in typeck. Greatly improves normalization error spans from a signature.
This commit is contained in:
Matthias Krüger 2025-01-07 21:39:39 +01:00 committed by GitHub
commit c371a94e78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 69 additions and 77 deletions

View file

@ -147,8 +147,23 @@ fn typeck_with_fallback<'tcx>(
check_abi(tcx, span, fn_sig.abi());
// Compute the function signature from point of view of inside the fn.
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
let fn_sig = fcx.normalize(body.value.span, fn_sig);
let mut fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
// Normalize the input and output types one at a time, using a different
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
// on the entire `FnSig`, since this would use the same `WellFormedLoc`
// for each type, preventing the HIR wf check from generating
// a nice error message.
let arg_span =
|idx| decl.inputs.get(idx).map_or(decl.output.span(), |arg: &hir::Ty<'_>| arg.span);
fn_sig.inputs_and_output = tcx.mk_type_list_from_iter(
fn_sig
.inputs_and_output
.iter()
.enumerate()
.map(|(idx, ty)| fcx.normalize(arg_span(idx), ty)),
);
check_fn(&mut fcx, fn_sig, None, decl, def_id, body, tcx.features().unsized_fn_params());
} else {