Skip to content

Commit 30bda45

Browse files
fix: between span derviation on cast exprs
1 parent 17d90ca commit 30bda45

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/formatting/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ pub(crate) fn format_expr(
236236
/* Retrieving the comments before and after cast */
237237
let prefix_span = mk_sp(
238238
subexpr.span.hi(),
239-
context.snippet_provider.span_before(expr.span, "as"),
239+
context.snippet_provider.span_before_last(expr.span, "as") - BytePos(1),
240240
);
241241
let suffix_span = mk_sp(
242-
context.snippet_provider.span_after(expr.span, "as"),
242+
context.snippet_provider.span_after_last(expr.span, "as"),
243243
ty.span.lo(),
244244
);
245245
let infix_prefix_comments = rewrite_missing_comment(prefix_span, shape, context)?;

tests/source/issue_4534.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() { let z = (x as f64 / y as f64).floor() as usize; }
2+
3+
4+
fn main() { let z = (x /* x */ as /*y */ f64 / y /* z */ as /* a */ f64).floor() /* b */ as /* c */ usize; }

tests/target/issue_4534.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let z = (x as f64 / y as f64).floor() as usize;
3+
}
4+
5+
fn main() {
6+
let z = (x /* x */ as /*y */ f64 / y /* z */ as /* a */ f64).floor() /* b */ as /* c */ usize;
7+
}

0 commit comments

Comments
 (0)