Skip to content

Commit 03ba8ab

Browse files
authored
Rollup merge of #83535 - MidasLamb:mir-type-count-mismatch, r=nikomatsakis
Break when there is a mismatch in the type count 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. Fixes #83499
2 parents 5662d93 + 2d813b2 commit 03ba8ab

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
7070

7171
// Equate expected input tys with those in the MIR.
7272
for (argument_index, &normalized_input_ty) in normalized_input_tys.iter().enumerate() {
73+
if argument_index + 1 >= body.local_decls.len() {
74+
self.tcx()
75+
.sess
76+
.delay_span_bug(body.span, "found more normalized_input_ty than local_decls");
77+
break;
78+
}
7379
// In MIR, argument N is stored in local N+1.
7480
let local = Local::new(argument_index + 1);
7581

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Test that when in MIR the amount of local_decls and amount of normalized_input_tys don't match
2+
// that an out-of-bounds access does not occur.
3+
#![feature(c_variadic)]
4+
5+
fn main() {}
6+
7+
fn foo(_: Bar, ...) -> impl {}
8+
//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic
9+
//~| ERROR cannot find type `Bar` in this scope
10+
//~| ERROR at least one trait must be specified
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: only foreign or `unsafe extern "C" functions may be C-variadic
2+
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:16
3+
|
4+
LL | fn foo(_: Bar, ...) -> impl {}
5+
| ^^^
6+
7+
error: at least one trait must be specified
8+
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:24
9+
|
10+
LL | fn foo(_: Bar, ...) -> impl {}
11+
| ^^^^
12+
13+
error[E0412]: cannot find type `Bar` in this scope
14+
--> $DIR/issue-83499-input-output-iteration-ice.rs:7:11
15+
|
16+
LL | fn foo(_: Bar, ...) -> impl {}
17+
| ^^^ not found in this scope
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)