Use correct one line width for list attribute

Closes #2647.
This commit is contained in:
topecongiro 2018-04-30 15:49:32 +09:00
parent 9f3f48c85c
commit 61a401ae51
3 changed files with 12 additions and 1 deletions

View file

@ -247,7 +247,8 @@ impl Rewrite for ast::MetaItem {
config: context.config,
};
let item_str = write_list(&item_vec, &fmt)?;
let one_line_budget = shape.offset_left(name.len())?.sub_width(2)?.width;
// 3 = "()" and "]"
let one_line_budget = shape.offset_left(name.len())?.sub_width(3)?.width;
if context.config.indent_style() == IndentStyle::Visual
|| (!item_str.contains('\n') && item_str.len() <= one_line_budget)
{

View file

@ -157,3 +157,7 @@ pub struct HP(pub u8);
// Long `#[doc = "..."]`
struct A { #[doc = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] b: i32 }
// #2647
#[cfg(feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")]
pub fn foo() {}

View file

@ -165,3 +165,9 @@ struct A {
#[doc = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
b: i32,
}
// #2647
#[cfg(
feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)]
pub fn foo() {}