diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-02-16 20:51:43 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-03-04 17:13:50 +0100 |
| commit | 5c0615b89c399ce6a431ba660f9457c24bc69964 (patch) | |
| tree | 5b8fa8ae1d7ad45f5cf085b7a81f0690bfc84508 /src/librustc_codegen_ssa | |
| parent | a9da8fc9c267c08cfdb8cf5b39da14f154d12939 (diff) | |
| download | rust-5c0615b89c399ce6a431ba660f9457c24bc69964.tar.gz rust-5c0615b89c399ce6a431ba660f9457c24bc69964.zip | |
Use early unwraps instead of bubbling up errors just to unwrap in the end
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/mir/constant.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 6bc69efa4a7..349c9132842 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -49,36 +49,36 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { constant: Result<ty::Const<'tcx>, ErrorHandled>, ) -> (Bx::Value, Ty<'tcx>) { constant - .and_then(|c| { + .map(|c| { let field_ty = c.ty.builtin_index().unwrap(); let fields = match c.ty.sty { ty::Array(_, n) => n.unwrap_usize(bx.tcx()), ref other => bug!("invalid simd shuffle type: {}", other), }; - let values: Result<Vec<_>, ErrorHandled> = (0..fields).map(|field| { + let values: Vec<_> = (0..fields).map(|field| { let field = const_field( bx.tcx(), ty::ParamEnv::reveal_all(), None, mir::Field::new(field as usize), c, - )?; + ); if let Some(prim) = field.val.try_to_scalar() { let layout = bx.layout_of(field_ty); let scalar = match layout.abi { layout::Abi::Scalar(ref x) => x, _ => bug!("from_const: invalid ByVal layout: {:#?}", layout) }; - Ok(bx.scalar_to_backend( + bx.scalar_to_backend( prim, scalar, bx.immediate_backend_type(layout), - )) + ) } else { bug!("simd shuffle field {:?}", field) } }).collect(); - let llval = bx.const_struct(&values?, false); - Ok((llval, c.ty)) + let llval = bx.const_struct(&values, false); + (llval, c.ty) }) .unwrap_or_else(|_| { bx.tcx().sess.span_err( |
