Migrate weak_lang_items.rs
This commit is contained in:
parent
bde80f745b
commit
2f74d1d14f
3 changed files with 31 additions and 10 deletions
|
@ -271,3 +271,12 @@ passes_collapse_debuginfo = `collapse_debuginfo` attribute should be applied to
|
||||||
|
|
||||||
passes_deprecated_annotation_has_no_effect = this `#[deprecated]` annotation has no effect
|
passes_deprecated_annotation_has_no_effect = this `#[deprecated]` annotation has no effect
|
||||||
.suggestion = remove the unnecessary deprecation attribute
|
.suggestion = remove the unnecessary deprecation attribute
|
||||||
|
|
||||||
|
passes_missing_panic_handler = `#[panic_handler]` function required, but not found
|
||||||
|
|
||||||
|
passes_missing_alloc_error_handler = `#[alloc_error_handler]` function required, but not found
|
||||||
|
.note = use `#![feature(default_alloc_error_handler)]` for a default error handler
|
||||||
|
|
||||||
|
passes_missing_lang_item = language item required, but not found: `{$name}`
|
||||||
|
.note = this can occur when a binary crate with `#![no_std]` is compiled for a target where `{$name}` is defined in the standard library
|
||||||
|
.help = you may be able to compile for a target that doesn't need `{$name}`, specify a target with `--target` or in `.cargo/config`
|
||||||
|
|
|
@ -665,3 +665,20 @@ pub struct DeprecatedAnnotationHasNoEffect {
|
||||||
#[suggestion(applicability = "machine-applicable", code = "")]
|
#[suggestion(applicability = "machine-applicable", code = "")]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(passes::missing_panic_handler)]
|
||||||
|
pub struct MissingPanicHandler;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(passes::missing_alloc_error_handler)]
|
||||||
|
#[note]
|
||||||
|
pub struct MissingAllocErrorHandler;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(passes::missing_lang_item)]
|
||||||
|
#[note]
|
||||||
|
#[help]
|
||||||
|
pub struct MissingLangItem {
|
||||||
|
pub name: Symbol,
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ use rustc_middle::middle::lang_items::required;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::config::CrateType;
|
use rustc_session::config::CrateType;
|
||||||
|
|
||||||
|
use crate::errors::{MissingAllocErrorHandler, MissingLangItem, MissingPanicHandler};
|
||||||
|
|
||||||
/// Checks the crate for usage of weak lang items, returning a vector of all the
|
/// Checks the crate for usage of weak lang items, returning a vector of all the
|
||||||
/// language items required by this crate, but not defined yet.
|
/// language items required by this crate, but not defined yet.
|
||||||
pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItems) {
|
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) {
|
||||||
for (name, &item) in WEAK_ITEMS_REFS.iter() {
|
for (name, &item) in WEAK_ITEMS_REFS.iter() {
|
||||||
if missing.contains(&item) && required(tcx, item) && items.require(item).is_err() {
|
if missing.contains(&item) && required(tcx, item) && items.require(item).is_err() {
|
||||||
if item == LangItem::PanicImpl {
|
if item == LangItem::PanicImpl {
|
||||||
tcx.sess.err("`#[panic_handler]` function required, but not found");
|
tcx.sess.emit_err(MissingPanicHandler);
|
||||||
} else if item == LangItem::Oom {
|
} else if item == LangItem::Oom {
|
||||||
if !tcx.features().default_alloc_error_handler {
|
if !tcx.features().default_alloc_error_handler {
|
||||||
tcx.sess.err("`#[alloc_error_handler]` function required, but not found");
|
tcx.sess.emit_err(MissingAllocErrorHandler);
|
||||||
tcx.sess.note_without_error("use `#![feature(default_alloc_error_handler)]` for a default error handler");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tcx
|
tcx.sess.emit_err(MissingLangItem { name: *name });
|
||||||
.sess
|
|
||||||
.diagnostic()
|
|
||||||
.struct_err(&format!("language item required, but not found: `{}`", name))
|
|
||||||
.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))
|
|
||||||
.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))
|
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue