Skip to content

Commit 39d0477

Browse files
committed
Refactor BytePos handling
1 parent 8c50dfb commit 39d0477

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

clippy_lints/src/returns.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::lint::in_external_macro;
1212
use rustc_middle::ty::subst::GenericArgKind;
1313
use rustc_session::{declare_lint_pass, declare_tool_lint};
1414
use rustc_span::source_map::Span;
15-
use rustc_span::BytePos;
15+
use rustc_span::{BytePos, Pos};
1616

1717
declare_clippy_lint! {
1818
/// ### What it does
@@ -293,13 +293,12 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
293293
}
294294

295295
// Go backwards while encountering whitespace and extend the given Span to that point.
296-
#[expect(clippy::cast_possible_truncation)]
297296
fn extend_span_to_previous_non_ws(cx: &LateContext<'_>, sp: Span) -> Span {
298297
if let Ok(prev_source) = cx.sess().source_map().span_to_prev_source(sp) {
299298
let ws = [' ', '\t', '\n'];
300299
if let Some(non_ws_pos) = prev_source.rfind(|c| !ws.contains(&c)) {
301300
let len = prev_source.len() - non_ws_pos - 1;
302-
return sp.with_lo(BytePos(sp.lo().0 - len as u32));
301+
return sp.with_lo(sp.lo() - BytePos::from_usize(len));
303302
}
304303
}
305304

0 commit comments

Comments
 (0)