mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-19 16:51:42 +00:00
internal: move inference diagnostics to hir
This commit is contained in:
parent
409f5fb563
commit
f8009666be
6 changed files with 222 additions and 244 deletions
|
@ -14,8 +14,7 @@ use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
|
|||
pub use hir_ty::{
|
||||
diagnostics::{
|
||||
IncorrectCase, MismatchedArgCount, MissingFields, MissingMatchArms,
|
||||
MissingOkOrSomeInTailExpr, NoSuchField, RemoveThisSemicolon,
|
||||
ReplaceFilterMapNextWithFindMap,
|
||||
MissingOkOrSomeInTailExpr, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap,
|
||||
},
|
||||
diagnostics_sink::{Diagnostic, DiagnosticCode, DiagnosticSink, DiagnosticSinkBuilder},
|
||||
};
|
||||
|
@ -251,3 +250,54 @@ impl Diagnostic for UnimplementedBuiltinMacro {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
// Diagnostic: no-such-field
|
||||
//
|
||||
// This diagnostic is triggered if created structure does not have field provided in record.
|
||||
#[derive(Debug)]
|
||||
pub struct NoSuchField {
|
||||
pub file: HirFileId,
|
||||
pub field: AstPtr<ast::RecordExprField>,
|
||||
}
|
||||
|
||||
impl Diagnostic for NoSuchField {
|
||||
fn code(&self) -> DiagnosticCode {
|
||||
DiagnosticCode("no-such-field")
|
||||
}
|
||||
|
||||
fn message(&self) -> String {
|
||||
"no such field".to_string()
|
||||
}
|
||||
|
||||
fn display_source(&self) -> InFile<SyntaxNodePtr> {
|
||||
InFile::new(self.file, self.field.clone().into())
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
// Diagnostic: break-outside-of-loop
|
||||
//
|
||||
// This diagnostic is triggered if the `break` keyword is used outside of a loop.
|
||||
#[derive(Debug)]
|
||||
pub struct BreakOutsideOfLoop {
|
||||
pub file: HirFileId,
|
||||
pub expr: AstPtr<ast::Expr>,
|
||||
}
|
||||
|
||||
impl Diagnostic for BreakOutsideOfLoop {
|
||||
fn code(&self) -> DiagnosticCode {
|
||||
DiagnosticCode("break-outside-of-loop")
|
||||
}
|
||||
fn message(&self) -> String {
|
||||
"break outside of loop".to_string()
|
||||
}
|
||||
fn display_source(&self) -> InFile<SyntaxNodePtr> {
|
||||
InFile { file_id: self.file, value: self.expr.clone().into() }
|
||||
}
|
||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue