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))
39 MissingOkOrSomeInTailExpr,
43 ReplaceFilterMapNextWithFindMap,
44 UnimplementedBuiltinMacro,
45 UnresolvedExternCrate,
53 pub struct UnresolvedModule {
54 pub decl: InFile<AstPtr<ast::Module>>,
55 pub candidate: String,
59 pub struct UnresolvedExternCrate {
60 pub decl: InFile<AstPtr<ast::ExternCrate>>,
64 pub struct UnresolvedImport {
65 pub decl: InFile<AstPtr<ast::UseTree>>,
68 #[derive(Debug, Clone, Eq, PartialEq)]
69 pub struct UnresolvedMacroCall {
70 pub macro_call: InFile<AstPtr<ast::MacroCall>>,
74 #[derive(Debug, Clone, Eq, PartialEq)]
75 pub struct InactiveCode {
76 pub node: InFile<SyntaxNodePtr>,
81 #[derive(Debug, Clone, Eq, PartialEq)]
82 pub struct UnresolvedProcMacro {
83 pub node: InFile<SyntaxNodePtr>,
84 /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange`
86 pub precise_location: Option<TextRange>,
87 pub macro_name: Option<String>,
90 #[derive(Debug, Clone, Eq, PartialEq)]
91 pub struct MacroError {
92 pub node: InFile<SyntaxNodePtr>,
97 pub struct UnimplementedBuiltinMacro {
98 pub node: InFile<SyntaxNodePtr>,
102 pub struct NoSuchField {
103 pub field: InFile<AstPtr<ast::RecordExprField>>,
107 pub struct BreakOutsideOfLoop {
108 pub expr: InFile<AstPtr<ast::Expr>>,
112 pub struct MissingUnsafe {
113 pub expr: InFile<AstPtr<ast::Expr>>,
117 pub struct MissingFields {
119 pub field_list_parent: Either<AstPtr<ast::RecordExpr>, AstPtr<ast::RecordPat>>,
120 pub field_list_parent_path: Option<AstPtr<ast::Path>>,
121 pub missed_fields: Vec<Name>,
125 pub struct ReplaceFilterMapNextWithFindMap {
127 /// This expression is the whole method chain up to and including `.filter_map(..).next()`.
128 pub next_expr: AstPtr<ast::Expr>,
132 pub struct MismatchedArgCount {
133 pub call_expr: InFile<AstPtr<ast::Expr>>,
139 pub struct RemoveThisSemicolon {
140 pub expr: InFile<AstPtr<ast::Expr>>,
144 pub struct MissingOkOrSomeInTailExpr {
145 pub expr: InFile<AstPtr<ast::Expr>>,
146 // `Some` or `Ok` depending on whether the return type is Result or Option
147 pub required: String,
152 pub struct MissingMatchArms {
154 pub match_expr: AstPtr<ast::Expr>,
155 pub arms: AstPtr<ast::MatchArmList>,
159 pub struct AddReferenceHere {
160 pub expr: InFile<AstPtr<ast::Expr>>,
161 pub mutability: Mutability,
164 pub use hir_ty::diagnostics::IncorrectCase;