@@ -16,7 +16,7 @@ use rustc_trait_selection::traits::ObligationCtxt;
1616use tracing:: { debug, instrument} ;
1717
1818use super :: potentially_plural_count;
19- use crate :: errors:: LifetimesOrBoundsMismatchOnEII ;
19+ use crate :: errors:: { EiiWithGenerics , LifetimesOrBoundsMismatchOnEII } ;
2020
2121/// Checks a bunch of different properties of the impl/trait methods for
2222/// compatibility, such as asyncness, number of argument, self receiver kind,
@@ -28,12 +28,31 @@ fn check_is_structurally_compatible<'tcx>(
2828 eii_name : Symbol ,
2929 eii_attr_span : Span ,
3030) -> Result < ( ) , ErrorGuaranteed > {
31- // FIXME(jdonszelmann): check no generics
31+ check_no_generics ( tcx , external_impl , declaration , eii_name , eii_attr_span ) ? ;
3232 compare_number_of_method_arguments ( tcx, external_impl, declaration, eii_name, eii_attr_span) ?;
3333 check_region_bounds_on_impl_item ( tcx, external_impl, declaration, eii_attr_span) ?;
3434 Ok ( ( ) )
3535}
3636
37+ fn check_no_generics < ' tcx > (
38+ tcx : TyCtxt < ' tcx > ,
39+ external_impl : LocalDefId ,
40+ _declaration : DefId ,
41+ eii_name : Symbol ,
42+ eii_attr_span : Span ,
43+ ) -> Result < ( ) , ErrorGuaranteed > {
44+ let generics = tcx. generics_of ( external_impl) ;
45+ if generics. own_requires_monomorphization ( ) {
46+ tcx. dcx ( ) . emit_err ( EiiWithGenerics {
47+ span : tcx. def_span ( external_impl) ,
48+ attr : eii_attr_span,
49+ eii_name,
50+ } ) ;
51+ }
52+
53+ Ok ( ( ) )
54+ }
55+
3756fn check_region_bounds_on_impl_item < ' tcx > (
3857 tcx : TyCtxt < ' tcx > ,
3958 external_impl : LocalDefId ,
@@ -268,6 +287,8 @@ pub(crate) fn compare_eii_function_types<'tcx>(
268287 terr,
269288 ( declaration, declaration_sig) ,
270289 ( external_impl, external_impl_sig) ,
290+ eii_attr_span,
291+ eii_name,
271292 ) ;
272293 return Err ( emitted) ;
273294 }
@@ -299,6 +320,8 @@ fn report_eii_mismatch<'tcx>(
299320 terr : TypeError < ' tcx > ,
300321 ( declaration_did, declaration_sig) : ( DefId , ty:: FnSig < ' tcx > ) ,
301322 ( external_impl_did, external_impl_sig) : ( LocalDefId , ty:: FnSig < ' tcx > ) ,
323+ eii_attr_span : Span ,
324+ eii_name : Symbol ,
302325) -> ErrorGuaranteed {
303326 let tcx = infcx. tcx ;
304327 let ( impl_err_span, trait_err_span, external_impl_name) =
@@ -308,9 +331,12 @@ fn report_eii_mismatch<'tcx>(
308331 tcx. dcx( ) ,
309332 impl_err_span,
310333 E0053 , // TODO: new error code
311- "function `{}` has a type that is incompatible with the declaration" ,
334+ "function `{}` has a type that is incompatible with the declaration of `#[{eii_name}]` " ,
312335 external_impl_name
313336 ) ;
337+
338+ diag. span_note ( eii_attr_span, "expected this because of this attribute" ) ;
339+
314340 match & terr {
315341 TypeError :: ArgumentMutability ( i) | TypeError :: ArgumentSorts ( _, i) => {
316342 if declaration_sig. inputs ( ) . len ( ) == * i {
0 commit comments