@@ -371,39 +371,29 @@ fn check_opaque_type_parameter_valid(
371371 span : Span ,
372372) -> Result < ( ) , ErrorGuaranteed > {
373373 let opaque_ty_hir = tcx. hir ( ) . expect_item ( opaque_type_key. def_id ) ;
374- match opaque_ty_hir. expect_opaque_ty ( ) . origin {
375- // No need to check return position impl trait (RPIT)
376- // because for type and const parameters they are correct
377- // by construction: we convert
378- //
379- // fn foo<P0..Pn>() -> impl Trait
380- //
381- // into
382- //
383- // type Foo<P0...Pn>
384- // fn foo<P0..Pn>() -> Foo<P0...Pn>.
385- //
386- // For lifetime parameters we convert
387- //
388- // fn foo<'l0..'ln>() -> impl Trait<'l0..'lm>
389- //
390- // into
391- //
392- // type foo::<'p0..'pn>::Foo<'q0..'qm>
393- // fn foo<l0..'ln>() -> foo::<'static..'static>::Foo<'l0..'lm>.
394- //
395- // which would error here on all of the `'static` args.
396- OpaqueTyOrigin :: FnReturn ( ..) | OpaqueTyOrigin :: AsyncFn ( ..) => return Ok ( ( ) ) ,
397- // Check these
398- OpaqueTyOrigin :: TyAlias { .. } => { }
399- }
374+ let is_ty_alias = match opaque_ty_hir. expect_opaque_ty ( ) . origin {
375+ OpaqueTyOrigin :: TyAlias { .. } => true ,
376+ OpaqueTyOrigin :: AsyncFn ( ..) | OpaqueTyOrigin :: FnReturn ( ..) => false ,
377+ } ;
378+
400379 let opaque_generics = tcx. generics_of ( opaque_type_key. def_id ) ;
401380 let mut seen_params: FxIndexMap < _ , Vec < _ > > = FxIndexMap :: default ( ) ;
402381 for ( i, arg) in opaque_type_key. args . iter ( ) . enumerate ( ) {
382+ if let Err ( guar) = arg. error_reported ( ) {
383+ return Err ( guar) ;
384+ }
385+
403386 let arg_is_param = match arg. unpack ( ) {
404387 GenericArgKind :: Type ( ty) => matches ! ( ty. kind( ) , ty:: Param ( _) ) ,
405388 GenericArgKind :: Lifetime ( lt) => {
406- matches ! ( * lt, ty:: ReEarlyBound ( _) | ty:: ReFree ( _) )
389+ if is_ty_alias {
390+ matches ! ( * lt, ty:: ReEarlyBound ( _) | ty:: ReFree ( _) )
391+ } else {
392+ // FIXME(#113916): we can't currently check for unique lifetime params,
393+ // see that issue for more. We will also have to ignore bivariant lifetime
394+ // params for RPIT, but that's comparatively trivial ✨
395+ continue ;
396+ }
407397 }
408398 GenericArgKind :: Const ( ct) => matches ! ( ct. kind( ) , ty:: ConstKind :: Param ( _) ) ,
409399 } ;
0 commit comments