Skip to content

Commit

Permalink
Rollup merge of rust-lang#69903 - estebank:icemation, r=oli-obk
Browse files Browse the repository at this point in the history
Do not ICE in the face of invalid enum discriminant

Fix rust-lang#67377.

r? @pnkfelix
  • Loading branch information
Centril committed Apr 15, 2020
2 parents 76cbf00 + 187f270 commit 02e1a74
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/librustc_middle/ty/mod.rs
Expand Up @@ -2399,7 +2399,11 @@ impl<'tcx> AdtDef {
None
}
Err(ErrorHandled::TooGeneric) => {
span_bug!(tcx.def_span(expr_did), "enum discriminant depends on generic arguments",)
tcx.sess.delay_span_bug(
tcx.def_span(expr_did),
"enum discriminant depends on generic arguments",
);
None
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/librustc_mir_build/hair/cx/expr.rs
Expand Up @@ -12,7 +12,7 @@ use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, PointerCast,
};
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::{self, AdtKind, Ty};
use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable};
use rustc_span::Span;

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

Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
let user_provided_types = cx.tables.user_provided_types();
let user_provided_type = user_provided_types.get(expr.hir_id).copied();
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
let user_ty = user_provided_types.get(expr.hir_id).copied();
let ty = cx.tables().node_type(expr.hir_id);
match ty.kind {
// A unit struct/variant which is used as a value.
Expand All @@ -728,10 +727,17 @@ fn convert_path_expr<'a, 'tcx>(
adt_def,
variant_index: adt_def.variant_index_with_ctor_id(def_id),
substs,
user_ty: user_provided_type,
user_ty,
fields: vec![],
base: None,
},
_ if ty.references_error() => {
// Handle degenerate input without ICE (#67377).
ExprKind::Literal {
literal: ty::Const::zero_sized(cx.tcx, cx.tcx.types.err),
user_ty: None,
}
}
_ => bug!("unexpected ty: {:?}", ty),
}
}
Expand Down
@@ -0,0 +1,36 @@
mod a {
use std::marker::PhantomData;

enum Bug {
V = [PhantomData; { [ () ].len() ].len() as isize,
//~^ ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR destructors cannot be evaluated at compile-time
}
}

mod b {
enum Bug {
V = [Vec::new; { [].len() ].len() as isize,
//~^ ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR type annotations needed
}
}

mod c {
enum Bug {
V = [Vec::new; { [0].len() ].len() as isize,
//~^ ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR mismatched closing delimiter: `]`
//~| ERROR type annotations needed
}
}

fn main() {}
@@ -0,0 +1,130 @@
error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:16:36
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:27:36
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:16:36
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:27:36
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:16:36
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:27:36
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:42
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:16:36
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error: mismatched closing delimiter: `]`
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:27:36
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| - - ^ mismatched closing delimiter
| | |
| | unclosed delimiter
| closing delimiter possibly meant for this

error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:5:13
|
LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constants cannot evaluate destructors

error[E0282]: type annotations needed
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:16:29
|
LL | V = [Vec::new; { [].len() ].len() as isize,
| ^^^ cannot infer type for type parameter `T`

error[E0282]: type annotations needed
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:27:14
|
LL | V = [Vec::new; { [0].len() ].len() as isize,
| ^^^^^^^^ cannot infer type for type parameter `T`

error: aborting due to 15 previous errors

Some errors have detailed explanations: E0282, E0493.
For more information about an error, try `rustc --explain E0282`.

0 comments on commit 02e1a74

Please sign in to comment.