Skip to content

Use correct max width when formatting macro body #2920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,20 +1277,22 @@ impl MacroBranch {
let body_indent = if has_block_body {
shape.indent
} else {
// We'll hack the indent below, take this into account when formatting,
let body_indent = shape.indent.block_indent(&config);
let new_width = config.max_width() - body_indent.width();
config.set().max_width(new_width);
body_indent
shape.indent.block_indent(&config)
};
let new_width = config.max_width() - body_indent.width();
config.set().max_width(new_width);

// First try to format as items, then as statements.
let new_body = match ::format_snippet(&body_str, &config) {
Some(new_body) => new_body,
None => match ::format_code_block(&body_str, &config) {
Some(new_body) => new_body,
None => return None,
},
None => {
let new_width = new_width + config.tab_spaces();
config.set().max_width(new_width);
match ::format_code_block(&body_str, &config) {
Some(new_body) => new_body,
None => return None,
}
}
};
let new_body = wrap_str(new_body, config.max_width(), shape)?;

Expand Down
16 changes: 16 additions & 0 deletions tests/source/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,19 @@ macro_rules! impl_as_byte_slice_arrays {
}
};
}

// #2919
fn foo() {
{
macro_rules! touch_value {
($func:ident, $value:expr) => {{
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendMode::paTouch);
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppend);
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
let result = APIIIIIIIII::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendMMMMMMMMMM);
debug_assert!(result == 0);
}};
}
}
}
28 changes: 28 additions & 0 deletions tests/target/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,31 @@ macro_rules! impl_as_byte_slice_arrays {
}
};
}

// #2919
fn foo() {
{
macro_rules! touch_value {
($func:ident, $value:expr) => {{
let result = API::get_cached().$func(
self,
key.as_ptr(),
$value,
ffi::VSPropAppendMode::paTouch,
);
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppend);
let result =
API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
let result =
APIIIIIIIII::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
let result = API::get_cached().$func(
self,
key.as_ptr(),
$value,
ffi::VSPropAppendMMMMMMMMMM,
);
debug_assert!(result == 0);
}};
}
}
}