@@ -43,6 +43,9 @@ use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations}
43
43
use crate :: dataflow:: impls:: MaybeInitializedPlaces ;
44
44
use crate :: dataflow:: move_paths:: MoveData ;
45
45
use crate :: dataflow:: ResultsCursor ;
46
+ use crate :: transform:: {
47
+ check_consts:: ConstCx , promote_consts:: is_const_fn_in_array_repeat_expression,
48
+ } ;
46
49
47
50
use crate :: borrow_check:: {
48
51
borrow_set:: BorrowSet ,
@@ -1988,18 +1991,24 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1988
1991
Operand :: Copy ( ..) | Operand :: Constant ( ..) => {
1989
1992
// These are always okay: direct use of a const, or a value that can evidently be copied.
1990
1993
}
1991
- Operand :: Move ( _ ) => {
1994
+ Operand :: Move ( place ) => {
1992
1995
// Make sure that repeated elements implement `Copy`.
1993
1996
let span = body. source_info ( location) . span ;
1994
1997
let ty = operand. ty ( body, tcx) ;
1995
1998
if !self . infcx . type_is_copy_modulo_regions ( self . param_env , ty, span) {
1999
+ let ccx = ConstCx :: new_with_param_env ( tcx, body, self . param_env ) ;
2000
+ let is_const_fn =
2001
+ is_const_fn_in_array_repeat_expression ( & ccx, & place, & body) ;
2002
+
2003
+ debug ! ( "check_rvalue: is_const_fn={:?}" , is_const_fn) ;
2004
+
1996
2005
let def_id = body. source . def_id ( ) . expect_local ( ) ;
1997
2006
self . infcx . report_selection_error (
1998
2007
& traits:: Obligation :: new (
1999
2008
ObligationCause :: new (
2000
2009
span,
2001
2010
self . tcx ( ) . hir ( ) . local_def_id_to_hir_id ( def_id) ,
2002
- traits:: ObligationCauseCode :: RepeatVec ,
2011
+ traits:: ObligationCauseCode :: RepeatVec ( is_const_fn ) ,
2003
2012
) ,
2004
2013
self . param_env ,
2005
2014
ty:: Binder :: bind ( ty:: TraitRef :: new (
0 commit comments