-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not ICE in the face of invalid enum discriminant #69903
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> { | ||
|
@@ -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. | ||
|
@@ -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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait how are we even getting here?! MIR isn't built if |
||
user_ty: None, | ||
} | ||
} | ||
_ => bug!("unexpected ty: {:?}", ty), | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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: `]` | ||
} | ||
} | ||
|
||
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() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
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:15: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:26: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:15: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:26: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:15: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:26: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:15: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:26:36 | ||
| | ||
LL | V = [Vec::new; { [0].len() ].len() as isize, | ||
| - - ^ mismatched closing delimiter | ||
| | | | ||
| | unclosed delimiter | ||
| closing delimiter possibly meant for this | ||
|
||
error[E0282]: type annotations needed | ||
--> $DIR/issue-67377-invalid-syntax-in-enum-discriminant.rs:15: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:26:14 | ||
| | ||
LL | V = [Vec::new; { [0].len() ].len() as isize, | ||
| ^^^^^^^^ cannot infer type for type parameter `T` | ||
|
||
error: aborting due to 14 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be the actual change here, and it looks a lot like the "ty: use
delay_span_bug
inty::AdtDef::eval_explicit_discr
." commit from #70825.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is.