aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/diagnostics.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs
index 0b9bb5a66..94424dc16 100644
--- a/crates/ra_ide_api/src/diagnostics.rs
+++ b/crates/ra_ide_api/src/diagnostics.rs
@@ -79,7 +79,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
79 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| { 79 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| {
80 let node = d.ast(db); 80 let node = d.ast(db);
81 let mut builder = TextEditBuilder::default(); 81 let mut builder = TextEditBuilder::default();
82 let replacement = format!("Ok({})", node.syntax().text()); 82 let replacement = format!("Ok({})", node.syntax());
83 builder.replace(node.syntax().text_range(), replacement); 83 builder.replace(node.syntax().text_range(), replacement);
84 let fix = SourceChange::source_file_edit_from("wrap with ok", file_id, builder.finish()); 84 let fix = SourceChange::source_file_edit_from("wrap with ok", file_id, builder.finish());
85 res.borrow_mut().push(Diagnostic { 85 res.borrow_mut().push(Diagnostic {
@@ -353,7 +353,7 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
353 } 353 }
354 354
355 #[test] 355 #[test]
356 fn test_wrap_return_type_not_applicable() { 356 fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
357 let content = r#" 357 let content = r#"
358 //- /main.rs 358 //- /main.rs
359 use std::{string::String, result::Result::{self, Ok, Err}}; 359 use std::{string::String, result::Result::{self, Ok, Err}};
@@ -374,6 +374,32 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
374 } 374 }
375 375
376 #[test] 376 #[test]
377 fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() {
378 let content = r#"
379 //- /main.rs
380 use std::{string::String, result::Result::{self, Ok, Err}};
381
382 enum SomeOtherEnum {
383 Ok(i32),
384 Err(String),
385 }
386
387 fn foo() -> SomeOtherEnum {
388 0
389 }
390
391 //- /std/lib.rs
392 pub mod string {
393 pub struct String { }
394 }
395 pub mod result {
396 pub enum Result<T, E> { Ok(T), Err(E) }
397 }
398 "#;
399 check_no_diagnostic_for_target_file("/main.rs", content);
400 }
401
402 #[test]
377 fn test_fill_struct_fields_empty() { 403 fn test_fill_struct_fields_empty() {
378 let before = r" 404 let before = r"
379 struct TestStruct { 405 struct TestStruct {