From be6716f7f9b26bab52bb1879b273df515fe181e9 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Sat, 11 Apr 2020 15:53:10 +0800 Subject: [PATCH] Remove unnecessary variable intialization --- src/librustc_typeck/check/expr.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 7cb51b4d6d833..dbda735aa99c8 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -975,18 +975,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Expectation<'tcx>, expr: &'tcx hir::Expr<'tcx>, ) -> Ty<'tcx> { - let uty = expected.to_option(self).and_then(|uty| match uty.kind { - ty::Array(ty, _) | ty::Slice(ty) => Some(ty), - _ => None, - }); - let element_ty = if !args.is_empty() { - let coerce_to = uty.unwrap_or_else(|| { - self.next_ty_var(TypeVariableOrigin { - kind: TypeVariableOriginKind::TypeInference, - span: expr.span, + let coerce_to = expected + .to_option(self) + .and_then(|uty| match uty.kind { + ty::Array(ty, _) | ty::Slice(ty) => Some(ty), + _ => None, }) - }); + .unwrap_or_else(|| { + self.next_ty_var(TypeVariableOrigin { + kind: TypeVariableOriginKind::TypeInference, + span: expr.span, + }) + }); let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args); assert_eq!(self.diverges.get(), Diverges::Maybe); for e in args {