1 //! Re-export diagnostics such that clients of `hir` don't have to depend on
4 //! This probably isn't the best way to do this -- ideally, diagnistics should
5 //! be expressed in terms of hir types themselves.
7 use cfg::{CfgExpr, CfgOptions};
9 use hir_def::path::ModPath;
10 use hir_expand::{name::Name, HirFileId, InFile};
11 use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
13 use crate::{MacroKind, Type};
15 macro_rules! diagnostics {
16 ($($diag:ident,)*) => {
18 pub enum AnyDiagnostic {$(
23 impl From<$diag> for AnyDiagnostic {
24 fn from(d: $diag) -> AnyDiagnostic {
25 AnyDiagnostic::$diag(Box::new(d))
44 ReplaceFilterMapNextWithFindMap,
46 UnimplementedBuiltinMacro,
47 UnresolvedExternCrate,
55 pub struct UnresolvedModule {
56 pub decl: InFile<AstPtr<ast::Module>>,
57 pub candidates: Box<[String]>,
61 pub struct UnresolvedExternCrate {
62 pub decl: InFile<AstPtr<ast::ExternCrate>>,
66 pub struct UnresolvedImport {
67 pub decl: InFile<AstPtr<ast::UseTree>>,
70 #[derive(Debug, Clone, Eq, PartialEq)]
71 pub struct UnresolvedMacroCall {
72 pub macro_call: InFile<SyntaxNodePtr>,
73 pub precise_location: Option<TextRange>,
78 #[derive(Debug, Clone, Eq, PartialEq)]
79 pub struct InactiveCode {
80 pub node: InFile<SyntaxNodePtr>,
85 #[derive(Debug, Clone, Eq, PartialEq)]
86 pub struct UnresolvedProcMacro {
87 pub node: InFile<SyntaxNodePtr>,
88 /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange`
90 pub precise_location: Option<TextRange>,
91 pub macro_name: Option<String>,
93 /// The crate id of the proc-macro this macro belongs to, or `None` if the proc-macro can't be found.
97 #[derive(Debug, Clone, Eq, PartialEq)]
98 pub struct MacroError {
99 pub node: InFile<SyntaxNodePtr>,
100 pub precise_location: Option<TextRange>,
105 pub struct UnimplementedBuiltinMacro {
106 pub node: InFile<SyntaxNodePtr>,
110 pub struct InvalidDeriveTarget {
111 pub node: InFile<SyntaxNodePtr>,
115 pub struct MalformedDerive {
116 pub node: InFile<SyntaxNodePtr>,
120 pub struct NoSuchField {
121 pub field: InFile<AstPtr<ast::RecordExprField>>,
125 pub struct BreakOutsideOfLoop {
126 pub expr: InFile<AstPtr<ast::Expr>>,
130 pub struct MissingUnsafe {
131 pub expr: InFile<AstPtr<ast::Expr>>,
135 pub struct MissingFields {
137 pub field_list_parent: Either<AstPtr<ast::RecordExpr>, AstPtr<ast::RecordPat>>,
138 pub field_list_parent_path: Option<AstPtr<ast::Path>>,
139 pub missed_fields: Vec<Name>,
143 pub struct ReplaceFilterMapNextWithFindMap {
145 /// This expression is the whole method chain up to and including `.filter_map(..).next()`.
146 pub next_expr: AstPtr<ast::Expr>,
150 pub struct MismatchedArgCount {
151 pub call_expr: InFile<AstPtr<ast::Expr>>,
157 pub struct MissingMatchArms {
159 pub match_expr: AstPtr<ast::Expr>,
160 pub uncovered_patterns: String,
164 pub struct TypeMismatch {
165 // FIXME: add mismatches in patterns as well
166 pub expr: InFile<AstPtr<ast::Expr>>,
171 pub use hir_ty::diagnostics::IncorrectCase;