@@ -552,21 +552,34 @@ pub(crate) fn check_generic_arg_count(
552
552
synth_provided,
553
553
}
554
554
} else {
555
- let num_missing_args = expected_max - provided;
555
+ // Check if associated type bounds are incorrectly written in impl block header like:
556
+ // ```
557
+ // trait Foo<T> {}
558
+ // impl Foo<T: Default> for u8 {}
559
+ // ```
560
+ let parent_is_impl_block = cx
561
+ . tcx ( )
562
+ . hir ( )
563
+ . parent_owner_iter ( seg. hir_id )
564
+ . next ( )
565
+ . is_some_and ( |( _, owner_node) | owner_node. is_impl_block ( ) ) ;
566
+ if parent_is_impl_block {
567
+ let constraint_names: Vec < _ > =
568
+ gen_args. constraints . iter ( ) . map ( |b| b. ident . name ) . collect ( ) ;
569
+ let param_names: Vec < _ > = gen_params
570
+ . own_params
571
+ . iter ( )
572
+ . filter ( |param| !has_self || param. index != 0 ) // Assumes `Self` will always be the first parameter
573
+ . map ( |param| param. name )
574
+ . collect ( ) ;
575
+ if constraint_names == param_names {
576
+ // We set this to true and delay emitting `WrongNumberOfGenericArgs`
577
+ // to provide a succinct error for cases like issue #113073
578
+ all_params_are_binded = true ;
579
+ } ;
580
+ }
556
581
557
- let constraint_names: Vec < _ > =
558
- gen_args. constraints . iter ( ) . map ( |b| b. ident . name ) . collect ( ) ;
559
- let param_names: Vec < _ > = gen_params
560
- . own_params
561
- . iter ( )
562
- . filter ( |param| !has_self || param. index != 0 ) // Assumes `Self` will always be the first parameter
563
- . map ( |param| param. name )
564
- . collect ( ) ;
565
- if constraint_names == param_names {
566
- // We set this to true and delay emitting `WrongNumberOfGenericArgs`
567
- // to provide a succinct error for cases like issue #113073
568
- all_params_are_binded = true ;
569
- } ;
582
+ let num_missing_args = expected_max - provided;
570
583
571
584
GenericArgsInfo :: MissingTypesOrConsts {
572
585
num_missing_args,
0 commit comments