Skip to content

Commit 51ec465

Browse files
committed
Auto merge of #9873 - smoelius:move-line-span, r=flip1995
Move `line_span` to source.rs `line_span` is a non-public function used only in source.rs. It seems like it ought to go in source.rs. changelog: none
2 parents e0c1959 + ef5f602 commit 51ec465

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

clippy_utils/src/lib.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,10 @@ use rustc_middle::ty::{FloatTy, IntTy, UintTy};
108108
use rustc_semver::RustcVersion;
109109
use rustc_session::Session;
110110
use rustc_span::hygiene::{ExpnKind, MacroKind};
111-
use rustc_span::source_map::original_sp;
112111
use rustc_span::source_map::SourceMap;
113112
use rustc_span::sym;
114113
use rustc_span::symbol::{kw, Ident, Symbol};
115-
use rustc_span::{Span, DUMMY_SP};
114+
use rustc_span::Span;
116115
use rustc_target::abi::Integer;
117116

118117
use crate::consts::{constant, Constant};
@@ -1302,23 +1301,6 @@ pub fn contains_return(expr: &hir::Expr<'_>) -> bool {
13021301
.is_some()
13031302
}
13041303

1305-
/// Extends the span to the beginning of the spans line, incl. whitespaces.
1306-
///
1307-
/// ```rust
1308-
/// let x = ();
1309-
/// // ^^
1310-
/// // will be converted to
1311-
/// let x = ();
1312-
/// // ^^^^^^^^^^^^^^
1313-
/// ```
1314-
fn line_span<T: LintContext>(cx: &T, span: Span) -> Span {
1315-
let span = original_sp(span, DUMMY_SP);
1316-
let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap();
1317-
let line_no = source_map_and_line.line;
1318-
let line_start = source_map_and_line.sf.lines(|lines| lines[line_no]);
1319-
span.with_lo(line_start)
1320-
}
1321-
13221304
/// Gets the parent node, if any.
13231305
pub fn get_parent_node(tcx: TyCtxt<'_>, id: HirId) -> Option<Node<'_>> {
13241306
tcx.hir().parent_iter(id).next().map(|(_, node)| node)

clippy_utils/src/source.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
33
#![allow(clippy::module_name_repetitions)]
44

5-
use crate::line_span;
65
use rustc_errors::Applicability;
76
use rustc_hir::{Expr, ExprKind};
87
use rustc_lint::{LateContext, LintContext};
98
use rustc_span::hygiene;
10-
use rustc_span::source_map::SourceMap;
11-
use rustc_span::{BytePos, Pos, Span, SpanData, SyntaxContext};
9+
use rustc_span::source_map::{original_sp, SourceMap};
10+
use rustc_span::{BytePos, Pos, Span, SpanData, SyntaxContext, DUMMY_SP};
1211
use std::borrow::Cow;
1312

1413
/// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block`.
@@ -55,6 +54,23 @@ fn first_char_in_first_line<T: LintContext>(cx: &T, span: Span) -> Option<BytePo
5554
})
5655
}
5756

57+
/// Extends the span to the beginning of the spans line, incl. whitespaces.
58+
///
59+
/// ```rust
60+
/// let x = ();
61+
/// // ^^
62+
/// // will be converted to
63+
/// let x = ();
64+
/// // ^^^^^^^^^^^^^^
65+
/// ```
66+
fn line_span<T: LintContext>(cx: &T, span: Span) -> Span {
67+
let span = original_sp(span, DUMMY_SP);
68+
let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap();
69+
let line_no = source_map_and_line.line;
70+
let line_start = source_map_and_line.sf.lines(|lines| lines[line_no]);
71+
span.with_lo(line_start)
72+
}
73+
5874
/// Returns the indentation of the line of a span
5975
///
6076
/// ```rust,ignore

0 commit comments

Comments
 (0)