@@ -11,8 +11,9 @@ use crate::astconv::generics::{
1111use crate :: bounds:: Bounds ;
1212use crate :: collect:: HirPlaceholderCollector ;
1313use crate :: errors:: {
14- AmbiguousLifetimeBound , MultipleRelaxedDefaultBounds , TraitObjectDeclaredWithNoTraits ,
15- TypeofReservedKeywordUsed , ValueOfAssociatedStructAlreadySpecified , WildPatTy ,
14+ AmbiguousLifetimeBound , MultipleRelaxedDefaultBounds , NonConstRange ,
15+ TraitObjectDeclaredWithNoTraits , TypeofReservedKeywordUsed ,
16+ ValueOfAssociatedStructAlreadySpecified , WildPatTy ,
1617} ;
1718use crate :: middle:: resolve_lifetime as rl;
1819use crate :: require_c_abi_if_c_variadic;
@@ -29,6 +30,7 @@ use rustc_hir::intravisit::{walk_generics, Visitor as _};
2930use rustc_hir:: { GenericArg , GenericArgs , OpaqueTyOrigin } ;
3031use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
3132use rustc_middle:: middle:: stability:: AllowUnstable ;
33+ use rustc_middle:: mir:: interpret:: { LitToConstError , LitToConstInput } ;
3234use rustc_middle:: ty:: subst:: { self , GenericArgKind , InternalSubsts , SubstsRef } ;
3335use rustc_middle:: ty:: GenericParamDefKind ;
3436use rustc_middle:: ty:: { self , Const , DefIdTree , IsSuggestable , Ty , TyCtxt , TypeVisitable } ;
@@ -2968,23 +2970,72 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29682970 // handled specially and will not descend into this routine.
29692971 self . ty_infer ( None , ast_ty. span )
29702972 }
2971- hir:: TyKind :: Pat ( _ty, pat) => match pat. kind {
2972- hir:: PatKind :: Wild => {
2973- let err = tcx. sess . emit_err ( WildPatTy { span : pat. span } ) ;
2974- tcx. ty_error_with_guaranteed ( err)
2975- }
2976- hir:: PatKind :: Binding ( _, _, _, _) => todo ! ( ) ,
2977- hir:: PatKind :: Struct ( _, _, _) => todo ! ( ) ,
2978- hir:: PatKind :: TupleStruct ( _, _, _) => todo ! ( ) ,
2979- hir:: PatKind :: Or ( _) => todo ! ( ) ,
2980- hir:: PatKind :: Path ( _) => todo ! ( ) ,
2981- hir:: PatKind :: Tuple ( _, _) => todo ! ( ) ,
2982- hir:: PatKind :: Box ( _) => todo ! ( ) ,
2983- hir:: PatKind :: Ref ( _, _) => todo ! ( ) ,
2984- hir:: PatKind :: Lit ( _) => todo ! ( ) ,
2985- hir:: PatKind :: Range ( _, _, _) => tcx. ty_error ( ) ,
2986- hir:: PatKind :: Slice ( _, _, _) => todo ! ( ) ,
2987- } ,
2973+ hir:: TyKind :: Pat ( ty, pat) => {
2974+ let ty = self . ast_ty_to_ty ( ty) ;
2975+ let pat_ty = match pat. kind {
2976+ hir:: PatKind :: Wild => {
2977+ let err = tcx. sess . emit_err ( WildPatTy { span : pat. span } ) ;
2978+ tcx. ty_error_with_guaranteed ( err)
2979+ }
2980+ hir:: PatKind :: Binding ( _, _, _, _) => todo ! ( ) ,
2981+ hir:: PatKind :: Struct ( _, _, _) => todo ! ( ) ,
2982+ hir:: PatKind :: TupleStruct ( _, _, _) => todo ! ( ) ,
2983+ hir:: PatKind :: Or ( _) => todo ! ( ) ,
2984+ hir:: PatKind :: Path ( _) => todo ! ( ) ,
2985+ hir:: PatKind :: Tuple ( _, _) => todo ! ( ) ,
2986+ hir:: PatKind :: Box ( _) => todo ! ( ) ,
2987+ hir:: PatKind :: Ref ( _, _) => todo ! ( ) ,
2988+ hir:: PatKind :: Lit ( _) => todo ! ( ) ,
2989+ hir:: PatKind :: Range ( start, end, include_end) => {
2990+ let expr_to_const = |expr : & ' tcx hir:: Expr < ' tcx > , neg| -> ty:: Const < ' tcx > {
2991+ match & expr. kind {
2992+ hir:: ExprKind :: Lit ( lit) => {
2993+ let lit_input = LitToConstInput { lit : & lit. node , ty, neg } ;
2994+ match tcx. lit_to_const ( lit_input) {
2995+ Ok ( c) => c,
2996+ Err ( LitToConstError :: Reported ( err) ) => {
2997+ tcx. const_error_with_guaranteed ( ty, err)
2998+ }
2999+ Err ( LitToConstError :: TypeError ) => todo ! ( ) ,
3000+ }
3001+ }
3002+ _ => {
3003+ let err = tcx. sess . emit_err ( NonConstRange { span : expr. span } ) ;
3004+ tcx. const_error_with_guaranteed ( ty, err)
3005+ }
3006+ }
3007+ } ;
3008+ let expr_to_const = |expr, neg| {
3009+ let c = expr_to_const ( expr, neg) ;
3010+ self . record_ty ( expr. hir_id , c. ty ( ) , expr. span ) ;
3011+ c
3012+ } ;
3013+ let expr_to_const = |expr : & ' tcx hir:: Expr < ' tcx > | match & expr. kind {
3014+ hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , expr) => expr_to_const ( expr, true ) ,
3015+ _ => expr_to_const ( expr, false ) ,
3016+ } ;
3017+ let expr_to_const = |expr| {
3018+ let c = expr_to_const ( expr) ;
3019+ self . record_ty ( expr. hir_id , c. ty ( ) , expr. span ) ;
3020+ c
3021+ } ;
3022+
3023+ let start = start. map ( expr_to_const) ;
3024+ let end = end. map ( expr_to_const) ;
3025+
3026+ let include_end = match include_end {
3027+ hir:: RangeEnd :: Included => true ,
3028+ hir:: RangeEnd :: Excluded => false ,
3029+ } ;
3030+
3031+ let pat = tcx. mk_pat ( ty:: PatternKind :: Range { start, end, include_end } ) ;
3032+ tcx. mk_ty ( ty:: Pat ( ty, pat) )
3033+ }
3034+ hir:: PatKind :: Slice ( _, _, _) => todo ! ( ) ,
3035+ } ;
3036+ self . record_ty ( pat. hir_id , ty, pat. span ) ;
3037+ pat_ty
3038+ }
29883039 hir:: TyKind :: Err => tcx. ty_error ( ) ,
29893040 } ;
29903041
0 commit comments