From bbb0bc7b041278480edbfaa7c3cdadc5a704fc03 Mon Sep 17 00:00:00 2001 From: ivan770 Date: Thu, 10 Dec 2020 18:10:39 +0200 Subject: Cast to ExprStmt, style fixes --- crates/hir_ty/src/diagnostics/expr.rs | 11 +++++------ crates/ide/src/diagnostics/fixes.rs | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index 9e461e0b0..849415706 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs @@ -334,18 +334,17 @@ impl<'a, 'b> ExprValidator<'a, 'b> { None => return, }; - let possible_tail_ty = - if let Some(possible_tail_ty) = self.infer.type_of_expr.get(possible_tail_id) { - possible_tail_ty - } else { - return; - }; + let possible_tail_ty = match self.infer.type_of_expr.get(possible_tail_id) { + Some(ty) => ty, + None => return, + }; if mismatch.actual != Ty::unit() || mismatch.expected != *possible_tail_ty { return; } let (_, source_map) = db.body_with_source_map(self.owner.into()); + 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 }); diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index c235b5bf4..ba046232a 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs @@ -16,7 +16,7 @@ use ide_db::{ use syntax::{ algo, ast::{self, edit::IndentLevel, make}, - AstNode, Direction, T, + AstNode, }; use text_edit::TextEdit; @@ -110,9 +110,9 @@ impl DiagnosticWithFix for RemoveThisSemicolon { .expr .to_node(&root) .syntax() - .siblings_with_tokens(Direction::Next) - .filter_map(|it| it.into_token()) - .find(|it| it.kind() == T![;])? + .parent() + .and_then(ast::ExprStmt::cast) + .and_then(|expr| expr.semicolon_token())? .text_range(); let edit = TextEdit::delete(semicolon); -- cgit v1.2.3