aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_ty/src/diagnostics/expr.rs15
-rw-r--r--crates/ide/src/diagnostics/fixes.rs3
2 files changed, 11 insertions, 7 deletions
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs
index 455b0d4aa..a1c484fdf 100644
--- a/crates/hir_ty/src/diagnostics/expr.rs
+++ b/crates/hir_ty/src/diagnostics/expr.rs
@@ -11,8 +11,8 @@ use crate::{
11 db::HirDatabase, 11 db::HirDatabase,
12 diagnostics::{ 12 diagnostics::{
13 match_check::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness}, 13 match_check::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness},
14 MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, MissingPatFields, 14 MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr,
15 RemoveThisSemicolon, 15 MissingPatFields, RemoveThisSemicolon,
16 }, 16 },
17 utils::variant_data, 17 utils::variant_data,
18 ApplicationTy, InferenceResult, Ty, TypeCtor, 18 ApplicationTy, InferenceResult, Ty, TypeCtor,
@@ -324,10 +324,10 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
324 let (params, required) = match &mismatch.expected { 324 let (params, required) = match &mismatch.expected {
325 Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_result_ctor => { 325 Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_result_ctor => {
326 (parameters, "Ok".to_string()) 326 (parameters, "Ok".to_string())
327 }, 327 }
328 Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_option_ctor => { 328 Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_option_ctor => {
329 (parameters, "Some".to_string()) 329 (parameters, "Some".to_string())
330 }, 330 }
331 _ => return, 331 _ => return,
332 }; 332 };
333 333
@@ -335,8 +335,11 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
335 let (_, source_map) = db.body_with_source_map(self.owner.into()); 335 let (_, source_map) = db.body_with_source_map(self.owner.into());
336 336
337 if let Ok(source_ptr) = source_map.expr_syntax(id) { 337 if let Ok(source_ptr) = source_map.expr_syntax(id) {
338 self.sink 338 self.sink.push(MissingOkOrSomeInTailExpr {
339 .push(MissingOkOrSomeInTailExpr { file: source_ptr.file_id, expr: source_ptr.value, required }); 339 file: source_ptr.file_id,
340 expr: source_ptr.value,
341 required,
342 });
340 } 343 }
341 } 344 }
342 } 345 }
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs
index 50c18d02b..d7ad88ed5 100644
--- a/crates/ide/src/diagnostics/fixes.rs
+++ b/crates/ide/src/diagnostics/fixes.rs
@@ -101,7 +101,8 @@ impl DiagnosticWithFix for MissingOkOrSomeInTailExpr {
101 let tail_expr_range = tail_expr.syntax().text_range(); 101 let tail_expr_range = tail_expr.syntax().text_range();
102 let replacement = format!("{}({})", self.required, tail_expr.syntax()); 102 let replacement = format!("{}({})", self.required, tail_expr.syntax());
103 let edit = TextEdit::replace(tail_expr_range, replacement); 103 let edit = TextEdit::replace(tail_expr_range, replacement);
104 let source_change = SourceFileEdit { file_id: self.file.original_file(sema.db), edit }.into(); 104 let source_change =
105 SourceFileEdit { file_id: self.file.original_file(sema.db), edit }.into();
105 let name = if self.required == "Ok" { "Wrap with Ok" } else { "Wrap with Some" }; 106 let name = if self.required == "Ok" { "Wrap with Ok" } else { "Wrap with Some" };
106 Some(Fix::new(name, source_change, tail_expr_range)) 107 Some(Fix::new(name, source_change, tail_expr_range))
107 } 108 }