Skip to content

Commit 337ab40

Browse files
committed
Refactored the check for two spans on the same line
1 parent 790888d commit 337ab40

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

clippy_lints/src/semicolon_if_nothing_returned.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_macro_callsite;
3-
use clippy_utils::{get_parent_expr_for_hir, in_macro, spans_on_same_line, sugg};
3+
use clippy_utils::{get_parent_expr_for_hir, in_macro, sugg};
4+
use crate::rustc_lint::LintContext;
45
use if_chain::if_chain;
56
use rustc_errors::Applicability;
67
use rustc_hir::Expr;
@@ -82,8 +83,9 @@ fn check_if_inside_block_on_same_line<'tcx>(
8283
matches!(parent.kind, ExprKind::Closure(..) | ExprKind::Block(..));
8384

8485
if block.stmts.is_empty();
86+
let source_map = cx.sess().source_map();
8587
then {
86-
return spans_on_same_line(cx, parent.span, last_expr.span);
88+
return !source_map.is_multiline(parent.span.to(last_expr.span));
8789
}
8890
}
8991
false

clippy_utils/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,6 @@ fn line_span<T: LintContext>(cx: &T, span: Span) -> Span {
820820
Span::new(line_start, span.hi(), span.ctxt())
821821
}
822822

823-
/// Checks if two spans begin on the same line.
824-
pub fn spans_on_same_line<T: LintContext>(cx: &T, left_span: Span, right_span: Span) -> bool {
825-
line_span(cx, left_span).lo() == line_span(cx, right_span).lo()
826-
}
827-
828823
/// Gets the parent node, if any.
829824
pub fn get_parent_node(tcx: TyCtxt<'_>, id: HirId) -> Option<Node<'_>> {
830825
tcx.hir().parent_iter(id).next().map(|(_, node)| node)

0 commit comments

Comments
 (0)