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,44 +1988,48 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
// If the length is larger than 1, the repeat expression will need to copy the
|
// If the length is larger than 1, the repeat expression will need to copy the
|
||||||
// element, so we require the `Copy` trait.
|
// element, so we require the `Copy` trait.
|
||||||
if len.try_eval_usize(tcx, self.param_env).map_or(true, |len| len > 1) {
|
if len.try_eval_usize(tcx, self.param_env).map_or(true, |len| len > 1) {
|
||||||
if let Operand::Move(_) = operand {
|
match operand {
|
||||||
// While this is located in `nll::typeck` this error is not an NLL error, it's
|
Operand::Copy(..) | Operand::Constant(..) => {
|
||||||
// a required check to make sure that repeated elements implement `Copy`.
|
// These are always okay: direct use of a const, or a value that can evidently be copied.
|
||||||
let span = body.source_info(location).span;
|
}
|
||||||
let ty = operand.ty(body, tcx);
|
Operand::Move(_) => {
|
||||||
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
|
// Make sure that repeated elements implement `Copy`.
|
||||||
let ccx = ConstCx::new_with_param_env(tcx, body, self.param_env);
|
let span = body.source_info(location).span;
|
||||||
// To determine if `const_in_array_repeat_expressions` feature gate should
|
let ty = operand.ty(body, tcx);
|
||||||
// be mentioned, need to check if the rvalue is promotable.
|
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
|
||||||
let should_suggest =
|
let ccx = ConstCx::new_with_param_env(tcx, body, self.param_env);
|
||||||
should_suggest_const_in_array_repeat_expressions_attribute(
|
// To determine if `const_in_array_repeat_expressions` feature gate should
|
||||||
&ccx, operand,
|
// be mentioned, need to check if the rvalue is promotable.
|
||||||
);
|
let should_suggest =
|
||||||
debug!("check_rvalue: should_suggest={:?}", should_suggest);
|
should_suggest_const_in_array_repeat_expressions_attribute(
|
||||||
|
&ccx, operand,
|
||||||
|
);
|
||||||
|
debug!("check_rvalue: should_suggest={:?}", should_suggest);
|
||||||
|
|
||||||
let def_id = body.source.def_id().expect_local();
|
let def_id = body.source.def_id().expect_local();
|
||||||
self.infcx.report_selection_error(
|
self.infcx.report_selection_error(
|
||||||
&traits::Obligation::new(
|
&traits::Obligation::new(
|
||||||
ObligationCause::new(
|
ObligationCause::new(
|
||||||
span,
|
span,
|
||||||
self.tcx().hir().local_def_id_to_hir_id(def_id),
|
self.tcx().hir().local_def_id_to_hir_id(def_id),
|
||||||
traits::ObligationCauseCode::RepeatVec(should_suggest),
|
traits::ObligationCauseCode::RepeatVec(should_suggest),
|
||||||
),
|
|
||||||
self.param_env,
|
|
||||||
ty::Binder::bind(ty::TraitRef::new(
|
|
||||||
self.tcx().require_lang_item(
|
|
||||||
LangItem::Copy,
|
|
||||||
Some(self.last_span),
|
|
||||||
),
|
),
|
||||||
tcx.mk_substs_trait(ty, &[]),
|
self.param_env,
|
||||||
))
|
ty::Binder::bind(ty::TraitRef::new(
|
||||||
.without_const()
|
self.tcx().require_lang_item(
|
||||||
.to_predicate(self.tcx()),
|
LangItem::Copy,
|
||||||
),
|
Some(self.last_span),
|
||||||
&traits::SelectionError::Unimplemented,
|
),
|
||||||
false,
|
tcx.mk_substs_trait(ty, &[]),
|
||||||
false,
|
))
|
||||||
);
|
.without_const()
|
||||||
|
.to_predicate(self.tcx()),
|
||||||
|
),
|
||||||
|
&traits::SelectionError::Unimplemented,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue