diff --git a/compiler/rustc_error_messages/locales/en-US/passes.ftl b/compiler/rustc_error_messages/locales/en-US/passes.ftl index 7dddc6e10b6..49cd2ee1758 100644 --- a/compiler/rustc_error_messages/locales/en-US/passes.ftl +++ b/compiler/rustc_error_messages/locales/en-US/passes.ftl @@ -364,9 +364,11 @@ passes_unknown_external_lang_item = passes_missing_panic_handler = `#[panic_handler]` function required, but not found -passes_missing_alloc_error_handler = +passes_alloc_func_required = `#[alloc_error_handler]` function required, but not found - .note = use `#![feature(default_alloc_error_handler)]` for a default error handler + +passes_missing_alloc_error_handler = + use `#![feature(default_alloc_error_handler)]` for a default error handler passes_missing_lang_item = language item required, but not found: `{$name}` diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 0fabbb206cf..26190af0358 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -690,9 +690,12 @@ pub struct UnknownExternLangItem { #[diag(passes::missing_panic_handler)] pub struct MissingPanicHandler; +#[derive(Diagnostic)] +#[diag(passes::alloc_func_required)] +pub struct AllocFuncRequired; + #[derive(Diagnostic)] #[diag(passes::missing_alloc_error_handler)] -#[note] pub struct MissingAllocErrorHandler; #[derive(Diagnostic)] diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 0d2745fb5f4..92024989a75 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -8,7 +8,8 @@ use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; use crate::errors::{ - MissingAllocErrorHandler, MissingLangItem, MissingPanicHandler, UnknownExternLangItem, + AllocFuncRequired, MissingAllocErrorHandler, MissingLangItem, MissingPanicHandler, + UnknownExternLangItem, }; /// Checks the crate for usage of weak lang items, returning a vector of all the @@ -70,7 +71,8 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) { tcx.sess.emit_err(MissingPanicHandler); } else if item == LangItem::Oom { if !tcx.features().default_alloc_error_handler { - tcx.sess.emit_err(MissingAllocErrorHandler); + tcx.sess.emit_err(AllocFuncRequired); + tcx.sess.emit_note(MissingAllocErrorHandler); } } else { tcx.sess.emit_err(MissingLangItem { name: *name });