Skip to content

Commit 03707b5

Browse files
authored
Rollup merge of #69903 - estebank:icemation, r=oli-obk
Do not ICE in the face of invalid enum discriminant Fix #67377. r? @pnkfelix
2 parents 835428c + f47c4ff commit 03707b5

File tree

4 files changed

+173
-5
lines changed

4 files changed

+173
-5
lines changed

src/librustc_middle/ty/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,11 @@ impl<'tcx> AdtDef {
23992399
None
24002400
}
24012401
Err(ErrorHandled::TooGeneric) => {
2402-
span_bug!(tcx.def_span(expr_did), "enum discriminant depends on generic arguments",)
2402+
tcx.sess.delay_span_bug(
2403+
tcx.def_span(expr_did),
2404+
"enum discriminant depends on generic arguments",
2405+
);
2406+
None
24032407
}
24042408
}
24052409
}

src/librustc_mir_build/hair/cx/expr.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::adjustment::{
1212
Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, PointerCast,
1313
};
1414
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
15-
use rustc_middle::ty::{self, AdtKind, Ty};
15+
use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable};
1616
use rustc_span::Span;
1717

1818
impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr<'tcx> {
@@ -718,8 +718,7 @@ fn convert_path_expr<'a, 'tcx>(
718718

719719
Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
720720
let user_provided_types = cx.tables.user_provided_types();
721-
let user_provided_type = user_provided_types.get(expr.hir_id).copied();
722-
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
721+
let user_ty = user_provided_types.get(expr.hir_id).copied();
723722
let ty = cx.tables().node_type(expr.hir_id);
724723
match ty.kind {
725724
// A unit struct/variant which is used as a value.
@@ -728,10 +727,17 @@ fn convert_path_expr<'a, 'tcx>(
728727
adt_def,
729728
variant_index: adt_def.variant_index_with_ctor_id(def_id),
730729
substs,
731-
user_ty: user_provided_type,
730+
user_ty,
732731
fields: vec![],
733732
base: None,
734733
},
734+
_ if ty.references_error() => {
735+
// Handle degenerate input without ICE (#67377).
736+
ExprKind::Literal {
737+
literal: ty::Const::zero_sized(cx.tcx, cx.tcx.types.err),
738+
user_ty: None,
739+
}
740+
}
735741
_ => bug!("unexpected ty: {:?}", ty),
736742
}
737743
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
mod a {
2+
use std::marker::PhantomData;
3+
4+
enum Bug {
5+
V = [PhantomData; { [ () ].len() ].len() as isize,
6+
//~^ ERROR mismatched closing delimiter: `]`
7+
//~| ERROR mismatched closing delimiter: `]`
8+
//~| ERROR mismatched closing delimiter: `]`
9+
//~| ERROR mismatched closing delimiter: `]`
10+
}
11+
}
12+
13+
mod b {
14+
enum Bug {
15+
V = [Vec::new; { [].len() ].len() as isize,
16+
//~^ ERROR mismatched closing delimiter: `]`
17+
//~| ERROR mismatched closing delimiter: `]`
18+
//~| ERROR mismatched closing delimiter: `]`
19+
//~| ERROR mismatched closing delimiter: `]`
20+
//~| ERROR type annotations needed
21+
}
22+
}
23+
24+
mod c {
25+
enum Bug {
26+
V = [Vec::new; { [0].len() ].len() as isize,
27+
//~^ ERROR mismatched closing delimiter: `]`
28+
//~| ERROR mismatched closing delimiter: `]`
29+
//~| ERROR mismatched closing delimiter: `]`
30+
//~| ERROR mismatched closing delimiter: `]`
31+
//~| ERROR type annotations needed
32+
}
33+
}
34+
35+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
error: mismatched closing delimiter: `]`
2+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
3+
|
4+
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
5+
| - - ^ mismatched closing delimiter
6+
| | |
7+
| | unclosed delimiter
8+
| closing delimiter possibly meant for this
9+
10+
error: mismatched closing delimiter: `]`
11+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
12+
|
13+
LL | V = [Vec::new; { [].len() ].len() as isize,
14+
| - - ^ mismatched closing delimiter
15+
| | |
16+
| | unclosed delimiter
17+
| closing delimiter possibly meant for this
18+
19+
error: mismatched closing delimiter: `]`
20+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
21+
|
22+
LL | V = [Vec::new; { [0].len() ].len() as isize,
23+
| - - ^ mismatched closing delimiter
24+
| | |
25+
| | unclosed delimiter
26+
| closing delimiter possibly meant for this
27+
28+
error: mismatched closing delimiter: `]`
29+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
30+
|
31+
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
32+
| - - ^ mismatched closing delimiter
33+
| | |
34+
| | unclosed delimiter
35+
| closing delimiter possibly meant for this
36+
37+
error: mismatched closing delimiter: `]`
38+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
39+
|
40+
LL | V = [Vec::new; { [].len() ].len() as isize,
41+
| - - ^ mismatched closing delimiter
42+
| | |
43+
| | unclosed delimiter
44+
| closing delimiter possibly meant for this
45+
46+
error: mismatched closing delimiter: `]`
47+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
48+
|
49+
LL | V = [Vec::new; { [0].len() ].len() as isize,
50+
| - - ^ mismatched closing delimiter
51+
| | |
52+
| | unclosed delimiter
53+
| closing delimiter possibly meant for this
54+
55+
error: mismatched closing delimiter: `]`
56+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
57+
|
58+
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
59+
| - - ^ mismatched closing delimiter
60+
| | |
61+
| | unclosed delimiter
62+
| closing delimiter possibly meant for this
63+
64+
error: mismatched closing delimiter: `]`
65+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
66+
|
67+
LL | V = [Vec::new; { [].len() ].len() as isize,
68+
| - - ^ mismatched closing delimiter
69+
| | |
70+
| | unclosed delimiter
71+
| closing delimiter possibly meant for this
72+
73+
error: mismatched closing delimiter: `]`
74+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
75+
|
76+
LL | V = [Vec::new; { [0].len() ].len() as isize,
77+
| - - ^ mismatched closing delimiter
78+
| | |
79+
| | unclosed delimiter
80+
| closing delimiter possibly meant for this
81+
82+
error: mismatched closing delimiter: `]`
83+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
84+
|
85+
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
86+
| - - ^ mismatched closing delimiter
87+
| | |
88+
| | unclosed delimiter
89+
| closing delimiter possibly meant for this
90+
91+
error: mismatched closing delimiter: `]`
92+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:36
93+
|
94+
LL | V = [Vec::new; { [].len() ].len() as isize,
95+
| - - ^ mismatched closing delimiter
96+
| | |
97+
| | unclosed delimiter
98+
| closing delimiter possibly meant for this
99+
100+
error: mismatched closing delimiter: `]`
101+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:36
102+
|
103+
LL | V = [Vec::new; { [0].len() ].len() as isize,
104+
| - - ^ mismatched closing delimiter
105+
| | |
106+
| | unclosed delimiter
107+
| closing delimiter possibly meant for this
108+
109+
error[E0282]: type annotations needed
110+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15:29
111+
|
112+
LL | V = [Vec::new; { [].len() ].len() as isize,
113+
| ^^^ cannot infer type for type parameter `T`
114+
115+
error[E0282]: type annotations needed
116+
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:26:14
117+
|
118+
LL | V = [Vec::new; { [0].len() ].len() as isize,
119+
| ^^^^^^^^ cannot infer type for type parameter `T`
120+
121+
error: aborting due to 14 previous errors
122+
123+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)