Format code

This commit is contained in:
ivan770 2020-12-08 19:25:21 +00:00 committed by GitHub
parent f2950a1350
commit 7738467e0a
3 changed files with 24 additions and 8 deletions

View file

@ -5,5 +5,5 @@ pub use hir_expand::diagnostics::{
}; };
pub use hir_ty::diagnostics::{ pub use hir_ty::diagnostics::{
IncorrectCase, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, IncorrectCase, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr,
NoSuchField, RemoveThisSemicolon NoSuchField, RemoveThisSemicolon,
}; };

View file

@ -2,7 +2,7 @@
use std::sync::Arc; use std::sync::Arc;
use hir_def::{AdtId, DefWithBodyId, expr::Statement, path::path, resolver::HasResolver}; use hir_def::{expr::Statement, path::path, resolver::HasResolver, AdtId, DefWithBodyId};
use hir_expand::diagnostics::DiagnosticSink; use hir_expand::diagnostics::DiagnosticSink;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use syntax::{ast, AstPtr}; use syntax::{ast, AstPtr};
@ -11,7 +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, MissingOkInTailExpr, MissingPatFields, RemoveThisSemicolon MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, MissingPatFields,
RemoveThisSemicolon,
}, },
utils::variant_data, utils::variant_data,
ApplicationTy, InferenceResult, Ty, TypeCtor, ApplicationTy, InferenceResult, Ty, TypeCtor,
@ -324,7 +325,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
} }
} }
fn validate_missing_tail_expr(&mut self, body_id: ExprId, possible_tail_id: ExprId, db: &dyn HirDatabase) { fn validate_missing_tail_expr(
&mut self,
body_id: ExprId,
possible_tail_id: ExprId,
db: &dyn HirDatabase,
) {
let mismatch = match self.infer.type_mismatch_for_expr(body_id) { let mismatch = match self.infer.type_mismatch_for_expr(body_id) {
Some(m) => m, Some(m) => m,
None => return, None => return,
@ -335,7 +341,10 @@ 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(possible_tail_id) { if let Ok(source_ptr) = source_map.expr_syntax(possible_tail_id) {
self.sink.push(RemoveThisSemicolon { file: source_ptr.file_id, expr: source_ptr.value }); self.sink.push(RemoveThisSemicolon {
file: source_ptr.file_id,
expr: source_ptr.value,
});
} }
} }
} }

View file

@ -13,7 +13,11 @@ use ide_db::{
source_change::{FileSystemEdit, SourceFileEdit}, source_change::{FileSystemEdit, SourceFileEdit},
RootDatabase, RootDatabase,
}; };
use syntax::{AstNode, Direction, T, algo, ast::{self, edit::IndentLevel, make}}; use syntax::{
algo,
ast::{self, edit::IndentLevel, make},
AstNode, Direction, T,
};
use text_edit::TextEdit; use text_edit::TextEdit;
use crate::{diagnostics::Fix, references::rename::rename_with_semantics, FilePosition}; use crate::{diagnostics::Fix, references::rename::rename_with_semantics, FilePosition};
@ -102,7 +106,9 @@ impl DiagnosticWithFix for RemoveThisSemicolon {
fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> { fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
let root = sema.db.parse_or_expand(self.file)?; let root = sema.db.parse_or_expand(self.file)?;
let semicolon = self.expr.to_node(&root) let semicolon = self
.expr
.to_node(&root)
.syntax() .syntax()
.siblings_with_tokens(Direction::Next) .siblings_with_tokens(Direction::Next)
.filter_map(|it| it.into_token()) .filter_map(|it| it.into_token())
@ -110,7 +116,8 @@ impl DiagnosticWithFix for RemoveThisSemicolon {
.text_range(); .text_range();
let edit = TextEdit::delete(semicolon); let edit = TextEdit::delete(semicolon);
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();
Some(Fix::new("Remove this semicolon", source_change, semicolon)) Some(Fix::new("Remove this semicolon", source_change, semicolon))
} }