@@ -2294,18 +2294,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22942294 {
22952295 let anon_const_type = tcx. type_of ( param_def_id) . instantiate ( tcx, args) ;
22962296
2297- // We must error if the instantiated type has any inference variables as we will
2298- // use this type to feed the `type_of` and query results must not contain inference
2299- // variables otherwise we will ICE .
2300- //
2297+ // FIXME(generic_const_parameter_types): Ideally we remove these errors below when
2298+ // we have the ability to intermix typeck of anon const const args with the parent
2299+ // bodies typeck .
2300+
23012301 // We also error if the type contains any regions as effectively any region will wind
23022302 // up as a region variable in mir borrowck. It would also be somewhat concerning if
23032303 // hir typeck was using equality but mir borrowck wound up using subtyping as that could
23042304 // result in a non-infer in hir typeck but a region variable in borrowck.
2305- //
2306- // FIXME(generic_const_parameter_types): Ideally we remove these errors one day when
2307- // we have the ability to intermix typeck of anon const const args with the parent
2308- // bodies typeck.
23092305 if tcx. features ( ) . generic_const_parameter_types ( )
23102306 && ( anon_const_type. has_free_regions ( ) || anon_const_type. has_erased_regions ( ) )
23112307 {
@@ -2316,6 +2312,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23162312 tcx. feed_anon_const_type ( anon. def_id , ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, e) ) ) ;
23172313 return ty:: Const :: new_error ( tcx, e) ;
23182314 }
2315+ // We must error if the instantiated type has any inference variables as we will
2316+ // use this type to feed the `type_of` and query results must not contain inference
2317+ // variables otherwise we will ICE.
23192318 if anon_const_type. has_non_region_infer ( ) {
23202319 let e = tcx. dcx ( ) . span_err (
23212320 const_arg. span ( ) ,
@@ -2324,6 +2323,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23242323 tcx. feed_anon_const_type ( anon. def_id , ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, e) ) ) ;
23252324 return ty:: Const :: new_error ( tcx, e) ;
23262325 }
2326+ // We error when the type contains unsubstituted generics since we do not currently
2327+ // give the anon const any of the generics from the parent.
2328+ if anon_const_type. has_non_region_param ( ) {
2329+ let e = tcx. dcx ( ) . span_err (
2330+ const_arg. span ( ) ,
2331+ "anonymous constants referencing generics are not yet supported" ,
2332+ ) ;
2333+ tcx. feed_anon_const_type ( anon. def_id , ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, e) ) ) ;
2334+ return ty:: Const :: new_error ( tcx, e) ;
2335+ }
23272336
23282337 tcx. feed_anon_const_type (
23292338 anon. def_id ,
0 commit comments