@@ -305,14 +305,14 @@ pub(crate) fn is_anon_const<'tcx>(
305
305
fn trait_const_to_constant_expr_kind < ' tcx , S : BaseState < ' tcx > + HasOwnerId > (
306
306
s : & S ,
307
307
_const_def_id : rustc_hir:: def_id:: DefId ,
308
- substs : rustc_middle:: ty:: SubstsRef < ' tcx > ,
308
+ generics : rustc_middle:: ty:: GenericArgsRef < ' tcx > ,
309
309
assoc : & rustc_middle:: ty:: AssocItem ,
310
310
) -> ConstantExprKind {
311
311
assert ! ( assoc. trait_item_def_id. is_some( ) ) ;
312
312
let name = assoc. name . to_string ( ) ;
313
313
314
314
// Retrieve the trait information
315
- let impl_expr = get_trait_info ( s, substs , assoc) ;
315
+ let impl_expr = get_trait_info ( s, generics , assoc) ;
316
316
317
317
ConstantExprKind :: TraitConst { impl_expr, name }
318
318
}
@@ -356,19 +356,18 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
356
356
let cv = if let Some ( assoc) = s. base ( ) . tcx . opt_associated_item ( ucv. def ) {
357
357
if assoc. trait_item_def_id . is_some ( ) {
358
358
// This must be a trait declaration constant
359
- trait_const_to_constant_expr_kind ( s, ucv. def , ucv. substs , & assoc)
359
+ trait_const_to_constant_expr_kind ( s, ucv. def , ucv. args , & assoc)
360
360
} else {
361
361
// Constant appearing in an inherent impl block.
362
362
363
363
// Solve the trait obligations
364
364
let parent_def_id = tcx. parent ( ucv. def ) ;
365
365
let param_env = s. param_env ( ) ;
366
- let trait_refs =
367
- solve_item_traits ( s, param_env, parent_def_id, ucv. substs , None ) ;
366
+ let trait_refs = solve_item_traits ( s, param_env, parent_def_id, ucv. args , None ) ;
368
367
369
368
// Convert
370
369
let id = ucv. def . sinto ( s) ;
371
- let generics = ucv. substs . sinto ( s) ;
370
+ let generics = ucv. args . sinto ( s) ;
372
371
ConstantExprKind :: GlobalName {
373
372
id,
374
373
generics,
@@ -377,7 +376,7 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
377
376
}
378
377
} else {
379
378
// Top-level constant.
380
- assert ! ( ucv. substs . is_empty( ) , "top-level constant has generics?" ) ;
379
+ assert ! ( ucv. args . is_empty( ) , "top-level constant has generics?" ) ;
381
380
let id = ucv. def . sinto ( s) ;
382
381
ConstantExprKind :: GlobalName {
383
382
id,
@@ -449,7 +448,7 @@ pub(crate) fn valtree_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>(
449
448
( ty:: ValTree :: Branch ( _) , ty:: Array ( ..) | ty:: Tuple ( ..) | ty:: Adt ( ..) ) => {
450
449
let contents: rustc_middle:: ty:: DestructuredConst = s
451
450
. base ( ) . tcx
452
- . destructure_const ( s. base ( ) . tcx . mk_const ( valtree, ty) ) ;
451
+ . destructure_const ( ty :: Const :: new_value ( s. base ( ) . tcx , valtree, ty) ) ;
453
452
let fields = contents. fields . iter ( ) . copied ( ) ;
454
453
match ty. kind ( ) {
455
454
ty:: Array ( _, _) => ConstantExprKind :: Array {
@@ -499,23 +498,10 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t
499
498
val : rustc_middle:: mir:: interpret:: ConstValue < ' tcx > ,
500
499
span : rustc_span:: Span ,
501
500
) -> ConstantExpr {
502
- use rustc_middle:: mir:: interpret;
503
- use rustc_middle:: ty;
504
-
505
501
let tcx = s. base ( ) . tcx ;
506
502
507
- // We use [try_destructure_mir_constant] to destructure the constant
508
- let param_env = s. param_env ( ) ;
509
- // We have to clone some values: it is a bit annoying, but I don't
510
- // manage to get the lifetimes working otherwise...
511
- let cvalue = rustc_middle:: mir:: ConstantKind :: Val ( val, ty) ;
512
- let param_env_and_const = rustc_middle:: ty:: ParamEnvAnd {
513
- param_env,
514
- value : cvalue,
515
- } ;
516
-
517
503
let dc = tcx
518
- . try_destructure_mir_constant ( param_env_and_const )
504
+ . try_destructure_mir_constant_for_diagnostics ( ( val , ty ) )
519
505
. s_unwrap ( s) ;
520
506
521
507
// Iterate over the fields, which should be values
@@ -530,19 +516,14 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t
530
516
}
531
517
} ;
532
518
533
- // The fields should be of the variant: [ConstantKind::Value]
534
- let fields: Vec < ( ty:: Ty , interpret:: ConstValue ) > = dc
535
- . fields
536
- . iter ( )
537
- . map ( |f| ( f. ty ( ) , f. try_to_value ( tcx) . s_unwrap ( s) ) )
538
- . collect ( ) ;
539
-
540
519
// Below: we are mutually recursive with [const_value_to_constant_expr],
541
- // which takes a [ConstantKind] as input (see `cvalue` above) , but it should be
520
+ // which takes a [ConstantKind] as input, but it should be
542
521
// ok because we call it on a strictly smaller value.
543
- let fields: Vec < ConstantExpr > = fields
544
- . into_iter ( )
545
- . map ( |( ty, f) | const_value_to_constant_expr ( s, ty, f, span) )
522
+ let fields: Vec < ConstantExpr > = dc
523
+ . fields
524
+ . iter ( )
525
+ . copied ( )
526
+ . map ( |( val, ty) | const_value_to_constant_expr ( s, ty, val, span) )
546
527
. collect ( ) ;
547
528
( ConstantExprKind :: Tuple { fields } ) . decorate ( hax_ty, span. sinto ( s) )
548
529
}
@@ -577,9 +558,9 @@ pub fn const_value_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>(
577
558
let cv = match & hty {
578
559
Ty :: Tuple ( tys) if tys. is_empty ( ) => ConstantExprKind :: Tuple { fields : Vec :: new ( ) } ,
579
560
Ty :: Arrow ( _) => match ty. kind ( ) {
580
- rustc_middle:: ty:: TyKind :: FnDef ( def_id, substs ) => {
561
+ rustc_middle:: ty:: TyKind :: FnDef ( def_id, args ) => {
581
562
let ( def_id, generics, generics_impls, method_impl) =
582
- get_function_from_def_id_and_substs ( s, * def_id, substs ) ;
563
+ get_function_from_def_id_and_generics ( s, * def_id, args ) ;
583
564
584
565
ConstantExprKind :: FnPtr {
585
566
def_id,
0 commit comments