@@ -1099,10 +1099,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10991099 #[ instrument( skip( self ) , level = "debug" ) ]
11001100 fn check_user_type_annotations ( & mut self ) {
11011101 debug ! ( ?self . user_type_annotations) ;
1102+ let tcx = self . tcx ( ) ;
11021103 for user_annotation in self . user_type_annotations {
11031104 let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = * user_annotation;
11041105 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+ }
11061113 }
11071114 }
11081115
@@ -1195,6 +1202,36 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11951202 Ok ( ( ) )
11961203 }
11971204
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+
11981235 fn tcx ( & self ) -> TyCtxt < ' tcx > {
11991236 self . infcx . tcx
12001237 }
@@ -1851,7 +1888,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18511888 let def_id = uv. def ;
18521889 if tcx. def_kind ( def_id) == DefKind :: InlineConst {
18531890 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+ ) ;
18551897 self . normalize_and_prove_instantiated_predicates (
18561898 def_id. to_def_id ( ) ,
18571899 predicates,
@@ -2654,9 +2696,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26542696 // desugaring. A closure gets desugared to a struct, and
26552697 // these extra requirements are basically like where
26562698 // 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+ ) ,
26602708
26612709 AggregateKind :: Array ( _) | AggregateKind :: Tuple => {
26622710 ( CRATE_DEF_ID . to_def_id ( ) , ty:: InstantiatedPredicates :: empty ( ) )
@@ -2675,7 +2723,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26752723 tcx : TyCtxt < ' tcx > ,
26762724 def_id : LocalDefId ,
26772725 args : GenericArgsRef < ' tcx > ,
2678- location : Location ,
2726+ locations : Locations ,
26792727 ) -> ty:: InstantiatedPredicates < ' tcx > {
26802728 if let Some ( closure_requirements) = & tcx. mir_borrowck ( def_id) . closure_requirements {
26812729 constraint_conversion:: ConstraintConversion :: new (
@@ -2684,7 +2732,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26842732 self . region_bound_pairs ,
26852733 self . implicit_region_bound ,
26862734 self . param_env ,
2687- location . to_locations ( ) ,
2735+ locations ,
26882736 DUMMY_SP , // irrelevant; will be overridden.
26892737 ConstraintCategory :: Boring , // same as above.
26902738 self . borrowck_context . constraints ,
@@ -2710,7 +2758,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27102758 if let Err ( _) = self . eq_args (
27112759 typeck_root_args,
27122760 parent_args,
2713- location . to_locations ( ) ,
2761+ locations ,
27142762 ConstraintCategory :: BoringNoLocation ,
27152763 ) {
27162764 span_mirbug ! (
0 commit comments