Skip to content

Commit

Permalink
fix: between span derviation on cast exprs
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Nov 19, 2020
1 parent 17d90ca commit 30bda45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/formatting/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ pub(crate) fn format_expr(
/* Retrieving the comments before and after cast */
let prefix_span = mk_sp(
subexpr.span.hi(),
context.snippet_provider.span_before(expr.span, "as"),
context.snippet_provider.span_before_last(expr.span, "as") - BytePos(1),
);
let suffix_span = mk_sp(
context.snippet_provider.span_after(expr.span, "as"),
context.snippet_provider.span_after_last(expr.span, "as"),
ty.span.lo(),
);
let infix_prefix_comments = rewrite_missing_comment(prefix_span, shape, context)?;
Expand Down
4 changes: 4 additions & 0 deletions tests/source/issue_4534.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() { let z = (x as f64 / y as f64).floor() as usize; }


fn main() { let z = (x /* x */ as /*y */ f64 / y /* z */ as /* a */ f64).floor() /* b */ as /* c */ usize; }
7 changes: 7 additions & 0 deletions tests/target/issue_4534.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let z = (x as f64 / y as f64).floor() as usize;
}

fn main() {
let z = (x /* x */ as /*y */ f64 / y /* z */ as /* a */ f64).floor() /* b */ as /* c */ usize;
}

0 comments on commit 30bda45

Please sign in to comment.