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.
6 use cfg::{CfgExpr, CfgOptions};
8 use hir_def::{path::ModPath, type_ref::Mutability};
9 use hir_expand::{name::Name, HirFileId, InFile};
10 use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
14 macro_rules! diagnostics {
15 ($($diag:ident,)*) => {
16 pub enum AnyDiagnostic {$(
21 impl From<$diag> for AnyDiagnostic {
22 fn from(d: $diag) -> AnyDiagnostic {
23 AnyDiagnostic::$diag(Box::new(d))
41 MissingOkOrSomeInTailExpr,
45 ReplaceFilterMapNextWithFindMap,
46 UnimplementedBuiltinMacro,
47 UnresolvedExternCrate,
55 pub struct UnresolvedModule {
56 pub decl: InFile<AstPtr<ast::Module>>,
57 pub candidate: 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<AstPtr<ast::MacroCall>>,
76 #[derive(Debug, Clone, Eq, PartialEq)]
77 pub struct InactiveCode {
78 pub node: InFile<SyntaxNodePtr>,
83 #[derive(Debug, Clone, Eq, PartialEq)]
84 pub struct UnresolvedProcMacro {
85 pub node: InFile<SyntaxNodePtr>,
86 /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange`
88 pub precise_location: Option<TextRange>,
89 pub macro_name: Option<String>,
92 #[derive(Debug, Clone, Eq, PartialEq)]
93 pub struct MacroError {
94 pub node: InFile<SyntaxNodePtr>,
99 pub struct UnimplementedBuiltinMacro {
100 pub node: InFile<SyntaxNodePtr>,
104 pub struct InvalidDeriveTarget {
105 pub node: InFile<SyntaxNodePtr>,
109 pub struct MalformedDerive {
110 pub node: InFile<SyntaxNodePtr>,
114 pub struct NoSuchField {
115 pub field: InFile<AstPtr<ast::RecordExprField>>,
119 pub struct BreakOutsideOfLoop {
120 pub expr: InFile<AstPtr<ast::Expr>>,
124 pub struct MissingUnsafe {
125 pub expr: InFile<AstPtr<ast::Expr>>,
129 pub struct MissingFields {
131 pub field_list_parent: Either<AstPtr<ast::RecordExpr>, AstPtr<ast::RecordPat>>,
132 pub field_list_parent_path: Option<AstPtr<ast::Path>>,
133 pub missed_fields: Vec<Name>,
137 pub struct ReplaceFilterMapNextWithFindMap {
139 /// This expression is the whole method chain up to and including `.filter_map(..).next()`.
140 pub next_expr: AstPtr<ast::Expr>,
144 pub struct MismatchedArgCount {
145 pub call_expr: InFile<AstPtr<ast::Expr>>,
151 pub struct RemoveThisSemicolon {
152 pub expr: InFile<AstPtr<ast::Expr>>,
156 pub struct MissingOkOrSomeInTailExpr {
157 pub expr: InFile<AstPtr<ast::Expr>>,
158 // `Some` or `Ok` depending on whether the return type is Result or Option
159 pub required: String,
164 pub struct MissingMatchArms {
166 pub match_expr: AstPtr<ast::Expr>,
167 pub arms: AstPtr<ast::MatchArmList>,
171 pub struct AddReferenceHere {
172 pub expr: InFile<AstPtr<ast::Expr>>,
173 pub mutability: Mutability,
176 pub use hir_ty::diagnostics::IncorrectCase;