Skip to content

Commit a8daff2

Browse files
committed
Fix ICE in check_must_not_suspend_ty()
1 parent 772d51f commit a8daff2

File tree

3 files changed

+75
-9
lines changed

3 files changed

+75
-9
lines changed

compiler/rustc_typeck/src/check/generator_interior.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -536,22 +536,28 @@ pub fn check_must_not_suspend_ty<'tcx>(
536536
}
537537
has_emitted
538538
}
539-
ty::Tuple(ref tys) => {
539+
ty::Tuple(_) => {
540540
let mut has_emitted = false;
541-
let spans = if let Some(hir::ExprKind::Tup(comps)) = data.expr.map(|e| &e.kind) {
542-
debug_assert_eq!(comps.len(), tys.len());
543-
comps.iter().map(|e| e.span).collect()
544-
} else {
545-
vec![]
541+
let comps = match data.expr.map(|e| &e.kind) {
542+
Some(hir::ExprKind::Tup(comps)) => {
543+
debug_assert_eq!(comps.len(), ty.tuple_fields().count());
544+
Some(comps)
545+
}
546+
_ => None,
546547
};
547-
for (i, ty) in tys.iter().map(|k| k.expect_ty()).enumerate() {
548+
for (i, ty) in ty.tuple_fields().enumerate() {
548549
let descr_post = &format!(" in tuple element {}", i);
549-
let span = *spans.get(i).unwrap_or(&data.source_span);
550+
let span = comps.and_then(|c| c.get(i)).map(|e| e.span).unwrap_or(data.source_span);
550551
if check_must_not_suspend_ty(
551552
fcx,
552553
ty,
553554
hir_id,
554-
SuspendCheckData { descr_post, source_span: span, ..data },
555+
SuspendCheckData {
556+
descr_post,
557+
expr: comps.and_then(|comps| comps.get(i)),
558+
source_span: span,
559+
..data
560+
},
555561
) {
556562
has_emitted = true;
557563
}

src/test/ui/typeck/issue-91334.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for the ICE described in issue #91334.
2+
3+
// error-pattern: this file contains an unclosed delimiter
4+
// error-pattern: expected one of
5+
// error-pattern: mismatched closing delimiter
6+
// error-pattern: mismatched types
7+
8+
#![feature(generators)]
9+
10+
fn f(){||yield(((){),

src/test/ui/typeck/issue-91334.stderr

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/issue-91334.rs:10:23
3+
|
4+
LL | fn f(){||yield(((){),
5+
| - - ^
6+
| | |
7+
| | unclosed delimiter
8+
| unclosed delimiter
9+
10+
error: this file contains an unclosed delimiter
11+
--> $DIR/issue-91334.rs:10:23
12+
|
13+
LL | fn f(){||yield(((){),
14+
| - - ^
15+
| | |
16+
| | unclosed delimiter
17+
| unclosed delimiter
18+
19+
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `{`
20+
--> $DIR/issue-91334.rs:10:19
21+
|
22+
LL | fn f(){||yield(((){),
23+
| ^
24+
| |
25+
| expected one of `)`, `,`, `.`, `?`, or an operator
26+
| help: missing `,`
27+
28+
error: mismatched closing delimiter: `)`
29+
--> $DIR/issue-91334.rs:10:19
30+
|
31+
LL | fn f(){||yield(((){),
32+
| - ^^ mismatched closing delimiter
33+
| | |
34+
| | unclosed delimiter
35+
| closing delimiter possibly meant for this
36+
37+
error[E0308]: mismatched types
38+
--> $DIR/issue-91334.rs:10:8
39+
|
40+
LL | fn f(){||yield(((){),
41+
| -^^^^^^^^^^^^^^^ expected `()`, found generator
42+
| |
43+
| help: try adding a return type: `-> [generator@$DIR/issue-91334.rs:10:8: 10:23]`
44+
|
45+
= note: expected unit type `()`
46+
found generator `[generator@$DIR/issue-91334.rs:10:8: 10:23]`
47+
48+
error: aborting due to 5 previous errors
49+
50+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)