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