@@ -792,17 +792,19 @@ fn check_impl_items_against_trait<'tcx>(
792
792
trait_def. must_implement_one_of . as_deref ( ) ;
793
793
794
794
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 ( )
797
799
. map_or ( false , |node_item| node_item. item . defaultness ( tcx) . has_value ( ) ) ;
798
800
799
801
if !is_implemented && tcx. impl_defaultness ( impl_id) . is_final ( ) {
800
802
missing_items. push ( tcx. associated_item ( trait_item_id) ) ;
801
803
}
802
804
803
805
// 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 ( )
806
808
. map_or ( false , |node_item| !node_item. defining_node . is_from_trait ( ) ) ;
807
809
808
810
if !is_implemented_here {
@@ -831,6 +833,36 @@ fn check_impl_items_against_trait<'tcx>(
831
833
}
832
834
}
833
835
}
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
+ }
834
866
}
835
867
836
868
if !missing_items. is_empty ( ) {
0 commit comments