Repository: rust-lang/rust
File: compiler/rustc_const_eval/src/check_consts/ops.rs (Rust)

Code before:
                    span.push_span_label(trait_span, format!("this {trait_descr} is not const"));
                    err.span_note(
                        span,
                        format!(
                            "{def_descr} `{assoc_name}` is not const because {trait_descr} \
                            `{trait_name}` is not const",
                        ),
                    );
                    if parent.is_local() && ccx.tcx.sess.is_nightly_build() {
                        if !ccx.tcx.features().const_trait_impl() {
                            err.help(
                                "add `#![feature(const_trait_impl)]` to the crate attributes to \
                                 enable `#[const_trait]`",
                            );
                        }
                        let indentation = ccx
                            .tcx
                            .sess
                            .source_map()
                            .indentation_before(trait_span)
                            .unwrap_or_default();
                        err.span_suggestion_verbose(
                            trait_span.shrink_to_lo(),
                            format!("consider making trait `{trait_name}` const"),
                            format!("#[const_trait]\n{indentation}"),
                            Applicability::MachineApplicable,
                        );
                    } else if !ccx.tcx.sess.is_nightly_build() {
                        err.help("const traits are not yet supported on stable Rust");
                    }
                }
            } else if ccx.tcx.constness(callee) != hir::Constness::Const {
                let name = ccx.tcx.item_name(callee);
                err.span_note(
                    ccx.tcx.def_span(callee),
                    format!("{def_descr} `{name}` is not const"),
                );
            }
            err
        }
    };

    if note {
        err.note(format!(
            "calls in {}s are limited to constant functions, tuple structs and tuple variants",
            ccx.const_kind(),
        ));
    }

    err
}

Review comment (bug):
This is not `MachineApplicable`, since it doesn't fix the bug completely.

Code after:
                                 enable `#[const_trait]`",
                            );
                        }
                        let indentation = ccx
                            .tcx
                            .sess
                            .source_map()
                            .indentation_before(trait_span)
                            .unwrap_or_default();
                        err.span_suggestion_verbose(
                            trait_span.shrink_to_lo(),
                            format!("consider making trait `{trait_name}` const"),
                            format!("#[const_trait]\n{indentation}"),
                            Applicability::MaybeIncorrect,
                        );
                    } else if !ccx.tcx.sess.is_nightly_build() {
                        err.help("const traits are not yet supported on stable Rust");
                    }
                }
            } else if ccx.tcx.constness(callee) != hir::Constness::Const {
                let name = ccx.tcx.item_name(callee);
                err.span_note(
                    ccx.tcx.def_span(callee),
                    format!("{def_descr} `{name}` is not const"),
                );
            }
            err
        }
    };

    err.note(format!(
        "calls in {}s are limited to constant functions, tuple structs and tuple variants",
        ccx.const_kind(),
    ));

    err
}

/// A call to an `#[unstable]` const fn, `#[rustc_const_unstable]` function or trait.
///
/// Contains the name of the feature that would allow the use of this function/trait.
#[derive(Debug)]
pub(crate) struct CallUnstable {
    pub def_id: DefId,
    pub feature: Symbol,
    /// If this is true, then the feature is enabled, but we need to still check if it is safe to
    /// expose on stable.
    pub feature_enabled: bool,
    pub safe_to_expose_on_stable: bool,
    /// true if `def_id` is the function we are calling, false if `def_id` is an unstable trait.
    pub is_function_call: bool,