]> git.lizzy.rs Git - rust.git/commitdiff
Break when there is a mismatch in the type count
authorMidas Lambrichts <midaslamb@gmail.com>
Fri, 26 Mar 2021 22:16:22 +0000 (23:16 +0100)
committerMidas Lambrichts <midaslamb@gmail.com>
Fri, 26 Mar 2021 22:16:22 +0000 (23:16 +0100)
When other errors are generated, there can be a mismatch between the
amount of input types in MIR, and the amount in the function itself.
Break from the comparative loop if this is the case to prevent
out-of-bounds.

compiler/rustc_mir/src/borrow_check/type_check/input_output.rs

index 77d9136622458ca33fc28207ef60d76da4ceeed1..1bb447d1057815e7764d9342d2f56311813e506e 100644 (file)
@@ -70,6 +70,12 @@ pub(super) fn equate_inputs_and_outputs(
 
         // Equate expected input tys with those in the MIR.
         for (argument_index, &normalized_input_ty) in normalized_input_tys.iter().enumerate() {
+            if argument_index + 1 >= body.local_decls.len() {
+                self.tcx()
+                    .sess
+                    .delay_span_bug(body.span, "found more normalized_input_ty than local_decls");
+                break;
+            }
             // In MIR, argument N is stored in local N+1.
             let local = Local::new(argument_index + 1);