]> git.lizzy.rs Git - rust.git/blob - crates/hir/src/diagnostics.rs
internal: kill diagnostic sink
[rust.git] / crates / hir / src / diagnostics.rs
1 //! Re-export diagnostics such that clients of `hir` don't have to depend on
2 //! low-level crates.
3 //!
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};
7 use either::Either;
8 use hir_def::path::ModPath;
9 use hir_expand::{name::Name, HirFileId, InFile};
10 use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
11
12 macro_rules! diagnostics {
13     ($($diag:ident,)*) => {
14         pub enum AnyDiagnostic {$(
15             $diag(Box<$diag>),
16         )*}
17
18         $(
19             impl From<$diag> for AnyDiagnostic {
20                 fn from(d: $diag) -> AnyDiagnostic {
21                     AnyDiagnostic::$diag(Box::new(d))
22                 }
23             }
24         )*
25     };
26 }
27
28 diagnostics![
29     BreakOutsideOfLoop,
30     InactiveCode,
31     IncorrectCase,
32     MacroError,
33     MismatchedArgCount,
34     MissingFields,
35     MissingMatchArms,
36     MissingOkOrSomeInTailExpr,
37     MissingUnsafe,
38     NoSuchField,
39     RemoveThisSemicolon,
40     ReplaceFilterMapNextWithFindMap,
41     UnimplementedBuiltinMacro,
42     UnresolvedExternCrate,
43     UnresolvedImport,
44     UnresolvedMacroCall,
45     UnresolvedModule,
46     UnresolvedProcMacro,
47 ];
48
49 #[derive(Debug)]
50 pub struct UnresolvedModule {
51     pub decl: InFile<AstPtr<ast::Module>>,
52     pub candidate: String,
53 }
54
55 #[derive(Debug)]
56 pub struct UnresolvedExternCrate {
57     pub decl: InFile<AstPtr<ast::ExternCrate>>,
58 }
59
60 #[derive(Debug)]
61 pub struct UnresolvedImport {
62     pub decl: InFile<AstPtr<ast::UseTree>>,
63 }
64
65 #[derive(Debug, Clone, Eq, PartialEq)]
66 pub struct UnresolvedMacroCall {
67     pub macro_call: InFile<AstPtr<ast::MacroCall>>,
68     pub path: ModPath,
69 }
70
71 #[derive(Debug, Clone, Eq, PartialEq)]
72 pub struct InactiveCode {
73     pub node: InFile<SyntaxNodePtr>,
74     pub cfg: CfgExpr,
75     pub opts: CfgOptions,
76 }
77
78 #[derive(Debug, Clone, Eq, PartialEq)]
79 pub struct UnresolvedProcMacro {
80     pub node: InFile<SyntaxNodePtr>,
81     /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange`
82     /// to use instead.
83     pub precise_location: Option<TextRange>,
84     pub macro_name: Option<String>,
85 }
86
87 #[derive(Debug, Clone, Eq, PartialEq)]
88 pub struct MacroError {
89     pub node: InFile<SyntaxNodePtr>,
90     pub message: String,
91 }
92
93 #[derive(Debug)]
94 pub struct UnimplementedBuiltinMacro {
95     pub node: InFile<SyntaxNodePtr>,
96 }
97
98 #[derive(Debug)]
99 pub struct NoSuchField {
100     pub field: InFile<AstPtr<ast::RecordExprField>>,
101 }
102
103 #[derive(Debug)]
104 pub struct BreakOutsideOfLoop {
105     pub expr: InFile<AstPtr<ast::Expr>>,
106 }
107
108 #[derive(Debug)]
109 pub struct MissingUnsafe {
110     pub expr: InFile<AstPtr<ast::Expr>>,
111 }
112
113 #[derive(Debug)]
114 pub struct MissingFields {
115     pub file: HirFileId,
116     pub field_list_parent: Either<AstPtr<ast::RecordExpr>, AstPtr<ast::RecordPat>>,
117     pub field_list_parent_path: Option<AstPtr<ast::Path>>,
118     pub missed_fields: Vec<Name>,
119 }
120
121 #[derive(Debug)]
122 pub struct ReplaceFilterMapNextWithFindMap {
123     pub file: HirFileId,
124     /// This expression is the whole method chain up to and including `.filter_map(..).next()`.
125     pub next_expr: AstPtr<ast::Expr>,
126 }
127
128 #[derive(Debug)]
129 pub struct MismatchedArgCount {
130     pub call_expr: InFile<AstPtr<ast::Expr>>,
131     pub expected: usize,
132     pub found: usize,
133 }
134
135 #[derive(Debug)]
136 pub struct RemoveThisSemicolon {
137     pub expr: InFile<AstPtr<ast::Expr>>,
138 }
139
140 #[derive(Debug)]
141 pub struct MissingOkOrSomeInTailExpr {
142     pub expr: InFile<AstPtr<ast::Expr>>,
143     // `Some` or `Ok` depending on whether the return type is Result or Option
144     pub required: String,
145 }
146
147 #[derive(Debug)]
148 pub struct MissingMatchArms {
149     pub file: HirFileId,
150     pub match_expr: AstPtr<ast::Expr>,
151     pub arms: AstPtr<ast::MatchArmList>,
152 }
153
154 pub use hir_ty::diagnostics::IncorrectCase;