From 89890294764fd0a3ff286167cc07d04e6b970336 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 4 Apr 2020 21:26:34 +0300 Subject: [PATCH] borrow_check/type_check: normalize `Aggregate` and `Call` operands. --- src/librustc_mir/borrow_check/type_check/mod.rs | 2 ++ .../ui/consts/issue-70773-mir-typeck-lt-norm.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index a118fe2db712..4dc4fb6d8e93 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1760,6 +1760,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() { let op_arg_ty = op_arg.ty(body, self.tcx()); + let op_arg_ty = self.normalize(op_arg_ty, term_location); let category = if from_hir_call { ConstraintCategory::CallArgument } else { @@ -2402,6 +2403,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } }; let operand_ty = operand.ty(body, tcx); + let operand_ty = self.normalize(operand_ty, location); if let Err(terr) = self.sub_types( operand_ty, diff --git a/src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs b/src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs new file mode 100644 index 000000000000..07af83104241 --- /dev/null +++ b/src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs @@ -0,0 +1,15 @@ +// run-pass + +const HASH_LEN: usize = 20; +struct Hash([u8; HASH_LEN]); +fn init_hash(_: &mut [u8; HASH_LEN]) {} + +fn foo<'a>() -> &'a () { + Hash([0; HASH_LEN]); + init_hash(&mut [0; HASH_LEN]); + &() +} + +fn main() { + foo(); +}