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;
9 use hir_expand::{name::Name, HirFileId, InFile};
10 use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
12 macro_rules! diagnostics {
13 ($($diag:ident,)*) => {
14 pub enum AnyDiagnostic {$(
19 impl From<$diag> for AnyDiagnostic {
20 fn from(d: $diag) -> AnyDiagnostic {
21 AnyDiagnostic::$diag(Box::new(d))
36 MissingOkOrSomeInTailExpr,
40 ReplaceFilterMapNextWithFindMap,
41 UnimplementedBuiltinMacro,
42 UnresolvedExternCrate,
50 pub struct UnresolvedModule {
51 pub decl: InFile<AstPtr<ast::Module>>,
52 pub candidate: String,
56 pub struct UnresolvedExternCrate {
57 pub decl: InFile<AstPtr<ast::ExternCrate>>,
61 pub struct UnresolvedImport {
62 pub decl: InFile<AstPtr<ast::UseTree>>,
65 #[derive(Debug, Clone, Eq, PartialEq)]
66 pub struct UnresolvedMacroCall {
67 pub macro_call: InFile<AstPtr<ast::MacroCall>>,
71 #[derive(Debug, Clone, Eq, PartialEq)]
72 pub struct InactiveCode {
73 pub node: InFile<SyntaxNodePtr>,
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`
83 pub precise_location: Option<TextRange>,
84 pub macro_name: Option<String>,
87 #[derive(Debug, Clone, Eq, PartialEq)]
88 pub struct MacroError {
89 pub node: InFile<SyntaxNodePtr>,
94 pub struct UnimplementedBuiltinMacro {
95 pub node: InFile<SyntaxNodePtr>,
99 pub struct NoSuchField {
100 pub field: InFile<AstPtr<ast::RecordExprField>>,
104 pub struct BreakOutsideOfLoop {
105 pub expr: InFile<AstPtr<ast::Expr>>,
109 pub struct MissingUnsafe {
110 pub expr: InFile<AstPtr<ast::Expr>>,
114 pub struct MissingFields {
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>,
122 pub struct ReplaceFilterMapNextWithFindMap {
124 /// This expression is the whole method chain up to and including `.filter_map(..).next()`.
125 pub next_expr: AstPtr<ast::Expr>,
129 pub struct MismatchedArgCount {
130 pub call_expr: InFile<AstPtr<ast::Expr>>,
136 pub struct RemoveThisSemicolon {
137 pub expr: InFile<AstPtr<ast::Expr>>,
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,
148 pub struct MissingMatchArms {
150 pub match_expr: AstPtr<ast::Expr>,
151 pub arms: AstPtr<ast::MatchArmList>,
154 pub use hir_ty::diagnostics::IncorrectCase;