Merge pull request #2920 from topecongiro/issue-2919

Use correct max width when formatting macro body
This commit is contained in:
Nick Cameron 2018-08-17 10:07:59 -07:00 committed by GitHub
commit a275a059e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 9 deletions

View File

@ -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);
shape.indent.block_indent(&config)
};
let new_width = config.max_width() - body_indent.width();
config.set().max_width(new_width);
body_indent
};
// 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) {
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)?;

View File

@ -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);
}};
}
}
}

View File

@ -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);
}};
}
}
}