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

Code before:
            trait_number_args
        );

        if let Some(trait_span) = trait_span {
            err.span_label(
                trait_span,
                format!(
                    "trait requires {}",
                    potentially_plural_count(trait_number_args, "parameter")
                ),
            );
        } else {
            err.note_trait_signature(trait_m.name(), trait_m.signature(tcx));
        }

        err.span_label(
            impl_span,
            format!(
                "expected {}, found {}",
                potentially_plural_count(trait_number_args, "parameter"),
                impl_number_args
            ),
        );

        let sm = tcx.sess.source_map();
        let find_param_bounds = |snippet: &str| -> Option<(usize, usize)> {
            let start = snippet.find('(')?;
            let mut depth = 1usize;
            let bytes = snippet.as_bytes();
            let mut i = start + 1;
            while i < bytes.len() {
                match bytes[i] as char {
                    '(' => depth += 1,
                    ')' => {
                        depth -= 1;
                        if depth == 0 {
                            return Some((start + 1, i));
                        }
                    }
                    _ => {}
                }
                i += 1;
            }
            None
        };

        let impl_inputs_span = (!impl_m_sig.span.is_dummy())
            .then(|| {
                sm.span_to_snippet(impl_m_sig.span).ok().and_then(|snippet| {
                    find_param_bounds(&snippet).map(|(lo_rel, hi_rel)| {
                        let lo = impl_m_sig.span.lo() + BytePos(lo_rel as u32);

Review comment (suggestion):
Nit: Maybe make this a function? That makes it clearer that it doesn't capture anything.
```suggestion
        fn find_param_bounds(snippet: &str) -> Option<(usize, usize)> {
```

Code after:
    if let Some(reported) = err_occurred { Err(reported) } else { Ok(()) }
}

fn compare_number_of_method_arguments<'tcx>(
    tcx: TyCtxt<'tcx>,
    impl_m: ty::AssocItem,
    trait_m: ty::AssocItem,
    delay: bool,
) -> Result<(), ErrorGuaranteed> {
    let impl_m_fty = tcx.fn_sig(impl_m.def_id);
    let trait_m_fty = tcx.fn_sig(trait_m.def_id);
    let trait_number_args = trait_m_fty.skip_binder().inputs().skip_binder().len();
    let impl_number_args = impl_m_fty.skip_binder().inputs().skip_binder().len();

    if trait_number_args != impl_number_args {
        let trait_span = trait_m
            .def_id
            .as_local()
            .and_then(|def_id| {
                let (trait_m_sig, _) = &tcx.hir_expect_trait_item(def_id).expect_fn();
                let pos = trait_number_args.saturating_sub(1);
                trait_m_sig.decl.inputs.get(pos).map(|arg| {
                    if pos == 0 {
                        arg.span
                    } else {
                        arg.span.with_lo(trait_m_sig.decl.inputs[0].span.lo())
                    }
                })
            })
            .or_else(|| tcx.hir_span_if_local(trait_m.def_id));

        let (impl_m_sig, _) = &tcx.hir_expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
        let pos = impl_number_args.saturating_sub(1);
        let impl_span = impl_m_sig
            .decl
            .inputs
            .get(pos)
            .map(|arg| {
                if pos == 0 {
                    arg.span
                } else {
                    arg.span.with_lo(impl_m_sig.decl.inputs[0].span.lo())
                }
            })
            .unwrap_or_else(|| tcx.def_span(impl_m.def_id));

        let mut err = struct_span_code_err!(
            tcx.dcx(),
            impl_span,
            E0050,
            "method `{}` has {} but the declaration in trait `{}` has {}",