@@ -792,17 +792,19 @@ fn check_impl_items_against_trait<'tcx>(
792792 trait_def. must_implement_one_of . as_deref ( ) ;
793793
794794 for & trait_item_id in tcx. associated_item_def_ids ( impl_trait_ref. def_id ) {
795- let is_implemented = ancestors
796- . leaf_def ( tcx, trait_item_id)
795+ let leaf_def = ancestors. leaf_def ( tcx, trait_item_id) ;
796+
797+ let is_implemented = leaf_def
798+ . as_ref ( )
797799 . map_or ( false , |node_item| node_item. item . defaultness ( tcx) . has_value ( ) ) ;
798800
799801 if !is_implemented && tcx. impl_defaultness ( impl_id) . is_final ( ) {
800802 missing_items. push ( tcx. associated_item ( trait_item_id) ) ;
801803 }
802804
803805 // true if this item is specifically implemented in this impl
804- let is_implemented_here = ancestors
805- . leaf_def ( tcx , trait_item_id )
806+ let is_implemented_here = leaf_def
807+ . as_ref ( )
806808 . map_or ( false , |node_item| !node_item. defining_node . is_from_trait ( ) ) ;
807809
808810 if !is_implemented_here {
@@ -831,6 +833,36 @@ fn check_impl_items_against_trait<'tcx>(
831833 }
832834 }
833835 }
836+
837+ if let Some ( leaf_def) = & leaf_def
838+ && !leaf_def. is_final ( )
839+ && let def_id = leaf_def. item . def_id
840+ && tcx. impl_method_has_trait_impl_trait_tys ( def_id)
841+ {
842+ let def_kind = tcx. def_kind ( def_id) ;
843+ let descr = tcx. def_kind_descr ( def_kind, def_id) ;
844+ let ( msg, feature) = if tcx. asyncness ( def_id) . is_async ( ) {
845+ (
846+ format ! ( "async {descr} in trait cannot be specialized" ) ,
847+ sym:: async_fn_in_trait,
848+ )
849+ } else {
850+ (
851+ format ! (
852+ "{descr} with return-position `impl Trait` in trait cannot be specialized"
853+ ) ,
854+ sym:: return_position_impl_trait_in_trait,
855+ )
856+ } ;
857+ tcx. sess
858+ . struct_span_err ( tcx. def_span ( def_id) , msg)
859+ . note ( format ! (
860+ "specialization behaves in inconsistent and \
861+ surprising ways with `#![feature({feature})]`, \
862+ and for now is disallowed"
863+ ) )
864+ . emit ( ) ;
865+ }
834866 }
835867
836868 if !missing_items. is_empty ( ) {
0 commit comments