diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-09-03 10:15:35 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-09-03 12:56:10 +0000 |
| commit | c3170771f307bd991b0cdf91233d262aa1702e9a (patch) | |
| tree | f2689a5f8656db63e43b4603d878081d9c8cee6d | |
| parent | b3136a874d2be591fd437e15db9434af6818a696 (diff) | |
Use relative positions inside a SourceFile.
| -rw-r--r-- | clippy_lints/src/undocumented_unsafe_blocks.rs | 4 | ||||
| -rw-r--r-- | clippy_utils/src/source.rs | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index f2ef602012f..7956bf12622 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -12,7 +12,7 @@ use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{BytePos, Pos, Span, SyntaxContext}; +use rustc_span::{BytePos, RelativeBytePos,Pos, Span, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -688,7 +688,7 @@ fn span_in_body_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { } /// Checks if the given text has a safety comment for the immediately proceeding line. -fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) -> Option<BytePos> { +fn text_has_safety_comment(src: &str, line_starts: &[RelativeBytePos], offset: usize) -> Option<BytePos> { let mut lines = line_starts .array_windows::<2>() .rev() diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index dc4ee725681..03416d35ba4 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -8,7 +8,7 @@ use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource}; use rustc_lint::{LateContext, LintContext}; use rustc_session::Session; use rustc_span::source_map::{original_sp, SourceMap}; -use rustc_span::{hygiene, BytePos, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP}; +use rustc_span::{hygiene, BytePos, SourceFileAndLine, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP}; use std::borrow::Cow; use std::ops::Range; @@ -117,9 +117,9 @@ fn first_char_in_first_line<T: LintContext>(cx: &T, span: Span) -> Option<BytePo /// ``` fn line_span<T: LintContext>(cx: &T, span: Span) -> Span { let span = original_sp(span, DUMMY_SP); - let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap(); - let line_no = source_map_and_line.line; - let line_start = source_map_and_line.sf.lines(|lines| lines[line_no]); + let SourceFileAndLine { sf, line } = cx.sess().source_map().lookup_line(span.lo()).unwrap(); + let line_start = sf.lines(|lines| lines[line]); + let line_start = sf.absolute_position(line_start); span.with_lo(line_start) } |
