]> git.lizzy.rs Git - rust.git/commitdiff
Require source implementations for Diagnostic
authorKirill Bulatov <mail4score@gmail.com>
Tue, 28 Jul 2020 07:24:59 +0000 (10:24 +0300)
committerKirill Bulatov <mail4score@gmail.com>
Tue, 11 Aug 2020 12:09:08 +0000 (15:09 +0300)
crates/ra_hir_def/src/diagnostics.rs
crates/ra_hir_expand/src/diagnostics.rs
crates/ra_hir_ty/src/diagnostics.rs

index e532695895e731dba6daafe5b6263c8985d8a7e5..30db48f86828d1820bba8a62b08df4bf08f9eaef 100644 (file)
@@ -18,7 +18,7 @@ impl Diagnostic for UnresolvedModule {
     fn message(&self) -> String {
         "unresolved module".to_string()
     }
-    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+    fn source(&self) -> InFile<SyntaxNodePtr> {
         InFile::new(self.file, self.decl.clone().into())
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
index 23f28a7f71dc5f2a30e3d11b1a8abcd2963fbbc3..90a3b87f96a81b72964b127b0079dcb3e3c14509 100644 (file)
 
 pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
     fn message(&self) -> String;
-    fn fix_source(&self) -> InFile<SyntaxNodePtr>;
-    fn source(&self) -> InFile<SyntaxNodePtr> {
-        self.fix_source()
+    /// A source to be used in highlighting and other visual representations
+    fn source(&self) -> InFile<SyntaxNodePtr>;
+    /// A source to be used during the fix application
+    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+        self.source()
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static);
     fn is_experimental(&self) -> bool {
@@ -39,8 +41,9 @@ pub trait AstDiagnostic {
 
 impl dyn Diagnostic {
     pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode {
-        let node = db.parse_or_expand(self.source().file_id).unwrap();
-        self.source().value.to_node(&node)
+        let source = self.source();
+        let node = db.parse_or_expand(source.file_id).unwrap();
+        source.value.to_node(&node)
     }
 
     pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
index 9d29f307166d7e3eaa70aafbd8d83259105f6e78..efca096199558c36ca79ab75a54789a5a98f935f 100644 (file)
@@ -37,7 +37,7 @@ fn message(&self) -> String {
         "no such field".to_string()
     }
 
-    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+    fn source(&self) -> InFile<SyntaxNodePtr> {
         InFile::new(self.file, self.field.clone().into())
     }
 
@@ -137,7 +137,7 @@ impl Diagnostic for MissingMatchArms {
     fn message(&self) -> String {
         String::from("Missing match arm")
     }
-    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+    fn source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.match_expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -155,7 +155,7 @@ impl Diagnostic for MissingOkInTailExpr {
     fn message(&self) -> String {
         "wrap return expression in Ok".to_string()
     }
-    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+    fn source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -182,7 +182,7 @@ impl Diagnostic for BreakOutsideOfLoop {
     fn message(&self) -> String {
         "break outside of loop".to_string()
     }
-    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+    fn source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -209,7 +209,7 @@ impl Diagnostic for MissingUnsafe {
     fn message(&self) -> String {
         format!("This operation is unsafe and requires an unsafe function or block")
     }
-    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+    fn source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -239,7 +239,7 @@ fn message(&self) -> String {
         let s = if self.expected == 1 { "" } else { "s" };
         format!("Expected {} argument{}, found {}", self.expected, s, self.found)
     }
-    fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+    fn source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.call_expr.clone().into() }
     }
     fn as_any(&self) -> &(dyn Any + Send + 'static) {