//! 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}; use crate::Type; 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, InvalidDeriveTarget, MacroError, MalformedDerive, MismatchedArgCount, MissingFields, MissingMatchArms, MissingUnsafe, NoSuchField, ReplaceFilterMapNextWithFindMap, TypeMismatch, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, ]; #[derive(Debug)] pub struct UnresolvedModule { pub decl: InFile>, pub candidates: Box<[String]>, } #[derive(Debug)] pub struct UnresolvedExternCrate { pub decl: InFile>, } #[derive(Debug)] pub struct UnresolvedImport { pub decl: InFile>, } #[derive(Debug, Clone, Eq, PartialEq)] pub struct UnresolvedMacroCall { pub macro_call: InFile>, pub path: ModPath, } #[derive(Debug, Clone, Eq, PartialEq)] pub struct InactiveCode { pub node: InFile, pub cfg: CfgExpr, pub opts: CfgOptions, } #[derive(Debug, Clone, Eq, PartialEq)] pub struct UnresolvedProcMacro { pub node: InFile, /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange` /// to use instead. pub precise_location: Option, pub macro_name: Option, } #[derive(Debug, Clone, Eq, PartialEq)] pub struct MacroError { pub node: InFile, pub message: String, } #[derive(Debug)] pub struct UnimplementedBuiltinMacro { pub node: InFile, } #[derive(Debug)] pub struct InvalidDeriveTarget { pub node: InFile, } #[derive(Debug)] pub struct MalformedDerive { pub node: InFile, } #[derive(Debug)] pub struct NoSuchField { pub field: InFile>, } #[derive(Debug)] pub struct BreakOutsideOfLoop { pub expr: InFile>, } #[derive(Debug)] pub struct MissingUnsafe { pub expr: InFile>, } #[derive(Debug)] pub struct MissingFields { pub file: HirFileId, pub field_list_parent: Either, AstPtr>, pub field_list_parent_path: Option>, pub missed_fields: Vec, } #[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, } #[derive(Debug)] pub struct MismatchedArgCount { pub call_expr: InFile>, pub expected: usize, pub found: usize, } #[derive(Debug)] pub struct MissingMatchArms { pub file: HirFileId, pub match_expr: AstPtr, } #[derive(Debug)] pub struct TypeMismatch { // FIXME: add mismatches in patterns as well pub expr: InFile>, pub expected: Type, pub actual: Type, } pub use hir_ty::diagnostics::IncorrectCase;