allow non-monomorphize modules to access hard-coded error message through new struct, use fluent message in monomorphize

This commit is contained in:
Nathan Stocks
2022-08-24 16:28:56 -06:00
parent e9142473df
commit 30c7506655
8 changed files with 29 additions and 13 deletions

View File

@@ -8,6 +8,7 @@
//! * Functions called by the compiler itself.
use crate::def_id::DefId;
use crate::errors::LangItemError;
use crate::{MethodKind, Target};
use rustc_ast as ast;
@@ -115,9 +116,9 @@ macro_rules! language_item_table {
/// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
/// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
/// returns an error message as a string.
pub fn require(&self, it: LangItem) -> Result<DefId, String> {
self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
/// returns an error encapsulating the `LangItem`.
pub fn require(&self, it: LangItem) -> Result<DefId, LangItemError> {
self.items[it as usize].ok_or_else(|| LangItemError(it))
}
/// Returns the [`DefId`]s of all lang items in a group.