cargo fmt

This commit is contained in:
Phil Ellison 2020-12-30 17:33:33 +00:00
parent b2dbe6e43a
commit 554ee6ea02
2 changed files with 11 additions and 7 deletions

View file

@ -11,8 +11,8 @@ use crate::{
db::HirDatabase, db::HirDatabase,
diagnostics::{ diagnostics::{
match_check::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness}, match_check::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness},
MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, MissingPatFields, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr,
RemoveThisSemicolon, MissingPatFields, RemoveThisSemicolon,
}, },
utils::variant_data, utils::variant_data,
ApplicationTy, InferenceResult, Ty, TypeCtor, ApplicationTy, InferenceResult, Ty, TypeCtor,
@ -324,10 +324,10 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
let (params, required) = match &mismatch.expected { let (params, required) = match &mismatch.expected {
Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_result_ctor => { Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_result_ctor => {
(parameters, "Ok".to_string()) (parameters, "Ok".to_string())
}, }
Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_option_ctor => { Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_option_ctor => {
(parameters, "Some".to_string()) (parameters, "Some".to_string())
}, }
_ => return, _ => return,
}; };
@ -335,8 +335,11 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
let (_, source_map) = db.body_with_source_map(self.owner.into()); let (_, source_map) = db.body_with_source_map(self.owner.into());
if let Ok(source_ptr) = source_map.expr_syntax(id) { if let Ok(source_ptr) = source_map.expr_syntax(id) {
self.sink self.sink.push(MissingOkOrSomeInTailExpr {
.push(MissingOkOrSomeInTailExpr { file: source_ptr.file_id, expr: source_ptr.value, required }); file: source_ptr.file_id,
expr: source_ptr.value,
required,
});
} }
} }
} }

View file

@ -101,7 +101,8 @@ impl DiagnosticWithFix for MissingOkOrSomeInTailExpr {
let tail_expr_range = tail_expr.syntax().text_range(); let tail_expr_range = tail_expr.syntax().text_range();
let replacement = format!("{}({})", self.required, tail_expr.syntax()); let replacement = format!("{}({})", self.required, tail_expr.syntax());
let edit = TextEdit::replace(tail_expr_range, replacement); let edit = TextEdit::replace(tail_expr_range, replacement);
let source_change = SourceFileEdit { file_id: self.file.original_file(sema.db), edit }.into(); let source_change =
SourceFileEdit { file_id: self.file.original_file(sema.db), edit }.into();
let name = if self.required == "Ok" { "Wrap with Ok" } else { "Wrap with Some" }; let name = if self.required == "Ok" { "Wrap with Ok" } else { "Wrap with Some" };
Some(Fix::new(name, source_change, tail_expr_range)) Some(Fix::new(name, source_change, tail_expr_range))
} }