Restructure proc-macro loading erros, differentiate hard error property on kind

This commit is contained in:
Lukas Wirth 2025-07-03 09:28:53 +02:00
parent 7c3de9df36
commit e54759083a
11 changed files with 105 additions and 63 deletions

View file

@ -199,9 +199,9 @@ impl ExpandErrorKind {
},
&ExpandErrorKind::MissingProcMacroExpander(def_crate) => {
match db.proc_macros_for_crate(def_crate).as_ref().and_then(|it| it.get_error()) {
Some((e, hard_err)) => RenderedExpandError {
message: e.to_owned(),
error: hard_err,
Some(e) => RenderedExpandError {
message: e.to_string(),
error: e.is_hard_error(),
kind: RenderedExpandError::GENERAL_KIND,
},
None => RenderedExpandError {

View file

@ -46,7 +46,7 @@ pub fn prettify_macro_expansion(
} else if let Some(crate_name) = &macro_def_crate.extra_data(db).display_name {
make::tokens::ident(crate_name.crate_name().as_str())
} else {
return dollar_crate.clone();
dollar_crate.clone()
}
});
if replacement.text() == "$crate" {

View file

@ -4,7 +4,7 @@ use core::fmt;
use std::any::Any;
use std::{panic::RefUnwindSafe, sync};
use base_db::{Crate, CrateBuilderId, CratesIdMap, Env};
use base_db::{Crate, CrateBuilderId, CratesIdMap, Env, ProcMacroLoadingError};
use intern::Symbol;
use rustc_hash::FxHashMap;
use span::Span;
@ -53,8 +53,8 @@ pub enum ProcMacroExpansionError {
System(String),
}
pub type ProcMacroLoadResult = Result<Vec<ProcMacro>, (String, bool)>;
type StoredProcMacroLoadResult = Result<Box<[ProcMacro]>, (Box<str>, bool)>;
pub type ProcMacroLoadResult = Result<Vec<ProcMacro>, ProcMacroLoadingError>;
type StoredProcMacroLoadResult = Result<Box<[ProcMacro]>, ProcMacroLoadingError>;
#[derive(Default, Debug)]
pub struct ProcMacrosBuilder(FxHashMap<CrateBuilderId, Arc<CrateProcMacros>>);
@ -77,9 +77,7 @@ impl ProcMacrosBuilder {
proc_macros_crate,
match proc_macro {
Ok(it) => Arc::new(CrateProcMacros(Ok(it.into_boxed_slice()))),
Err((e, hard_err)) => {
Arc::new(CrateProcMacros(Err((e.into_boxed_str(), hard_err))))
}
Err(e) => Arc::new(CrateProcMacros(Err(e))),
},
);
}
@ -139,8 +137,8 @@ impl CrateProcMacros {
)
}
pub fn get_error(&self) -> Option<(&str, bool)> {
self.0.as_ref().err().map(|(e, hard_err)| (&**e, *hard_err))
pub fn get_error(&self) -> Option<&ProcMacroLoadingError> {
self.0.as_ref().err()
}
/// Fetch the [`CustomProcMacroExpander`]s and their corresponding names for the given crate.