use exhaustive match for checking Rvalue::Repeat
This commit is contained in:
parent
bd2f1cb278
commit
54a3ed3114
1 changed files with 40 additions and 36 deletions
|
@ -1988,9 +1988,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
// 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`.
|
||||
match operand {
|
||||
Operand::Copy(..) | Operand::Constant(..) => {
|
||||
// These are always okay: direct use of a const, or a value that can evidently be copied.
|
||||
}
|
||||
Operand::Move(_) => {
|
||||
// Make sure that repeated elements implement `Copy`.
|
||||
let span = body.source_info(location).span;
|
||||
let ty = operand.ty(body, tcx);
|
||||
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
|
||||
|
@ -2030,6 +2033,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rvalue::NullaryOp(_, ty) => {
|
||||
// Even with unsized locals cannot box an unsized value.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue