Refactored the check for two spans on the same line

This commit is contained in:
Bastian Kersting 2021-06-07 21:44:04 +02:00
parent 790888d520
commit 6bf8303c47
2 changed files with 4 additions and 7 deletions

View file

@ -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

View file

@ -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)