Skip to content

Commit 4368cd3

Browse files
authored
Merge pull request #1719 from topecongiro/macro-on-rhs
Avoid line break when rhs of assignment is an invalid macro
2 parents 34fa428 + 6afb0e8 commit 4368cd3

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/expr.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,17 +2719,7 @@ pub fn rewrite_assign_rhs<S: Into<String>>(
27192719
};
27202720
// 1 = space between operator and rhs.
27212721
let orig_shape = try_opt!(shape.offset_left(last_line_width + 1));
2722-
let rhs = match ex.node {
2723-
ast::ExprKind::Mac(ref mac) => {
2724-
match rewrite_macro(mac, None, context, orig_shape, MacroPosition::Expression) {
2725-
None if !context.snippet(ex.span).contains("\n") => {
2726-
context.snippet(ex.span).rewrite(context, orig_shape)
2727-
}
2728-
rhs @ _ => rhs,
2729-
}
2730-
}
2731-
_ => ex.rewrite(context, orig_shape),
2732-
};
2722+
let rhs = ex.rewrite(context, orig_shape);
27332723

27342724
fn count_line_breaks(src: &str) -> usize {
27352725
src.chars().filter(|&x| x == '\n').count()

tests/source/macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ fn main() {
7979
not function like
8080
);
8181

82+
// #1712
83+
let image = gray_image!(
84+
00, 01, 02;
85+
10, 11, 12;
86+
20, 21, 22);
87+
8288
// #1577
8389
let json = json!({
8490
"foo": "bar",

tests/target/macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ fn main() {
110110
not function like
111111
);
112112

113+
// #1712
114+
let image = gray_image!(
115+
00, 01, 02;
116+
10, 11, 12;
117+
20, 21, 22);
118+
113119
// #1577
114120
let json = json!({
115121
"foo": "bar",

0 commit comments

Comments
 (0)