@@ -22,7 +22,7 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2222use rustc_hir:: def_id:: DefId ;
2323use rustc_hir:: intravisit:: Visitor ;
2424use rustc_hir:: print;
25- use rustc_hir:: { Constness , ExprKind , GenericArg , GenericArgs } ;
25+ use rustc_hir:: { Constness , GenericArg , GenericArgs } ;
2626use rustc_session:: lint:: builtin:: { AMBIGUOUS_ASSOCIATED_ITEMS , LATE_BOUND_LIFETIME_ARGUMENTS } ;
2727use rustc_session:: parse:: feature_err;
2828use rustc_session:: Session ;
@@ -39,8 +39,6 @@ use std::collections::BTreeSet;
3939use std:: iter;
4040use std:: slice;
4141
42- use rustc:: mir:: interpret:: LitToConstInput ;
43-
4442#[ derive( Debug ) ]
4543pub struct PathSeg ( pub DefId , pub usize ) ;
4644
@@ -782,7 +780,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
782780 }
783781 }
784782 ( GenericParamDefKind :: Const , GenericArg :: Const ( ct) ) => {
785- self . ast_const_to_const ( & ct. value , tcx. type_of ( param. def_id ) ) . into ( )
783+ ty :: Const :: from_hir_anon_const ( tcx , & ct. value , tcx. type_of ( param. def_id ) ) . into ( )
786784 }
787785 _ => unreachable ! ( ) ,
788786 } ,
@@ -2766,7 +2764,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27662764 . unwrap_or ( tcx. types . err )
27672765 }
27682766 hir:: TyKind :: Array ( ref ty, ref length) => {
2769- let length = self . ast_const_to_const ( length, tcx. types . usize ) ;
2767+ let length = ty :: Const :: from_hir_anon_const ( tcx , length, tcx. types . usize ) ;
27702768 let array_ty = tcx. mk_ty ( ty:: Array ( self . ast_ty_to_ty ( & ty) , length) ) ;
27712769 self . normalize_ty ( ast_ty. span , array_ty)
27722770 }
@@ -2798,75 +2796,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27982796 result_ty
27992797 }
28002798
2801- /// Returns the `DefId` of the constant parameter that the provided expression is a path to.
2802- pub fn const_param_def_id ( & self , expr : & hir:: Expr < ' _ > ) -> Option < DefId > {
2803- // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
2804- // currently have to be wrapped in curly brackets, so it's necessary to special-case.
2805- let expr = match & expr. kind {
2806- ExprKind :: Block ( block, _) if block. stmts . is_empty ( ) && block. expr . is_some ( ) => {
2807- block. expr . as_ref ( ) . unwrap ( )
2808- }
2809- _ => expr,
2810- } ;
2811-
2812- match & expr. kind {
2813- ExprKind :: Path ( hir:: QPath :: Resolved ( _, path) ) => match path. res {
2814- Res :: Def ( DefKind :: ConstParam , did) => Some ( did) ,
2815- _ => None ,
2816- } ,
2817- _ => None ,
2818- }
2819- }
2820-
2821- pub fn ast_const_to_const (
2822- & self ,
2823- ast_const : & hir:: AnonConst ,
2824- ty : Ty < ' tcx > ,
2825- ) -> & ' tcx ty:: Const < ' tcx > {
2826- debug ! ( "ast_const_to_const(id={:?}, ast_const={:?})" , ast_const. hir_id, ast_const) ;
2827-
2828- let tcx = self . tcx ( ) ;
2829- let def_id = tcx. hir ( ) . local_def_id ( ast_const. hir_id ) ;
2830-
2831- let expr = & tcx. hir ( ) . body ( ast_const. body ) . value ;
2832-
2833- let lit_input = match expr. kind {
2834- hir:: ExprKind :: Lit ( ref lit) => Some ( LitToConstInput { lit : & lit. node , ty, neg : false } ) ,
2835- hir:: ExprKind :: Unary ( hir:: UnOp :: UnNeg , ref expr) => match expr. kind {
2836- hir:: ExprKind :: Lit ( ref lit) => {
2837- Some ( LitToConstInput { lit : & lit. node , ty, neg : true } )
2838- }
2839- _ => None ,
2840- } ,
2841- _ => None ,
2842- } ;
2843-
2844- if let Some ( lit_input) = lit_input {
2845- // If an error occurred, ignore that it's a literal and leave reporting the error up to
2846- // mir.
2847- if let Ok ( c) = tcx. at ( expr. span ) . lit_to_const ( lit_input) {
2848- return c;
2849- } else {
2850- tcx. sess . delay_span_bug ( expr. span , "ast_const_to_const: couldn't lit_to_const" ) ;
2851- }
2852- }
2853-
2854- let kind = if let Some ( def_id) = self . const_param_def_id ( expr) {
2855- // Find the name and index of the const parameter by indexing the generics of the
2856- // parent item and construct a `ParamConst`.
2857- let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
2858- let item_id = tcx. hir ( ) . get_parent_node ( hir_id) ;
2859- let item_def_id = tcx. hir ( ) . local_def_id ( item_id) ;
2860- let generics = tcx. generics_of ( item_def_id) ;
2861- let index = generics. param_def_id_to_index [ & tcx. hir ( ) . local_def_id ( hir_id) ] ;
2862- let name = tcx. hir ( ) . name ( hir_id) ;
2863- ty:: ConstKind :: Param ( ty:: ParamConst :: new ( index, name) )
2864- } else {
2865- ty:: ConstKind :: Unevaluated ( def_id, InternalSubsts :: identity_for_item ( tcx, def_id) , None )
2866- } ;
2867- tcx. mk_const ( ty:: Const { val : kind, ty } )
2868- }
2869-
28702799 pub fn impl_trait_ty_to_ty (
28712800 & self ,
28722801 def_id : DefId ,
0 commit comments