@@ -8,6 +8,8 @@ use rustc_middle::middle::lang_items::required;
8
8
use rustc_middle:: ty:: TyCtxt ;
9
9
use rustc_session:: config:: CrateType ;
10
10
11
+ use crate :: errors:: { MissingAllocErrorHandler , MissingLangItem , MissingPanicHandler } ;
12
+
11
13
/// Checks the crate for usage of weak lang items, returning a vector of all the
12
14
/// language items required by this crate, but not defined yet.
13
15
pub fn check_crate < ' tcx > ( tcx : TyCtxt < ' tcx > , items : & mut lang_items:: LanguageItems ) {
@@ -71,20 +73,13 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
71
73
for ( name, & item) in WEAK_ITEMS_REFS . iter ( ) {
72
74
if missing. contains ( & item) && required ( tcx, item) && items. require ( item) . is_err ( ) {
73
75
if item == LangItem :: PanicImpl {
74
- tcx. sess . err ( "`#[panic_handler]` function required, but not found" ) ;
76
+ tcx. sess . emit_err ( MissingPanicHandler ) ;
75
77
} else if item == LangItem :: Oom {
76
78
if !tcx. features ( ) . default_alloc_error_handler {
77
- tcx. sess . err ( "`#[alloc_error_handler]` function required, but not found" ) ;
78
- tcx. sess . note_without_error ( "use `#![feature(default_alloc_error_handler)]` for a default error handler" ) ;
79
+ tcx. sess . emit_err ( MissingAllocErrorHandler ) ;
79
80
}
80
81
} else {
81
- tcx
82
- . sess
83
- . diagnostic ( )
84
- . struct_err ( & format ! ( "language item required, but not found: `{}`" , name) )
85
- . note ( & format ! ( "this can occur when a binary crate with `#![no_std]` is compiled for a target where `{}` is defined in the standard library" , name) )
86
- . help ( & format ! ( "you may be able to compile for a target that doesn't need `{}`, specify a target with `--target` or in `.cargo/config`" , name) )
87
- . emit ( ) ;
82
+ tcx. sess . emit_err ( MissingLangItem { name : * name } ) ;
88
83
}
89
84
}
90
85
}
0 commit comments