@@ -56,16 +56,17 @@ mod min_specialization;
5656pub ( crate ) fn check_impl_wf (
5757 tcx : TyCtxt < ' _ > ,
5858 impl_def_id : LocalDefId ,
59+ of_trait : bool ,
5960) -> Result < ( ) , ErrorGuaranteed > {
6061 debug_assert_matches ! ( tcx. def_kind( impl_def_id) , DefKind :: Impl { .. } ) ;
6162
6263 // Check that the args are constrained. We queryfied the check for ty/const params
6364 // since unconstrained type/const params cause ICEs in projection, so we want to
6465 // detect those specifically and project those to `TyKind::Error`.
6566 let mut res = tcx. ensure_ok ( ) . enforce_impl_non_lifetime_params_are_constrained ( impl_def_id) ;
66- res = res. and ( enforce_impl_lifetime_params_are_constrained ( tcx, impl_def_id) ) ;
67+ res = res. and ( enforce_impl_lifetime_params_are_constrained ( tcx, impl_def_id, of_trait ) ) ;
6768
68- if tcx. features ( ) . min_specialization ( ) {
69+ if of_trait && tcx. features ( ) . min_specialization ( ) {
6970 res = res. and ( check_min_specialization ( tcx, impl_def_id) ) ;
7071 }
7172 res
@@ -74,6 +75,7 @@ pub(crate) fn check_impl_wf(
7475pub ( crate ) fn enforce_impl_lifetime_params_are_constrained (
7576 tcx : TyCtxt < ' _ > ,
7677 impl_def_id : LocalDefId ,
78+ of_trait : bool ,
7779) -> Result < ( ) , ErrorGuaranteed > {
7880 let impl_self_ty = tcx. type_of ( impl_def_id) . instantiate_identity ( ) ;
7981 if impl_self_ty. references_error ( ) {
@@ -93,7 +95,8 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
9395
9496 let impl_generics = tcx. generics_of ( impl_def_id) ;
9597 let impl_predicates = tcx. predicates_of ( impl_def_id) ;
96- let impl_trait_ref = tcx. impl_trait_ref ( impl_def_id) . map ( ty:: EarlyBinder :: instantiate_identity) ;
98+ let impl_trait_ref =
99+ of_trait. then ( || tcx. impl_trait_ref ( impl_def_id) . unwrap ( ) . instantiate_identity ( ) ) ;
97100
98101 impl_trait_ref. error_reported ( ) ?;
99102
0 commit comments