allow non-monomorphize modules to access hard-coded error message through new struct, use fluent message in monomorphize
This commit is contained in:
parent
e9142473df
commit
30c7506655
8 changed files with 29 additions and 13 deletions
9
compiler/rustc_hir/src/errors.rs
Normal file
9
compiler/rustc_hir/src/errors.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use crate::LangItem;
|
||||
|
||||
pub struct LangItemError(pub LangItem);
|
||||
|
||||
impl ToString for LangItemError {
|
||||
fn to_string(&self) -> String {
|
||||
format!("requires `{}` lang_item", self.0.name())
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -27,6 +27,7 @@ pub mod def;
|
|||
pub mod def_path_hash_map;
|
||||
pub mod definitions;
|
||||
pub mod diagnostic_items;
|
||||
pub mod errors;
|
||||
pub use rustc_span::def_id;
|
||||
mod hir;
|
||||
pub mod hir_id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue