From 3a748330af35ec9da4b07f55b78e8f08f2af0888 Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Thu, 22 Sep 2022 10:15:51 -0600 Subject: [PATCH] use cherry-picked commit from #100754 to emit note without error --- compiler/rustc_error_messages/locales/en-US/passes.ftl | 6 ++++-- compiler/rustc_passes/src/errors.rs | 5 ++++- compiler/rustc_passes/src/weak_lang_items.rs | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/passes.ftl b/compiler/rustc_error_messages/locales/en-US/passes.ftl index 7dddc6e10b65..49cd2ee17588 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 0fabbb206cf9..26190af03587 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 0d2745fb5f40..92024989a75e 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 });