Fix ICEs with match/return expressions inside array lengths
This commit is contained in:
parent
30fde04780
commit
0195714836
4 changed files with 58 additions and 9 deletions
|
|
@ -1118,9 +1118,12 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
|||
ty::TyParam(_) => {
|
||||
return Err(LayoutError::Unknown(ty));
|
||||
}
|
||||
ty::TyGeneratorWitness(..) | ty::TyInfer(_) | ty::TyError => {
|
||||
ty::TyGeneratorWitness(..) | ty::TyInfer(_) => {
|
||||
bug!("LayoutDetails::compute: unexpected type `{}`", ty)
|
||||
}
|
||||
ty::TyError => {
|
||||
return Err(LayoutError::Unknown(ty));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -743,8 +743,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
|||
);
|
||||
*self.const_to_pat(instance, val, expr.hir_id, lit.span).kind
|
||||
},
|
||||
Err(()) => {
|
||||
self.errors.push(PatternError::FloatBug);
|
||||
Err(float_bug) => {
|
||||
if float_bug {
|
||||
self.errors.push(PatternError::FloatBug);
|
||||
}
|
||||
PatternKind::Wild
|
||||
},
|
||||
}
|
||||
|
|
@ -764,8 +766,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
|||
);
|
||||
*self.const_to_pat(instance, val, expr.hir_id, lit.span).kind
|
||||
},
|
||||
Err(()) => {
|
||||
self.errors.push(PatternError::FloatBug);
|
||||
Err(float_bug) => {
|
||||
if float_bug {
|
||||
self.errors.push(PatternError::FloatBug);
|
||||
}
|
||||
PatternKind::Wild
|
||||
},
|
||||
}
|
||||
|
|
@ -1123,7 +1127,7 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
|
|||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
neg: bool)
|
||||
-> Result<&'tcx ty::Const<'tcx>, ()> {
|
||||
-> Result<&'tcx ty::Const<'tcx>, bool> {
|
||||
use syntax::ast::*;
|
||||
|
||||
use rustc::mir::interpret::*;
|
||||
|
|
@ -1152,7 +1156,11 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
|
|||
ty::TyInt(other) => Int::Signed(other),
|
||||
ty::TyUint(UintTy::Usize) => Int::Unsigned(tcx.sess.target.usize_ty),
|
||||
ty::TyUint(other) => Int::Unsigned(other),
|
||||
_ => bug!(),
|
||||
ty::TyError => {
|
||||
// Avoid ICE
|
||||
return Err(false);
|
||||
}
|
||||
_ => bug!("{:?}", ty.sty),
|
||||
};
|
||||
// This converts from LitKind::Int (which is sign extended) to
|
||||
// Scalar::Bytes (which is zero extended)
|
||||
|
|
@ -1182,14 +1190,14 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
|
|||
})
|
||||
},
|
||||
LitKind::Float(n, fty) => {
|
||||
parse_float(n, fty, neg)?
|
||||
parse_float(n, fty, neg).map_err(|_| true)?
|
||||
}
|
||||
LitKind::FloatUnsuffixed(n) => {
|
||||
let fty = match ty.sty {
|
||||
ty::TyFloat(fty) => fty,
|
||||
_ => bug!()
|
||||
};
|
||||
parse_float(n, fty, neg)?
|
||||
parse_float(n, fty, neg).map_err(|_| true)?
|
||||
}
|
||||
LitKind::Bool(b) => ConstValue::Scalar(Scalar::Bits {
|
||||
bits: b as u128,
|
||||
|
|
|
|||
17
src/test/ui/return-match-array-const.rs
Normal file
17
src/test/ui/return-match-array-const.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
[(); return match 0 { n => n }]; //~ ERROR: return statement outside of function body
|
||||
|
||||
[(); return match 0 { 0 => 0 }]; //~ ERROR: return statement outside of function body
|
||||
|
||||
[(); return match () { 'a' => 0, _ => 0 }]; //~ ERROR: return statement outside of function body
|
||||
}
|
||||
21
src/test/ui/return-match-array-const.stderr
Normal file
21
src/test/ui/return-match-array-const.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error[E0572]: return statement outside of function body
|
||||
--> $DIR/return-match-array-const.rs:12:10
|
||||
|
|
||||
LL | [(); return match 0 { n => n }]; //~ ERROR: return statement outside of function body
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0572]: return statement outside of function body
|
||||
--> $DIR/return-match-array-const.rs:14:10
|
||||
|
|
||||
LL | [(); return match 0 { 0 => 0 }]; //~ ERROR: return statement outside of function body
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0572]: return statement outside of function body
|
||||
--> $DIR/return-match-array-const.rs:16:10
|
||||
|
|
||||
LL | [(); return match () { 'a' => 0, _ => 0 }]; //~ ERROR: return statement outside of function body
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0572`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue