Skip to content

Commit

Permalink
Avoid line break when rhs of assignment is an invalid macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiichi Uchida authored and topecongiro committed Jun 18, 2017
1 parent be18e7a commit 6afb0e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/expr.rs
Expand Up @@ -2719,17 +2719,7 @@ pub fn rewrite_assign_rhs<S: Into<String>>(
};
// 1 = space between operator and rhs.
let orig_shape = try_opt!(shape.offset_left(last_line_width + 1));
let rhs = match ex.node {
ast::ExprKind::Mac(ref mac) => {
match rewrite_macro(mac, None, context, orig_shape, MacroPosition::Expression) {
None if !context.snippet(ex.span).contains("\n") => {
context.snippet(ex.span).rewrite(context, orig_shape)
}
rhs @ _ => rhs,
}
}
_ => ex.rewrite(context, orig_shape),
};
let rhs = ex.rewrite(context, orig_shape);

fn count_line_breaks(src: &str) -> usize {
src.chars().filter(|&x| x == '\n').count()
Expand Down
6 changes: 6 additions & 0 deletions tests/source/macros.rs
Expand Up @@ -79,6 +79,12 @@ fn main() {
not function like
);

// #1712
let image = gray_image!(
00, 01, 02;
10, 11, 12;
20, 21, 22);

// #1577
let json = json!({
"foo": "bar",
Expand Down
6 changes: 6 additions & 0 deletions tests/target/macros.rs
Expand Up @@ -110,6 +110,12 @@ fn main() {
not function like
);

// #1712
let image = gray_image!(
00, 01, 02;
10, 11, 12;
20, 21, 22);

// #1577
let json = json!({
"foo": "bar",
Expand Down

0 comments on commit 6afb0e8

Please sign in to comment.