diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-03-14 15:30:35 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-03-23 13:14:36 +0100 |
| commit | 799b15ed96942aec81aecab4b2ae2f9243b632fa (patch) | |
| tree | a6d41b6d8af86647946aa33fb126cebb8f57568f /src/librustc_mir | |
| parent | 8ff785011be6625e32afceee3a08e5cff7470feb (diff) | |
| download | rust-799b15ed96942aec81aecab4b2ae2f9243b632fa.tar.gz rust-799b15ed96942aec81aecab4b2ae2f9243b632fa.zip | |
Evaluate repeat expression lengths as late as possible
Diffstat (limited to 'src/librustc_mir')
| -rw-r--r-- | src/librustc_mir/borrow_check/type_check/mod.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 521861624cb..e1aacb1fa26 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1986,7 +1986,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } Rvalue::Repeat(operand, len) => { - if *len > 1 { + // If the length cannot be evaluated we must assume that the length can be larger + // than 1. + // If the length is larger than 1, the repeat expression will need to copy the + // element, so we require the `Copy` trait. + if len.try_eval_usize(tcx, self.param_env).map_or(true, |len| len > 1) { if let Operand::Move(_) = operand { // While this is located in `nll::typeck` this error is not an NLL error, it's // a required check to make sure that repeated elements implement `Copy`. |
