Skip to content

Commit 1aa6ae0

Browse files
committed
Changes per reviewer comments
1 parent 8e49f20 commit 1aa6ae0

File tree

5 files changed

+124
-6
lines changed

5 files changed

+124
-6
lines changed

src/items.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ impl Rewrite for ast::Local {
113113
result.push_str(&infix);
114114

115115
if let Some((init, _els)) = self.kind.init_else_opt() {
116-
let base_span = if let Some(ref ty) = self.ty {
117-
mk_sp(ty.span.hi(), self.span.hi())
116+
let lhs_to_expr_span = if let Some(ref ty) = self.ty {
117+
ty.span.between(init.span)
118118
} else {
119-
mk_sp(self.pat.span.hi(), self.span.hi())
119+
self.pat.span.between(init.span)
120120
};
121121

122-
result = rewrite_initializer_expr(context, init, result, base_span, shape)?;
122+
result = rewrite_initializer_expr(context, init, result, lhs_to_expr_span, shape)?;
123123
}
124124
// todo else of kind.init_else_opt
125125

@@ -132,7 +132,7 @@ fn rewrite_initializer_expr(
132132
context: &RewriteContext<'_>,
133133
init: &ast::Expr,
134134
lhs: String,
135-
base_span: Span,
135+
lhs_to_rhs_span: Span,
136136
shape: Shape,
137137
) -> Option<String> {
138138
if context.config.version() == Version::One {
@@ -148,7 +148,7 @@ fn rewrite_initializer_expr(
148148
)
149149
} else {
150150
// Version:Two+
151-
let comment_lo = context.snippet_provider.span_after(base_span, "=");
151+
let comment_lo = context.snippet_provider.span_after(lhs_to_rhs_span, "=");
152152
let comment_span = mk_sp(comment_lo, init.span.lo());
153153

154154
// 1 = trailing semicolon;

tests/source/lhs-to-rhs-between-comments/assignment-multi-line-comments.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ var = // Line comment
4242
* Block comment line 2 */ seventh;
4343
}
4444

45+
// ": type =" Assignemnt - Multiline Line and Block comments
46+
fn main () {
47+
let var: int = /* Block comment line 1
48+
* Block comment line 2
49+
* Block comment line 3 */ first;
50+
let var: u64 = /* Block comment line 1
51+
* Block comment line 2
52+
* Block comment line 3 */ second;
53+
let var: f32 = // Line comment 1
54+
// Line comment 2
55+
// Line comment 3
56+
third;
57+
let var: bool = // Line comment
58+
/* Block comment line 1
59+
* Block comment line 2 */ forth;
60+
let var: char = /* Block comment single line */
61+
// Line comment
62+
/* Block comment line 1
63+
* Block comment line 2 */ fifth;
64+
let var: str = /* Block comment single line 1 */
65+
/* Block comment single line 2*/ fsixth;
66+
let var: usize = /* Block comment single line 1 */
67+
/* Block comment single line 2*/
68+
seventh;
69+
}
70+
4571
// BinOp Assignemnt - Multiline Block comments
4672
fn main () {
4773
let var = /* Block comment line 1

tests/source/lhs-to-rhs-between-comments/assignment-single-line-comments.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ let var = /* Block comment longggggggggggggggggggggggggggggggggggggggggggggggggg
2525
var = /* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg */ second;
2626
}
2727

28+
// ": type =" Assignemnt
29+
fn main () {
30+
let var: u8 = first;
31+
var = second;
32+
}
33+
fn main () {
34+
let var: int = /* Block comment */ first;
35+
let var: u32 = /* Block comment */ second;
36+
let var: f64 = /* Block comment */
37+
third;
38+
}
39+
fn main () {
40+
let var: bool = // Line comment
41+
first;
42+
let var: char = // Line comment
43+
second;
44+
}
45+
fn main () {
46+
let var: str = /* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggg */ first;
47+
let var: usize = /* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg */ second;
48+
}
49+
fn main () {
50+
let var: isize = /* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg */ first;
51+
let var: u8 = /* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg */ second;
52+
}
53+
2854
// BinOp Assigment
2955
fn main () {
3056
let var = first;

tests/target/lhs-to-rhs-between-comments/assignment-multi-line-comments.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ fn main() {
5555
seventh;
5656
}
5757

58+
// ": type =" Assignemnt - Multiline Line and Block comments
59+
fn main() {
60+
let var: int =
61+
/* Block comment line 1
62+
* Block comment line 2
63+
* Block comment line 3 */
64+
first;
65+
let var: u64 =
66+
/* Block comment line 1
67+
* Block comment line 2
68+
* Block comment line 3 */
69+
second;
70+
let var: f32 = // Line comment 1
71+
// Line comment 2
72+
// Line comment 3
73+
third;
74+
let var: bool = // Line comment
75+
/* Block comment line 1
76+
* Block comment line 2 */
77+
forth;
78+
let var: char = /* Block comment single line */
79+
// Line comment
80+
/* Block comment line 1
81+
* Block comment line 2 */
82+
fifth;
83+
let var: str = /* Block comment single line 1 */
84+
/* Block comment single line 2*/
85+
fsixth;
86+
let var: usize = /* Block comment single line 1 */
87+
/* Block comment single line 2*/
88+
seventh;
89+
}
90+
5891
// BinOp Assignemnt - Multiline Block comments
5992
fn main() {
6093
let var =

tests/target/lhs-to-rhs-between-comments/assignment-single-line-comments.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,39 @@ fn main() {
3030
second;
3131
}
3232

33+
// ": type =" Assignemnt
34+
fn main() {
35+
let var: u8 = first;
36+
var = second;
37+
}
38+
fn main() {
39+
let var: int = /* Block comment */ first;
40+
let var: u32 = /* Block comment */ second;
41+
let var: f64 = /* Block comment */ third;
42+
}
43+
fn main() {
44+
let var: bool = // Line comment
45+
first;
46+
let var: char = // Line comment
47+
second;
48+
}
49+
fn main() {
50+
let var: str =
51+
/* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggg */
52+
first;
53+
let var: usize =
54+
/* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg */
55+
second;
56+
}
57+
fn main() {
58+
let var: isize =
59+
/* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg */
60+
first;
61+
let var: u8 =
62+
/* Block comment longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg */
63+
second;
64+
}
65+
3366
// BinOp Assigment
3467
fn main() {
3568
let var = first;

0 commit comments

Comments
 (0)