@@ -512,61 +512,69 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
512
512
explicit_late_bound == ExplicitLateBound :: Yes ,
513
513
) ;
514
514
515
- let mut check_types_and_consts =
516
- |expected_min, expected_max, provided, params_offset, args_offset| {
517
- debug ! (
518
- ?expected_min,
519
- ?expected_max,
520
- ?provided,
521
- ?params_offset,
522
- ?args_offset,
523
- "check_types_and_consts"
515
+ let mut check_types_and_consts = |expected_min,
516
+ expected_max,
517
+ expected_max_with_synth,
518
+ provided,
519
+ params_offset,
520
+ args_offset| {
521
+ debug ! (
522
+ ?expected_min,
523
+ ?expected_max,
524
+ ?provided,
525
+ ?params_offset,
526
+ ?args_offset,
527
+ "check_types_and_consts"
528
+ ) ;
529
+ if ( expected_min..=expected_max) . contains ( & provided) {
530
+ return true ;
531
+ }
532
+
533
+ let num_default_params = expected_max - expected_min;
534
+
535
+ let gen_args_info = if provided > expected_max {
536
+ invalid_args. extend (
537
+ gen_args. args [ args_offset + expected_max..args_offset + provided]
538
+ . iter ( )
539
+ . map ( |arg| arg. span ( ) ) ,
524
540
) ;
525
- if ( expected_min..=expected_max) . contains ( & provided) {
526
- return true ;
541
+ let num_redundant_args = provided - expected_max;
542
+
543
+ // Provide extra note if synthetic arguments like `impl Trait` are specified.
544
+ let synth_provided = provided <= expected_max_with_synth;
545
+
546
+ GenericArgsInfo :: ExcessTypesOrConsts {
547
+ num_redundant_args,
548
+ num_default_params,
549
+ args_offset,
550
+ synth_provided,
527
551
}
552
+ } else {
553
+ let num_missing_args = expected_max - provided;
528
554
529
- let num_default_params = expected_max - expected_min;
555
+ GenericArgsInfo :: MissingTypesOrConsts {
556
+ num_missing_args,
557
+ num_default_params,
558
+ args_offset,
559
+ }
560
+ } ;
530
561
531
- let gen_args_info = if provided > expected_max {
532
- invalid_args. extend (
533
- gen_args. args [ args_offset + expected_max..args_offset + provided]
534
- . iter ( )
535
- . map ( |arg| arg. span ( ) ) ,
536
- ) ;
537
- let num_redundant_args = provided - expected_max;
562
+ debug ! ( ?gen_args_info) ;
538
563
539
- GenericArgsInfo :: ExcessTypesOrConsts {
540
- num_redundant_args,
541
- num_default_params,
542
- args_offset,
543
- }
544
- } else {
545
- let num_missing_args = expected_max - provided;
564
+ WrongNumberOfGenericArgs :: new (
565
+ tcx,
566
+ gen_args_info,
567
+ seg,
568
+ gen_params,
569
+ params_offset,
570
+ gen_args,
571
+ def_id,
572
+ )
573
+ . diagnostic ( )
574
+ . emit_unless ( gen_args. has_err ( ) ) ;
546
575
547
- GenericArgsInfo :: MissingTypesOrConsts {
548
- num_missing_args,
549
- num_default_params,
550
- args_offset,
551
- }
552
- } ;
553
-
554
- debug ! ( ?gen_args_info) ;
555
-
556
- WrongNumberOfGenericArgs :: new (
557
- tcx,
558
- gen_args_info,
559
- seg,
560
- gen_params,
561
- params_offset,
562
- gen_args,
563
- def_id,
564
- )
565
- . diagnostic ( )
566
- . emit_unless ( gen_args. has_err ( ) ) ;
567
-
568
- false
569
- } ;
576
+ false
577
+ } ;
570
578
571
579
let args_correct = {
572
580
let expected_min = if infer_args {
@@ -582,6 +590,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
582
590
check_types_and_consts (
583
591
expected_min,
584
592
param_counts. consts + named_type_param_count,
593
+ param_counts. consts + named_type_param_count + synth_type_param_count,
585
594
gen_args. num_generic_params ( ) ,
586
595
param_counts. lifetimes + has_self as usize ,
587
596
gen_args. num_lifetime_params ( ) ,
0 commit comments