mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Split macro-error
diagnostic so users can ignore only parts of it
Split it into `macro-error`, `proc-macros-disabled` and `proc-macro-disabled`.
This commit is contained in:
parent
6a67a4d3cd
commit
f4585ea023
5 changed files with 77 additions and 34 deletions
|
@ -165,40 +165,73 @@ pub enum ExpandErrorKind {
|
|||
}
|
||||
|
||||
impl ExpandError {
|
||||
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> (String, bool) {
|
||||
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError {
|
||||
self.inner.0.render_to_string(db)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RenderedExpandError {
|
||||
pub message: String,
|
||||
pub error: bool,
|
||||
pub kind: &'static str,
|
||||
}
|
||||
|
||||
impl RenderedExpandError {
|
||||
const GENERAL_KIND: &str = "macro-error";
|
||||
}
|
||||
|
||||
impl ExpandErrorKind {
|
||||
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> (String, bool) {
|
||||
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError {
|
||||
match self {
|
||||
ExpandErrorKind::ProcMacroAttrExpansionDisabled => {
|
||||
("procedural attribute macro expansion is disabled".to_owned(), false)
|
||||
}
|
||||
ExpandErrorKind::MacroDisabled => {
|
||||
("proc-macro is explicitly disabled".to_owned(), false)
|
||||
}
|
||||
ExpandErrorKind::ProcMacroAttrExpansionDisabled => RenderedExpandError {
|
||||
message: "procedural attribute macro expansion is disabled".to_owned(),
|
||||
error: false,
|
||||
kind: "proc-macros-disabled",
|
||||
},
|
||||
ExpandErrorKind::MacroDisabled => RenderedExpandError {
|
||||
message: "proc-macro is explicitly disabled".to_owned(),
|
||||
error: false,
|
||||
kind: "proc-macro-disabled",
|
||||
},
|
||||
&ExpandErrorKind::MissingProcMacroExpander(def_crate) => {
|
||||
match db.proc_macros().get_error_for_crate(def_crate) {
|
||||
Some((e, hard_err)) => (e.to_owned(), hard_err),
|
||||
None => (
|
||||
format!(
|
||||
"internal error: proc-macro map is missing error entry for crate {def_crate:?}"
|
||||
),
|
||||
true,
|
||||
),
|
||||
Some((e, hard_err)) => RenderedExpandError {
|
||||
message: e.to_owned(),
|
||||
error: hard_err,
|
||||
kind: RenderedExpandError::GENERAL_KIND,
|
||||
},
|
||||
None => RenderedExpandError {
|
||||
message: format!("internal error: proc-macro map is missing error entry for crate {def_crate:?}"),
|
||||
error: true,
|
||||
kind: RenderedExpandError::GENERAL_KIND,
|
||||
},
|
||||
}
|
||||
}
|
||||
ExpandErrorKind::MacroDefinition => {
|
||||
("macro definition has parse errors".to_owned(), true)
|
||||
}
|
||||
ExpandErrorKind::Mbe(e) => (e.to_string(), true),
|
||||
ExpandErrorKind::RecursionOverflow => {
|
||||
("overflow expanding the original macro".to_owned(), true)
|
||||
}
|
||||
ExpandErrorKind::Other(e) => ((**e).to_owned(), true),
|
||||
ExpandErrorKind::ProcMacroPanic(e) => (format!("proc-macro panicked: {e}"), true),
|
||||
ExpandErrorKind::MacroDefinition => RenderedExpandError {
|
||||
message: "macro definition has parse errors".to_owned(),
|
||||
error: true,
|
||||
kind: RenderedExpandError::GENERAL_KIND,
|
||||
},
|
||||
ExpandErrorKind::Mbe(e) => RenderedExpandError {
|
||||
message: e.to_string(),
|
||||
error: true,
|
||||
kind: RenderedExpandError::GENERAL_KIND,
|
||||
},
|
||||
ExpandErrorKind::RecursionOverflow => RenderedExpandError {
|
||||
message: "overflow expanding the original macro".to_owned(),
|
||||
error: true,
|
||||
kind: RenderedExpandError::GENERAL_KIND,
|
||||
},
|
||||
ExpandErrorKind::Other(e) => RenderedExpandError {
|
||||
message: (**e).to_owned(),
|
||||
error: true,
|
||||
kind: RenderedExpandError::GENERAL_KIND,
|
||||
},
|
||||
ExpandErrorKind::ProcMacroPanic(e) => RenderedExpandError {
|
||||
message: format!("proc-macro panicked: {e}"),
|
||||
error: true,
|
||||
kind: RenderedExpandError::GENERAL_KIND,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue