Report syntax errors from item level macro expansions

This commit is contained in:
Lukas Wirth 2023-04-16 17:22:06 +02:00
parent 71b50f9f09
commit d1632c2727
11 changed files with 147 additions and 76 deletions

View file

@ -10,7 +10,7 @@ use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_def::path::ModPath;
use hir_expand::{name::Name, HirFileId, InFile};
use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
use syntax::{ast, AstPtr, SyntaxError, SyntaxNodePtr, TextRange};
use crate::{AssocItem, Field, Local, MacroKind, Type};
@ -38,8 +38,9 @@ diagnostics![
IncorrectCase,
InvalidDeriveTarget,
IncoherentImpl,
MacroError,
MacroDefError,
MacroError,
MacroExpansionParseError,
MalformedDerive,
MismatchedArgCount,
MissingFields,
@ -132,6 +133,13 @@ pub struct MacroError {
pub message: String,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct MacroExpansionParseError {
pub node: InFile<SyntaxNodePtr>,
pub precise_location: Option<TextRange>,
pub errors: Box<[SyntaxError]>,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct MacroDefError {
pub node: InFile<AstPtr<ast::Macro>>,