mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-23 04:57:37 +00:00
Avoid ICE on return outside of fn with literal array
Do not ICE when encountering `enum E { A = return [0][0] }`.
This commit is contained in:
parent
22bc9e1d9c
commit
2ae87ff59d
@ -189,9 +189,23 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||
if let hir::ExprKind::Index(ref base, ref index) = e.kind {
|
||||
let mut tables = self.fcx.tables.borrow_mut();
|
||||
|
||||
// All valid indexing looks like this; might encounter non-valid indexes at this point
|
||||
if let ty::Ref(_, base_ty, _) = tables.expr_ty_adjusted(&base).kind {
|
||||
let index_ty = tables.expr_ty_adjusted(&index);
|
||||
// All valid indexing looks like this; might encounter non-valid indexes at this point.
|
||||
let base_ty = tables.expr_ty_adjusted_opt(&base).map(|t| &t.kind);
|
||||
if base_ty.is_none() {
|
||||
self.tcx().sess.delay_span_bug(e.span, &format!("bad base: `{:?}`", base));
|
||||
return;
|
||||
}
|
||||
if let Some(ty::Ref(_, base_ty, _)) = base_ty {
|
||||
let index_ty = match tables.expr_ty_adjusted_opt(&index) {
|
||||
Some(t) => t,
|
||||
None => {
|
||||
self.tcx().sess.delay_span_bug(
|
||||
e.span,
|
||||
&format!("bad index {:?} for base: `{:?}`", index, base),
|
||||
);
|
||||
self.fcx.tcx.types.err
|
||||
}
|
||||
};
|
||||
let index_ty = self.fcx.resolve_vars_if_possible(&index_ty);
|
||||
|
||||
if base_ty.builtin_index().is_some() && index_ty == self.fcx.tcx.types.usize {
|
||||
|
5
src/test/ui/issues/issue-64620.rs
Normal file
5
src/test/ui/issues/issue-64620.rs
Normal file
@ -0,0 +1,5 @@
|
||||
enum Bug {
|
||||
V1 = return [0][0] //~ERROR return statement outside of function body
|
||||
}
|
||||
|
||||
fn main() {}
|
9
src/test/ui/issues/issue-64620.stderr
Normal file
9
src/test/ui/issues/issue-64620.stderr
Normal file
@ -0,0 +1,9 @@
|
||||
error[E0572]: return statement outside of function body
|
||||
--> $DIR/issue-64620.rs:2:10
|
||||
|
|
||||
LL | V1 = return [0][0]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0572`.
|
Loading…
Reference in New Issue
Block a user