@@ -339,9 +339,9 @@ fn check_opaque_type_well_formed<'tcx>(
339339 }
340340}
341341
342- fn check_opaque_type_parameter_valid (
343- tcx : TyCtxt < ' _ > ,
344- opaque_type_key : OpaqueTypeKey < ' _ > ,
342+ fn check_opaque_type_parameter_valid < ' tcx > (
343+ tcx : TyCtxt < ' tcx > ,
344+ opaque_type_key : OpaqueTypeKey < ' tcx > ,
345345 span : Span ,
346346) -> Result < ( ) , ErrorGuaranteed > {
347347 let opaque_ty_hir = tcx. hir ( ) . expect_item ( opaque_type_key. def_id ) ;
@@ -352,25 +352,28 @@ fn check_opaque_type_parameter_valid(
352352
353353 let opaque_generics = tcx. generics_of ( opaque_type_key. def_id ) ;
354354 let mut seen_params: FxIndexMap < _ , Vec < _ > > = FxIndexMap :: default ( ) ;
355- for ( i, arg) in opaque_type_key. args . iter ( ) . enumerate ( ) {
355+ for ( i, arg) in opaque_type_key. iter_captured_args ( tcx ) {
356356 if let Err ( guar) = arg. error_reported ( ) {
357357 return Err ( guar) ;
358358 }
359359
360360 let arg_is_param = match arg. unpack ( ) {
361361 GenericArgKind :: Type ( ty) => matches ! ( ty. kind( ) , ty:: Param ( _) ) ,
362- GenericArgKind :: Lifetime ( lt) if is_ty_alias => {
363- matches ! ( * lt, ty:: ReEarlyBound ( _) | ty:: ReFree ( _) )
364- }
365- // FIXME(#113916): we can't currently check for unique lifetime params,
366- // see that issue for more. We will also have to ignore unused lifetime
367- // params for RPIT, but that's comparatively trivial ✨
368- GenericArgKind :: Lifetime ( _) => continue ,
362+ GenericArgKind :: Lifetime ( lt) => match is_ty_alias {
363+ true => matches ! ( * lt, ty:: ReEarlyBound ( _) | ty:: ReFree ( _) ) ,
364+ // FIXME(#111935, #113916): For RPIT, we currently accept ReStatic as well.
365+ // This is a back-compat hack, see the issue for more.
366+ false => matches ! ( * lt, ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic ) ,
367+ } ,
369368 GenericArgKind :: Const ( ct) => matches ! ( ct. kind( ) , ty:: ConstKind :: Param ( _) ) ,
370369 } ;
371370
372371 if arg_is_param {
373- seen_params. entry ( arg) . or_default ( ) . push ( i) ;
372+ // FIXME(#113916): For RPIT, we can't currently check for unique lifetime
373+ // params, see that issue for more. We limit this to TAIT for now.
374+ if is_ty_alias {
375+ seen_params. entry ( arg) . or_default ( ) . push ( i) ;
376+ }
374377 } else {
375378 // Prevent `fn foo() -> Foo<u32>` from being defining.
376379 let opaque_param = opaque_generics. param_at ( i, tcx) ;
0 commit comments