Merge pull request #18674 from Veykril/push-lrxotqknvxvr

Show expansion errors in expand_macro feature
This commit is contained in:
Lukas Wirth 2024-12-13 08:50:45 +00:00 committed by GitHub
commit 6aadbae022
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 76 additions and 37 deletions

View file

@ -28,6 +28,7 @@ use rustc_hash::FxHashMap;
use stdx::TupleExt;
use triomphe::Arc;
use core::fmt;
use std::hash::Hash;
use base_db::{ra_salsa::InternValueTrivial, CrateId};
@ -147,6 +148,10 @@ impl ExpandError {
pub fn span(&self) -> Span {
self.inner.1
}
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError {
self.inner.0.render_to_string(db)
}
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
@ -164,18 +169,18 @@ pub enum ExpandErrorKind {
ProcMacroPanic(Box<str>),
}
impl ExpandError {
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 fmt::Display for RenderedExpandError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl RenderedExpandError {
const GENERAL_KIND: &str = "macro-error";
}