@@ -2294,18 +2294,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2294
2294
{
2295
2295
let anon_const_type = tcx. type_of ( param_def_id) . instantiate ( tcx, args) ;
2296
2296
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
+
2301
2301
// We also error if the type contains any regions as effectively any region will wind
2302
2302
// up as a region variable in mir borrowck. It would also be somewhat concerning if
2303
2303
// hir typeck was using equality but mir borrowck wound up using subtyping as that could
2304
2304
// 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.
2309
2305
if tcx. features ( ) . generic_const_parameter_types ( )
2310
2306
&& ( anon_const_type. has_free_regions ( ) || anon_const_type. has_erased_regions ( ) )
2311
2307
{
@@ -2316,6 +2312,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2316
2312
tcx. feed_anon_const_type ( anon. def_id , ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, e) ) ) ;
2317
2313
return ty:: Const :: new_error ( tcx, e) ;
2318
2314
}
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.
2319
2318
if anon_const_type. has_non_region_infer ( ) {
2320
2319
let e = tcx. dcx ( ) . span_err (
2321
2320
const_arg. span ( ) ,
@@ -2324,6 +2323,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2324
2323
tcx. feed_anon_const_type ( anon. def_id , ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, e) ) ) ;
2325
2324
return ty:: Const :: new_error ( tcx, e) ;
2326
2325
}
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
+ }
2327
2336
2328
2337
tcx. feed_anon_const_type (
2329
2338
anon. def_id ,
0 commit comments