@@ -1099,10 +1099,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1099
1099
#[ instrument( skip( self ) , level = "debug" ) ]
1100
1100
fn check_user_type_annotations ( & mut self ) {
1101
1101
debug ! ( ?self . user_type_annotations) ;
1102
+ let tcx = self . tcx ( ) ;
1102
1103
for user_annotation in self . user_type_annotations {
1103
1104
let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = * user_annotation;
1104
1105
let annotation = self . instantiate_canonical_with_fresh_inference_vars ( span, user_ty) ;
1105
- self . ascribe_user_type ( inferred_ty, annotation, span) ;
1106
+ if let ty:: UserType :: TypeOf ( def, args) = annotation
1107
+ && let DefKind :: InlineConst = tcx. def_kind ( def)
1108
+ {
1109
+ self . check_inline_const ( inferred_ty, def. expect_local ( ) , args, span) ;
1110
+ } else {
1111
+ self . ascribe_user_type ( inferred_ty, annotation, span) ;
1112
+ }
1106
1113
}
1107
1114
}
1108
1115
@@ -1195,6 +1202,36 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1195
1202
Ok ( ( ) )
1196
1203
}
1197
1204
1205
+ fn check_inline_const (
1206
+ & mut self ,
1207
+ inferred_ty : Ty < ' tcx > ,
1208
+ def_id : LocalDefId ,
1209
+ args : UserArgs < ' tcx > ,
1210
+ span : Span ,
1211
+ ) {
1212
+ assert ! ( args. user_self_ty. is_none( ) ) ;
1213
+ let tcx = self . tcx ( ) ;
1214
+ let const_ty = tcx. type_of ( def_id) . instantiate ( tcx, args. args ) ;
1215
+ if let Err ( terr) =
1216
+ self . eq_types ( const_ty, inferred_ty, Locations :: All ( span) , ConstraintCategory :: Boring )
1217
+ {
1218
+ span_bug ! (
1219
+ span,
1220
+ "bad inline const pattern: ({:?} = {:?}) {:?}" ,
1221
+ const_ty,
1222
+ inferred_ty,
1223
+ terr
1224
+ ) ;
1225
+ }
1226
+ let args = self . infcx . resolve_vars_if_possible ( args. args ) ;
1227
+ let predicates = self . prove_closure_bounds ( tcx, def_id, args, Locations :: All ( span) ) ;
1228
+ self . normalize_and_prove_instantiated_predicates (
1229
+ def_id. to_def_id ( ) ,
1230
+ predicates,
1231
+ Locations :: All ( span) ,
1232
+ ) ;
1233
+ }
1234
+
1198
1235
fn tcx ( & self ) -> TyCtxt < ' tcx > {
1199
1236
self . infcx . tcx
1200
1237
}
@@ -1851,7 +1888,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1851
1888
let def_id = uv. def ;
1852
1889
if tcx. def_kind ( def_id) == DefKind :: InlineConst {
1853
1890
let def_id = def_id. expect_local ( ) ;
1854
- let predicates = self . prove_closure_bounds ( tcx, def_id, uv. args , location) ;
1891
+ let predicates = self . prove_closure_bounds (
1892
+ tcx,
1893
+ def_id,
1894
+ uv. args ,
1895
+ location. to_locations ( ) ,
1896
+ ) ;
1855
1897
self . normalize_and_prove_instantiated_predicates (
1856
1898
def_id. to_def_id ( ) ,
1857
1899
predicates,
@@ -2654,9 +2696,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2654
2696
// desugaring. A closure gets desugared to a struct, and
2655
2697
// these extra requirements are basically like where
2656
2698
// clauses on the struct.
2657
- AggregateKind :: Closure ( def_id, args) | AggregateKind :: Coroutine ( def_id, args) => {
2658
- ( def_id, self . prove_closure_bounds ( tcx, def_id. expect_local ( ) , args, location) )
2659
- }
2699
+ AggregateKind :: Closure ( def_id, args) | AggregateKind :: Coroutine ( def_id, args) => (
2700
+ def_id,
2701
+ self . prove_closure_bounds (
2702
+ tcx,
2703
+ def_id. expect_local ( ) ,
2704
+ args,
2705
+ location. to_locations ( ) ,
2706
+ ) ,
2707
+ ) ,
2660
2708
2661
2709
AggregateKind :: Array ( _) | AggregateKind :: Tuple => {
2662
2710
( CRATE_DEF_ID . to_def_id ( ) , ty:: InstantiatedPredicates :: empty ( ) )
@@ -2675,7 +2723,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2675
2723
tcx : TyCtxt < ' tcx > ,
2676
2724
def_id : LocalDefId ,
2677
2725
args : GenericArgsRef < ' tcx > ,
2678
- location : Location ,
2726
+ locations : Locations ,
2679
2727
) -> ty:: InstantiatedPredicates < ' tcx > {
2680
2728
if let Some ( closure_requirements) = & tcx. mir_borrowck ( def_id) . closure_requirements {
2681
2729
constraint_conversion:: ConstraintConversion :: new (
@@ -2684,7 +2732,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2684
2732
self . region_bound_pairs ,
2685
2733
self . implicit_region_bound ,
2686
2734
self . param_env ,
2687
- location . to_locations ( ) ,
2735
+ locations ,
2688
2736
DUMMY_SP , // irrelevant; will be overridden.
2689
2737
ConstraintCategory :: Boring , // same as above.
2690
2738
self . borrowck_context . constraints ,
@@ -2710,7 +2758,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2710
2758
if let Err ( _) = self . eq_args (
2711
2759
typeck_root_args,
2712
2760
parent_args,
2713
- location . to_locations ( ) ,
2761
+ locations ,
2714
2762
ConstraintCategory :: BoringNoLocation ,
2715
2763
) {
2716
2764
span_mirbug ! (
0 commit comments