@@ -1988,44 +1988,48 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19881988 // If the length is larger than 1, the repeat expression will need to copy the
19891989 // element, so we require the `Copy` trait.
19901990 if len. try_eval_usize ( tcx, self . param_env ) . map_or ( true , |len| len > 1 ) {
1991- if let Operand :: Move ( _) = operand {
1992- // While this is located in `nll::typeck` this error is not an NLL error, it's
1993- // a required check to make sure that repeated elements implement `Copy`.
1994- let span = body. source_info ( location) . span ;
1995- let ty = operand. ty ( body, tcx) ;
1996- if !self . infcx . type_is_copy_modulo_regions ( self . param_env , ty, span) {
1997- let ccx = ConstCx :: new_with_param_env ( tcx, body, self . param_env ) ;
1998- // To determine if `const_in_array_repeat_expressions` feature gate should
1999- // be mentioned, need to check if the rvalue is promotable.
2000- let should_suggest =
2001- should_suggest_const_in_array_repeat_expressions_attribute (
2002- & ccx, operand,
2003- ) ;
2004- debug ! ( "check_rvalue: should_suggest={:?}" , should_suggest) ;
2005-
2006- let def_id = body. source . def_id ( ) . expect_local ( ) ;
2007- self . infcx . report_selection_error (
2008- & traits:: Obligation :: new (
2009- ObligationCause :: new (
2010- span,
2011- self . tcx ( ) . hir ( ) . local_def_id_to_hir_id ( def_id) ,
2012- traits:: ObligationCauseCode :: RepeatVec ( should_suggest) ,
2013- ) ,
2014- self . param_env ,
2015- ty:: Binder :: bind ( ty:: TraitRef :: new (
2016- self . tcx ( ) . require_lang_item (
2017- LangItem :: Copy ,
2018- Some ( self . last_span ) ,
1991+ match operand {
1992+ Operand :: Copy ( ..) | Operand :: Constant ( ..) => {
1993+ // These are always okay: direct use of a const, or a value that can evidently be copied.
1994+ }
1995+ Operand :: Move ( _) => {
1996+ // Make sure that repeated elements implement `Copy`.
1997+ let span = body. source_info ( location) . span ;
1998+ let ty = operand. ty ( body, tcx) ;
1999+ if !self . infcx . type_is_copy_modulo_regions ( self . param_env , ty, span) {
2000+ let ccx = ConstCx :: new_with_param_env ( tcx, body, self . param_env ) ;
2001+ // To determine if `const_in_array_repeat_expressions` feature gate should
2002+ // be mentioned, need to check if the rvalue is promotable.
2003+ let should_suggest =
2004+ should_suggest_const_in_array_repeat_expressions_attribute (
2005+ & ccx, operand,
2006+ ) ;
2007+ debug ! ( "check_rvalue: should_suggest={:?}" , should_suggest) ;
2008+
2009+ let def_id = body. source . def_id ( ) . expect_local ( ) ;
2010+ self . infcx . report_selection_error (
2011+ & traits:: Obligation :: new (
2012+ ObligationCause :: new (
2013+ span,
2014+ self . tcx ( ) . hir ( ) . local_def_id_to_hir_id ( def_id) ,
2015+ traits:: ObligationCauseCode :: RepeatVec ( should_suggest) ,
20192016 ) ,
2020- tcx. mk_substs_trait ( ty, & [ ] ) ,
2021- ) )
2022- . without_const ( )
2023- . to_predicate ( self . tcx ( ) ) ,
2024- ) ,
2025- & traits:: SelectionError :: Unimplemented ,
2026- false ,
2027- false ,
2028- ) ;
2017+ self . param_env ,
2018+ ty:: Binder :: bind ( ty:: TraitRef :: new (
2019+ self . tcx ( ) . require_lang_item (
2020+ LangItem :: Copy ,
2021+ Some ( self . last_span ) ,
2022+ ) ,
2023+ tcx. mk_substs_trait ( ty, & [ ] ) ,
2024+ ) )
2025+ . without_const ( )
2026+ . to_predicate ( self . tcx ( ) ) ,
2027+ ) ,
2028+ & traits:: SelectionError :: Unimplemented ,
2029+ false ,
2030+ false ,
2031+ ) ;
2032+ }
20292033 }
20302034 }
20312035 }
0 commit comments