Skip the closure signature annotation check for tainted bodies

When a coroutine has too many parameters, `check_match` fails and
`construct_error` builds a MIR body with only the coroutine's computed
args (env + resume type). The user-provided signature, however, still
reflects all the parameters the user wrote. `check_signature_annotation`
then tries to `zip_eq` these two mismatched iterators, causing a panic.
Checking `tainted_by_errors` and bailing early avoids this, since
`construct_error` bodies cannot meaningfully be compared against user
annotations.
This commit is contained in:
Jacob Adam
2026-04-12 23:21:13 +01:00
parent 14196dbfa3
commit 189305eda3
@@ -32,6 +32,15 @@ pub(super) fn check_signature_annotation(&mut self) {
return;
}
// If the MIR body was constructed via `construct_error` (because an
// earlier pass like match checking failed), its args may not match
// the user-provided signature (e.g. a coroutine with too many
// parameters). Bail out as this can cause panic,
// see <https://github.com/rust-lang/rust/issues/139570>.
if self.body.tainted_by_errors.is_some() {
return;
}
let user_provided_poly_sig = self.tcx().closure_user_provided_sig(mir_def_id);
// Instantiate the canonicalized variables from user-provided signature