about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBastian Kersting <bastian@cmbt.de>2021-06-07 21:44:04 +0200
committerBastian Kersting <bastian@cmbt.de>2021-06-07 22:05:53 +0200
commit6bf8303c4768e91deb3ba02f4c8a846166b5600b (patch)
tree63c47f174f276dea98b82ca88c19c8b84ee94bed
parent790888d520859543cf8fce8b5a3226d71e719539 (diff)
downloadrust-6bf8303c4768e91deb3ba02f4c8a846166b5600b.tar.gz
rust-6bf8303c4768e91deb3ba02f4c8a846166b5600b.zip
Refactored the check for two spans on the same line
-rw-r--r--clippy_lints/src/semicolon_if_nothing_returned.rs6
-rw-r--r--clippy_utils/src/lib.rs5
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 3698e548bd2..eff6cdf36b4 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 be625eb2655..769836aaf18 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -820,11 +820,6 @@ fn line_span<T: LintContext>(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<T: LintContext>(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<Node<'_>> {
     tcx.hir().parent_iter(id).next().map(|(_, node)| node)