@@ -16,7 +16,7 @@ use rustc_trait_selection::traits::ObligationCtxt;
16
16
use tracing:: { debug, instrument} ;
17
17
18
18
use super :: potentially_plural_count;
19
- use crate :: errors:: LifetimesOrBoundsMismatchOnEII ;
19
+ use crate :: errors:: { EiiWithGenerics , LifetimesOrBoundsMismatchOnEII } ;
20
20
21
21
/// Checks a bunch of different properties of the impl/trait methods for
22
22
/// compatibility, such as asyncness, number of argument, self receiver kind,
@@ -28,12 +28,31 @@ fn check_is_structurally_compatible<'tcx>(
28
28
eii_name : Symbol ,
29
29
eii_attr_span : Span ,
30
30
) -> Result < ( ) , ErrorGuaranteed > {
31
- // FIXME(jdonszelmann): check no generics
31
+ check_no_generics ( tcx , external_impl , declaration , eii_name , eii_attr_span ) ? ;
32
32
compare_number_of_method_arguments ( tcx, external_impl, declaration, eii_name, eii_attr_span) ?;
33
33
check_region_bounds_on_impl_item ( tcx, external_impl, declaration, eii_attr_span) ?;
34
34
Ok ( ( ) )
35
35
}
36
36
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
+
37
56
fn check_region_bounds_on_impl_item < ' tcx > (
38
57
tcx : TyCtxt < ' tcx > ,
39
58
external_impl : LocalDefId ,
@@ -268,6 +287,8 @@ pub(crate) fn compare_eii_function_types<'tcx>(
268
287
terr,
269
288
( declaration, declaration_sig) ,
270
289
( external_impl, external_impl_sig) ,
290
+ eii_attr_span,
291
+ eii_name,
271
292
) ;
272
293
return Err ( emitted) ;
273
294
}
@@ -299,6 +320,8 @@ fn report_eii_mismatch<'tcx>(
299
320
terr : TypeError < ' tcx > ,
300
321
( declaration_did, declaration_sig) : ( DefId , ty:: FnSig < ' tcx > ) ,
301
322
( external_impl_did, external_impl_sig) : ( LocalDefId , ty:: FnSig < ' tcx > ) ,
323
+ eii_attr_span : Span ,
324
+ eii_name : Symbol ,
302
325
) -> ErrorGuaranteed {
303
326
let tcx = infcx. tcx ;
304
327
let ( impl_err_span, trait_err_span, external_impl_name) =
@@ -308,9 +331,12 @@ fn report_eii_mismatch<'tcx>(
308
331
tcx. dcx( ) ,
309
332
impl_err_span,
310
333
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}]` " ,
312
335
external_impl_name
313
336
) ;
337
+
338
+ diag. span_note ( eii_attr_span, "expected this because of this attribute" ) ;
339
+
314
340
match & terr {
315
341
TypeError :: ArgumentMutability ( i) | TypeError :: ArgumentSorts ( _, i) => {
316
342
if declaration_sig. inputs ( ) . len ( ) == * i {
0 commit comments