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));
+ }
})
}
);
*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
},
}
);
*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
},
}
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::*;
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)
})
},
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,
--- /dev/null
+// 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
+}
--- /dev/null
+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`.