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, diagnostics should 5 //! be expressed in terms of hir types themselves. 6 pub use hir_ty::diagnostics::{IncoherentImpl, IncorrectCase}; 7 8 use base_db::CrateId; 9 use cfg::{CfgExpr, CfgOptions}; 10 use either::Either; 11 use hir_def::path::ModPath; 12 use hir_expand::{name::Name, HirFileId, InFile}; 13 use syntax::{ast, AstPtr, SyntaxError, SyntaxNodePtr, TextRange}; 14 15 use crate::{AssocItem, Field, Local, MacroKind, Type}; 16 17 macro_rules! diagnostics { 18 ($($diag:ident,)*) => { 19 #[derive(Debug)] 20 pub enum AnyDiagnostic {$( 21 $diag(Box<$diag>), 22 )*} 23 24 $( 25 impl From<$diag> for AnyDiagnostic { 26 fn from(d: $diag) -> AnyDiagnostic { 27 AnyDiagnostic::$diag(Box::new(d)) 28 } 29 } 30 )* 31 }; 32 } 33 34 diagnostics![ 35 BreakOutsideOfLoop, 36 ExpectedFunction, 37 InactiveCode, 38 IncorrectCase, 39 InvalidDeriveTarget, 40 IncoherentImpl, 41 MacroDefError, 42 MacroError, 43 MacroExpansionParseError, 44 MalformedDerive, 45 MismatchedArgCount, 46 MissingFields, 47 MissingMatchArms, 48 MissingUnsafe, 49 MovedOutOfRef, 50 NeedMut, 51 NoSuchField, 52 PrivateAssocItem, 53 PrivateField, 54 ReplaceFilterMapNextWithFindMap, 55 TypedHole, 56 TypeMismatch, 57 UndeclaredLabel, 58 UnimplementedBuiltinMacro, 59 UnreachableLabel, 60 UnresolvedExternCrate, 61 UnresolvedField, 62 UnresolvedImport, 63 UnresolvedMacroCall, 64 UnresolvedMethodCall, 65 UnresolvedModule, 66 UnresolvedProcMacro, 67 UnusedMut, 68 ]; 69 70 #[derive(Debug)] 71 pub struct BreakOutsideOfLoop { 72 pub expr: InFile<AstPtr<ast::Expr>>, 73 pub is_break: bool, 74 pub bad_value_break: bool, 75 } 76 77 #[derive(Debug)] 78 pub struct TypedHole { 79 pub expr: InFile<AstPtr<ast::Expr>>, 80 pub expected: Type, 81 } 82 83 #[derive(Debug)] 84 pub struct UnresolvedModule { 85 pub decl: InFile<AstPtr<ast::Module>>, 86 pub candidates: Box<[String]>, 87 } 88 89 #[derive(Debug)] 90 pub struct UnresolvedExternCrate { 91 pub decl: InFile<AstPtr<ast::ExternCrate>>, 92 } 93 94 #[derive(Debug)] 95 pub struct UnresolvedImport { 96 pub decl: InFile<AstPtr<ast::UseTree>>, 97 } 98 99 #[derive(Debug, Clone, Eq, PartialEq)] 100 pub struct UnresolvedMacroCall { 101 pub macro_call: InFile<SyntaxNodePtr>, 102 pub precise_location: Option<TextRange>, 103 pub path: ModPath, 104 pub is_bang: bool, 105 } 106 #[derive(Debug, Clone, Eq, PartialEq)] 107 pub struct UnreachableLabel { 108 pub node: InFile<AstPtr<ast::Lifetime>>, 109 pub name: Name, 110 } 111 112 #[derive(Debug, Clone, Eq, PartialEq)] 113 pub struct UndeclaredLabel { 114 pub node: InFile<AstPtr<ast::Lifetime>>, 115 pub name: Name, 116 } 117 118 #[derive(Debug, Clone, Eq, PartialEq)] 119 pub struct InactiveCode { 120 pub node: InFile<SyntaxNodePtr>, 121 pub cfg: CfgExpr, 122 pub opts: CfgOptions, 123 } 124 125 #[derive(Debug, Clone, Eq, PartialEq)] 126 pub struct UnresolvedProcMacro { 127 pub node: InFile<SyntaxNodePtr>, 128 /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange` 129 /// to use instead. 130 pub precise_location: Option<TextRange>, 131 pub macro_name: Option<String>, 132 pub kind: MacroKind, 133 /// The crate id of the proc-macro this macro belongs to, or `None` if the proc-macro can't be found. 134 pub krate: CrateId, 135 } 136 137 #[derive(Debug, Clone, Eq, PartialEq)] 138 pub struct MacroError { 139 pub node: InFile<SyntaxNodePtr>, 140 pub precise_location: Option<TextRange>, 141 pub message: String, 142 } 143 144 #[derive(Debug, Clone, Eq, PartialEq)] 145 pub struct MacroExpansionParseError { 146 pub node: InFile<SyntaxNodePtr>, 147 pub precise_location: Option<TextRange>, 148 pub errors: Box<[SyntaxError]>, 149 } 150 151 #[derive(Debug, Clone, Eq, PartialEq)] 152 pub struct MacroDefError { 153 pub node: InFile<AstPtr<ast::Macro>>, 154 pub message: String, 155 pub name: Option<TextRange>, 156 } 157 158 #[derive(Debug)] 159 pub struct UnimplementedBuiltinMacro { 160 pub node: InFile<SyntaxNodePtr>, 161 } 162 163 #[derive(Debug)] 164 pub struct InvalidDeriveTarget { 165 pub node: InFile<SyntaxNodePtr>, 166 } 167 168 #[derive(Debug)] 169 pub struct MalformedDerive { 170 pub node: InFile<SyntaxNodePtr>, 171 } 172 173 #[derive(Debug)] 174 pub struct NoSuchField { 175 pub field: InFile<AstPtr<ast::RecordExprField>>, 176 } 177 178 #[derive(Debug)] 179 pub struct PrivateAssocItem { 180 pub expr_or_pat: 181 InFile<Either<AstPtr<ast::Expr>, Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>>>, 182 pub item: AssocItem, 183 } 184 185 #[derive(Debug)] 186 pub struct ExpectedFunction { 187 pub call: InFile<AstPtr<ast::Expr>>, 188 pub found: Type, 189 } 190 191 #[derive(Debug)] 192 pub struct UnresolvedField { 193 pub expr: InFile<AstPtr<ast::Expr>>, 194 pub receiver: Type, 195 pub name: Name, 196 pub method_with_same_name_exists: bool, 197 } 198 199 #[derive(Debug)] 200 pub struct UnresolvedMethodCall { 201 pub expr: InFile<AstPtr<ast::Expr>>, 202 pub receiver: Type, 203 pub name: Name, 204 pub field_with_same_name: Option<Type>, 205 } 206 207 #[derive(Debug)] 208 pub struct PrivateField { 209 pub expr: InFile<AstPtr<ast::Expr>>, 210 pub field: Field, 211 } 212 213 #[derive(Debug)] 214 pub struct MissingUnsafe { 215 pub expr: InFile<AstPtr<ast::Expr>>, 216 } 217 218 #[derive(Debug)] 219 pub struct MissingFields { 220 pub file: HirFileId, 221 pub field_list_parent: Either<AstPtr<ast::RecordExpr>, AstPtr<ast::RecordPat>>, 222 pub field_list_parent_path: Option<AstPtr<ast::Path>>, 223 pub missed_fields: Vec<Name>, 224 } 225 226 #[derive(Debug)] 227 pub struct ReplaceFilterMapNextWithFindMap { 228 pub file: HirFileId, 229 /// This expression is the whole method chain up to and including `.filter_map(..).next()`. 230 pub next_expr: AstPtr<ast::Expr>, 231 } 232 233 #[derive(Debug)] 234 pub struct MismatchedArgCount { 235 pub call_expr: InFile<AstPtr<ast::Expr>>, 236 pub expected: usize, 237 pub found: usize, 238 } 239 240 #[derive(Debug)] 241 pub struct MissingMatchArms { 242 pub scrutinee_expr: InFile<AstPtr<ast::Expr>>, 243 pub uncovered_patterns: String, 244 } 245 246 #[derive(Debug)] 247 pub struct TypeMismatch { 248 pub expr_or_pat: Either<InFile<AstPtr<ast::Expr>>, InFile<AstPtr<ast::Pat>>>, 249 pub expected: Type, 250 pub actual: Type, 251 } 252 253 #[derive(Debug)] 254 pub struct NeedMut { 255 pub local: Local, 256 pub span: InFile<SyntaxNodePtr>, 257 } 258 259 #[derive(Debug)] 260 pub struct UnusedMut { 261 pub local: Local, 262 } 263 264 #[derive(Debug)] 265 pub struct MovedOutOfRef { 266 pub ty: Type, 267 pub span: InFile<SyntaxNodePtr>, 268 } 269