diff --git a/src/attr.rs b/src/attr.rs index e17b89e5c9e7..83de61c5e253 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -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) { diff --git a/tests/source/attrib.rs b/tests/source/attrib.rs index 552dd2b94429..d5c244a9bf88 100644 --- a/tests/source/attrib.rs +++ b/tests/source/attrib.rs @@ -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() {} diff --git a/tests/target/attrib.rs b/tests/target/attrib.rs index 13ba8bd64db0..45dc4ea8ba95 100644 --- a/tests/target/attrib.rs +++ b/tests/target/attrib.rs @@ -165,3 +165,9 @@ struct A { #[doc = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] b: i32, } + +// #2647 +#[cfg( + feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +)] +pub fn foo() {}