Rollup merge of #100730 - CleanCut:diagnostics-rustc_monomorphize, r=davidtwco
Migrate rustc_monomorphize to use SessionDiagnostic ### Description - Migrates diagnostics in `rustc_monomorphize` to use `SessionDiagnostic` - Adds an `impl IntoDiagnosticArg for PathBuf` ### TODO / Help! - [x] I'm having trouble figuring out how to apply an optional note. 😕 Help!? - Resolved. It was bad docs. Fixed in https://github.com/rust-lang/rustc-dev-guide/pull/1437/files - [x] `errors:RecursionLimit` should be `#[fatal ...]`, but that doesn't exist so it's `#[error ...]` at the moment. - Maybe I can switch after this is merged in? --> https://github.com/rust-lang/rust/pull/100694 - Or maybe I need to manually implement `SessionDiagnostic` instead of deriving it? - [x] How does one go about converting an error inside of [a call to struct_span_lint_hir](8064a49508/compiler/rustc_monomorphize/src/collector.rs (L917-L927)
)? - [x] ~What placeholder do you use in the fluent template to refer to the value in a vector? It seems like [this code](0b79f758c9/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs (L83-L114)
) ought to have the answer (or something near it)...but I can't figure it out.~ You can't. Punted.
This commit is contained in:
commit
6c4bda6de4
16 changed files with 196 additions and 52 deletions
10
compiler/rustc_hir/src/errors.rs
Normal file
10
compiler/rustc_hir/src/errors.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use crate::LangItem;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
|
||||
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