Skip to content

Commit c317077

Browse files
committed
Use relative positions inside a SourceFile.
1 parent b3136a8 commit c317077

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_lexer::{tokenize, TokenKind};
1212
use rustc_lint::{LateContext, LateLintPass, LintContext};
1313
use rustc_middle::lint::in_external_macro;
1414
use rustc_session::{declare_tool_lint, impl_lint_pass};
15-
use rustc_span::{BytePos, Pos, Span, SyntaxContext};
15+
use rustc_span::{BytePos, RelativeBytePos,Pos, Span, SyntaxContext};
1616

1717
declare_clippy_lint! {
1818
/// ### What it does
@@ -688,7 +688,7 @@ fn span_in_body_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool {
688688
}
689689

690690
/// Checks if the given text has a safety comment for the immediately proceeding line.
691-
fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) -> Option<BytePos> {
691+
fn text_has_safety_comment(src: &str, line_starts: &[RelativeBytePos], offset: usize) -> Option<BytePos> {
692692
let mut lines = line_starts
693693
.array_windows::<2>()
694694
.rev()

clippy_utils/src/source.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource};
88
use rustc_lint::{LateContext, LintContext};
99
use rustc_session::Session;
1010
use rustc_span::source_map::{original_sp, SourceMap};
11-
use rustc_span::{hygiene, BytePos, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP};
11+
use rustc_span::{hygiene, BytePos, SourceFileAndLine, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP};
1212
use std::borrow::Cow;
1313
use std::ops::Range;
1414

@@ -117,9 +117,9 @@ fn first_char_in_first_line<T: LintContext>(cx: &T, span: Span) -> Option<BytePo
117117
/// ```
118118
fn line_span<T: LintContext>(cx: &T, span: Span) -> Span {
119119
let span = original_sp(span, DUMMY_SP);
120-
let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap();
121-
let line_no = source_map_and_line.line;
122-
let line_start = source_map_and_line.sf.lines(|lines| lines[line_no]);
120+
let SourceFileAndLine { sf, line } = cx.sess().source_map().lookup_line(span.lo()).unwrap();
121+
let line_start = sf.lines(|lines| lines[line]);
122+
let line_start = sf.absolute_position(line_start);
123123
span.with_lo(line_start)
124124
}
125125

0 commit comments

Comments
 (0)