rust/crates/hir/src/diagnostics.rs

255 lines
5.9 KiB
Rust
Raw Normal View History

2021-05-22 08:53:47 -05:00
//! 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, diagnostics should
2021-05-22 08:53:47 -05:00
//! be expressed in terms of hir types themselves.
2023-01-20 16:09:35 -06:00
pub use hir_ty::diagnostics::{IncoherentImpl, IncorrectCase};
use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_def::path::ModPath;
2021-06-12 11:28:19 -05:00
use hir_expand::{name::Name, HirFileId, InFile};
use syntax::{ast, AstPtr, SyntaxError, SyntaxNodePtr, TextRange};
use crate::{AssocItem, Field, Local, MacroKind, Type};
macro_rules! diagnostics {
($($diag:ident,)*) => {
2022-07-28 13:08:20 -05:00
#[derive(Debug)]
pub enum AnyDiagnostic {$(
$diag(Box<$diag>),
)*}
$(
impl From<$diag> for AnyDiagnostic {
fn from(d: $diag) -> AnyDiagnostic {
AnyDiagnostic::$diag(Box::new(d))
}
}
)*
};
}
diagnostics![
BreakOutsideOfLoop,
ExpectedFunction,
InactiveCode,
IncorrectCase,
InvalidDeriveTarget,
2023-01-20 16:09:35 -06:00
IncoherentImpl,
MacroDefError,
MacroError,
MacroExpansionParseError,
MalformedDerive,
MismatchedArgCount,
MissingFields,
MissingMatchArms,
MissingUnsafe,
NeedMut,
NoSuchField,
2023-01-01 06:24:48 -06:00
PrivateAssocItem,
2022-12-31 07:20:59 -06:00
PrivateField,
2021-06-13 12:32:54 -05:00
ReplaceFilterMapNextWithFindMap,
2022-03-20 10:26:48 -05:00
TypeMismatch,
UndeclaredLabel,
UnimplementedBuiltinMacro,
UnreachableLabel,
UnresolvedExternCrate,
2023-03-03 12:32:18 -06:00
UnresolvedField,
UnresolvedImport,
UnresolvedMacroCall,
2023-03-03 13:41:17 -06:00
UnresolvedMethodCall,
UnresolvedModule,
UnresolvedProcMacro,
UnusedMut,
];
#[derive(Debug)]
pub struct BreakOutsideOfLoop {
pub expr: InFile<AstPtr<ast::Expr>>,
pub is_break: bool,
pub bad_value_break: bool,
}
#[derive(Debug)]
pub struct UnresolvedModule {
pub decl: InFile<AstPtr<ast::Module>>,
pub candidates: Box<[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 {
2022-04-27 13:03:57 -05:00
pub macro_call: InFile<SyntaxNodePtr>,
pub precise_location: Option<TextRange>,
pub path: ModPath,
2022-04-27 13:03:57 -05:00
pub is_bang: bool,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct UnreachableLabel {
pub node: InFile<AstPtr<ast::Lifetime>>,
pub name: Name,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct UndeclaredLabel {
pub node: InFile<AstPtr<ast::Lifetime>>,
pub name: Name,
}
#[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>,
pub kind: MacroKind,
/// The crate id of the proc-macro this macro belongs to, or `None` if the proc-macro can't be found.
pub krate: CrateId,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct MacroError {
2021-06-13 10:41:04 -05:00
pub node: InFile<SyntaxNodePtr>,
pub precise_location: Option<TextRange>,
pub message: String,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct MacroExpansionParseError {
pub node: InFile<SyntaxNodePtr>,
pub precise_location: Option<TextRange>,
pub errors: Box<[SyntaxError]>,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct MacroDefError {
pub node: InFile<AstPtr<ast::Macro>>,
pub message: String,
pub name: Option<TextRange>,
}
2021-05-29 21:19:47 -05:00
#[derive(Debug)]
pub struct UnimplementedBuiltinMacro {
pub node: InFile<SyntaxNodePtr>,
2021-05-29 21:19:47 -05:00
}
#[derive(Debug)]
pub struct InvalidDeriveTarget {
pub node: InFile<SyntaxNodePtr>,
}
#[derive(Debug)]
pub struct MalformedDerive {
pub node: InFile<SyntaxNodePtr>,
}
#[derive(Debug)]
pub struct NoSuchField {
pub field: InFile<AstPtr<ast::RecordExprField>>,
}
2023-01-01 06:24:48 -06:00
#[derive(Debug)]
pub struct PrivateAssocItem {
pub expr_or_pat:
InFile<Either<AstPtr<ast::Expr>, Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>>>,
pub item: AssocItem,
}
#[derive(Debug)]
pub struct ExpectedFunction {
pub call: InFile<AstPtr<ast::Expr>>,
pub found: Type,
}
2023-03-03 12:32:18 -06:00
#[derive(Debug)]
pub struct UnresolvedField {
pub expr: InFile<AstPtr<ast::Expr>>,
pub receiver: Type,
pub name: Name,
pub method_with_same_name_exists: bool,
}
2023-03-03 13:41:17 -06:00
#[derive(Debug)]
pub struct UnresolvedMethodCall {
pub expr: InFile<AstPtr<ast::Expr>>,
pub receiver: Type,
pub name: Name,
pub field_with_same_name: Option<Type>,
}
2022-12-31 07:20:59 -06:00
#[derive(Debug)]
pub struct PrivateField {
pub expr: InFile<AstPtr<ast::Expr>>,
pub field: Field,
}
#[derive(Debug)]
pub struct MissingUnsafe {
pub expr: InFile<AstPtr<ast::Expr>>,
}
2021-06-12 11:28:19 -05:00
#[derive(Debug)]
pub struct MissingFields {
pub file: HirFileId,
pub field_list_parent: Either<AstPtr<ast::RecordExpr>, AstPtr<ast::RecordPat>>,
2021-06-12 11:28:19 -05:00
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>>,
2021-06-12 11:28:19 -05:00
pub expected: usize,
pub found: usize,
}
#[derive(Debug)]
pub struct MissingMatchArms {
pub scrutinee_expr: InFile<AstPtr<ast::Expr>>,
pub uncovered_patterns: String,
2021-06-12 11:28:19 -05:00
}
2021-08-08 03:12:40 -05:00
#[derive(Debug)]
2022-03-20 10:26:48 -05:00
pub struct TypeMismatch {
2023-02-28 08:13:45 -06:00
pub expr_or_pat: Either<InFile<AstPtr<ast::Expr>>, InFile<AstPtr<ast::Pat>>>,
2022-03-20 10:26:48 -05:00
pub expected: Type,
pub actual: Type,
2021-08-08 03:12:40 -05:00
}
#[derive(Debug)]
pub struct NeedMut {
pub local: Local,
pub span: InFile<SyntaxNodePtr>,
}
#[derive(Debug)]
pub struct UnusedMut {
pub local: Local,
}