diff options
| author | koka <koka.code@gmail.com> | 2022-11-27 22:41:06 +0900 |
|---|---|---|
| committer | koka <koka.code@gmail.com> | 2022-11-27 22:41:06 +0900 |
| commit | 39d0477080de2c458cdbeb4a0a44d267d58af521 (patch) | |
| tree | 9dd762095fd01789f9e70352ee9fc2d709f1a573 | |
| parent | 8c50dfb54649cbd67e37e7a456e736241740666d (diff) | |
| download | rust-39d0477080de2c458cdbeb4a0a44d267d58af521.tar.gz rust-39d0477080de2c458cdbeb4a0a44d267d58af521.zip | |
Refactor BytePos handling
| -rw-r--r-- | clippy_lints/src/returns.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 933258f9c3e..81143d7799e 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -12,7 +12,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use rustc_span::BytePos; +use rustc_span::{BytePos, Pos}; declare_clippy_lint! { /// ### What it does @@ -293,13 +293,12 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) } // Go backwards while encountering whitespace and extend the given Span to that point. -#[expect(clippy::cast_possible_truncation)] fn extend_span_to_previous_non_ws(cx: &LateContext<'_>, sp: Span) -> Span { if let Ok(prev_source) = cx.sess().source_map().span_to_prev_source(sp) { let ws = [' ', '\t', '\n']; if let Some(non_ws_pos) = prev_source.rfind(|c| !ws.contains(&c)) { let len = prev_source.len() - non_ws_pos - 1; - return sp.with_lo(BytePos(sp.lo().0 - len as u32)); + return sp.with_lo(sp.lo() - BytePos::from_usize(len)); } } |
