Repository: rust-lang/rust
File: compiler/rustc_resolve/src/late/diagnostics.rs (Rust)

Code before:

        if suggestions.is_empty() {
            return false;
        }

        let mut suggestions: Vec<String> = suggestions.into_iter().collect();
        suggestions.sort();

        match suggestions.as_slice() {
            [one] => {
                err.span_suggestion_verbose(
                    ident_span,
                    "use the associated type",
                    one,
                    Applicability::MaybeIncorrect,
                );
            }
            _ => {
                err.span_suggestions(
                    ident_span,
                    "use an associated type",
                    suggestions,
                    Applicability::MaybeIncorrect,
                );
            }
        };

        true
    }

    fn make_base_error(
        &mut self,
        path: &[Segment],
        span: Span,
        source: PathSource<'_, 'ast, 'ra>,
        res: Option<Res>,
    ) -> BaseError {
        // Make the base error.
        let mut expected = source.descr_expected();
        let path_str = Segment::names_to_string(path);
        let item_str = path.last().unwrap().ident;

        if let Some(res) = res {
            BaseError {
                msg: format!("expected {}, found {} `{}`", expected, res.descr(), path_str),
                fallback_label: format!("not a {expected}"),
                span,
                span_label: match res {
                    Res::Def(DefKind::TyParam, def_id) => {
                        Some((self.r.def_span(def_id), "found this type parameter"))
                    }

Review comment (suggestion):
I think we have `span_suggestions_verbose` already? That would make the match unnecessary. If not, then we should just publish a PR making `span_suggestions` *be* always verbose and be done with it (inline suggestions are rarely the best option and we should inverse the default to verbose and opt-into inline suggestions on a per case basis).

Code after:
        if suggestions.is_empty() {
            return false;
        }

        let mut suggestions: Vec<String> = suggestions.into_iter().collect();
        suggestions.sort();

        err.span_suggestions_with_style(
            ident_span,
            "you might have meant to use an associated type of the same name",
            suggestions,
            Applicability::MaybeIncorrect,
            SuggestionStyle::ShowAlways,
        );

        true
    }

    fn make_base_error(
        &mut self,
        path: &[Segment],
        span: Span,
        source: PathSource<'_, 'ast, 'ra>,
        res: Option<Res>,
    ) -> BaseError {
        // Make the base error.
        let mut expected = source.descr_expected();
        let path_str = Segment::names_to_string(path);
        let item_str = path.last().unwrap().ident;

        if let Some(res) = res {
            BaseError {
                msg: format!("expected {}, found {} `{}`", expected, res.descr(), path_str),
                fallback_label: format!("not a {expected}"),
                span,
                span_label: match res {
                    Res::Def(DefKind::TyParam, def_id) => {
                        Some((self.r.def_span(def_id), "found this type parameter"))
                    }
                    _ => None,
                },
                could_be_expr: match res {
                    Res::Def(DefKind::Fn, _) => {
                        // Verify whether this is a fn call or an Fn used as a type.
                        self.r
                            .tcx
                            .sess
                            .source_map()
                            .span_to_snippet(span)
                            .is_ok_and(|snippet| snippet.ends_with(')'))
                    }