From 6bf8303c4768e91deb3ba02f4c8a846166b5600b Mon Sep 17 00:00:00 2001 From: Bastian Kersting Date: Mon, 7 Jun 2021 21:44:04 +0200 Subject: [PATCH] Refactored the check for two spans on the same line --- clippy_lints/src/semicolon_if_nothing_returned.rs | 6 ++++-- clippy_utils/src/lib.rs | 5 ----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index 3698e548bd20..eff6cdf36b4d 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -1,6 +1,7 @@ +use crate::rustc_lint::LintContext; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_macro_callsite; -use clippy_utils::{get_parent_expr_for_hir, in_macro, spans_on_same_line, sugg}; +use clippy_utils::{get_parent_expr_for_hir, in_macro, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::Expr; @@ -83,7 +84,8 @@ fn check_if_inside_block_on_same_line<'tcx>( if block.stmts.is_empty(); then { - return spans_on_same_line(cx, parent.span, last_expr.span); + let source_map = cx.sess().source_map(); + return !source_map.is_multiline(parent.span.to(last_expr.span)); } } false diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index be625eb26551..769836aaf18e 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -820,11 +820,6 @@ fn line_span(cx: &T, span: Span) -> Span { Span::new(line_start, span.hi(), span.ctxt()) } -/// Checks if two spans begin on the same line. -pub fn spans_on_same_line(cx: &T, left_span: Span, right_span: Span) -> bool { - line_span(cx, left_span).lo() == line_span(cx, right_span).lo() -} - /// Gets the parent node, if any. pub fn get_parent_node(tcx: TyCtxt<'_>, id: HirId) -> Option> { tcx.hir().parent_iter(id).next().map(|(_, node)| node)