Repository: rust-lang/rust
File: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs (Rust)

Code before:
                            )
                        })
                    }
                }
                Ordering::Less => impl_inputs_span.and_then(|full| {
                    // Span of the arguments that there are too many of:
                    // fn foo(a: i32, b: u32) {}
                    //              ^^^^^^^^
                    let lo = if trait_number_args == 0 {
                        full.lo()
                    } else {
                        impl_m_sig
                            .decl
                            .inputs
                            .get(trait_number_args - 1)
                            .map(|arg| arg.span.hi())?
                    };
                    let span = full.with_lo(lo);
                    Some((
                        span,
                        format!(
                            "remove the extra {} to match the trait",
                            potentially_plural_count(
                                impl_number_args - trait_number_args,
                                "parameter"
                            )
                        ),
                        String::new(),
                    ))
                }),
                Ordering::Equal => unreachable!(),
            };
            if let Some((span, msg, replacement)) = suggestion {
                err.span_suggestion_verbose(span, msg, replacement, Applicability::MaybeIncorrect);
            }
        }

        return Err(err.emit_unless_delay(delay));
    }

    Ok(())
}

fn compare_synthetic_generics<'tcx>(
    tcx: TyCtxt<'tcx>,
    impl_m: ty::AssocItem,
    trait_m: ty::AssocItem,
    delay: bool,
) -> Result<(), ErrorGuaranteed> {
    // FIXME(chrisvittal) Clean up this function, list of FIXME items:
    //     1. Better messages for the span labels

Review comment (bug):
I think I was wrong with `potentially_plural_count`, should probably just be:
```suggestion
                            "remove the extra parameter{} to match the trait",
                            pluralize!(impl_number_args - trait_number_args)
```

Because "remove the extra 1 parameter to match the trait" sounds weird.

Same with `add the missing {} from the trait` above.

Code after:
                        span,
                        format!(
                            "remove the extra parameter{} to match the trait",
                            pluralize!(impl_number_args - trait_number_args)
                        ),
                        String::new(),
                    ))
                }),
                Ordering::Equal => unreachable!(),
            };
            if let Some((span, msg, replacement)) = suggestion {
                err.span_suggestion_verbose(span, msg, replacement, Applicability::MaybeIncorrect);
            }
        }

        return Err(err.emit_unless_delay(delay));
    }

    Ok(())
}

fn compare_synthetic_generics<'tcx>(
    tcx: TyCtxt<'tcx>,
    impl_m: ty::AssocItem,
    trait_m: ty::AssocItem,
    delay: bool,
) -> Result<(), ErrorGuaranteed> {
    // FIXME(chrisvittal) Clean up this function, list of FIXME items:
    //     1. Better messages for the span labels
    //     2. Explanation as to what is going on
    // If we get here, we already have the same number of generics, so the zip will
    // be okay.
    let mut error_found = None;
    let impl_m_generics = tcx.generics_of(impl_m.def_id);
    let trait_m_generics = tcx.generics_of(trait_m.def_id);
    let impl_m_type_params =
        impl_m_generics.own_params.iter().filter_map(|param| match param.kind {
            GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
            GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None,
        });
    let trait_m_type_params =
        trait_m_generics.own_params.iter().filter_map(|param| match param.kind {
            GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
            GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None,
        });
    for ((impl_def_id, impl_synthetic), (trait_def_id, trait_synthetic)) in
        iter::zip(impl_m_type_params, trait_m_type_params)
    {
        if impl_synthetic != trait_synthetic {
            let impl_def_id = impl_def_id.expect_local();
            let impl_span = tcx.def_span(impl_def_id);