Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8b709c0

Browse files
committed
Add attr_fn_like_width to the width heuristics
It is a bit larger than than `fn_call_width` which we used previously, so fewer attributes get reformatted. Closes rust-lang#2929
1 parent b82949b commit 8b709c0

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl Rewrite for ast::MetaItem {
224224
// 1 = "]"
225225
shape.sub_width(1)?,
226226
self.span,
227-
context.config.width_heuristics().fn_call_width,
227+
context.config.width_heuristics().attr_fn_like_width,
228228
Some(if has_trailing_comma {
229229
SeparatorTactic::Always
230230
} else {

src/config/options.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ pub struct WidthHeuristics {
316316
// Maximum width of the args of a function call before falling back
317317
// to vertical formatting.
318318
pub fn_call_width: usize,
319+
// Maximum width of the args of a function-like attributes before falling
320+
// back to vertical formatting.
321+
pub attr_fn_like_width: usize,
319322
// Maximum width in the body of a struct lit before falling back to
320323
// vertical formatting.
321324
pub struct_lit_width: usize,
@@ -337,6 +340,7 @@ impl WidthHeuristics {
337340
pub fn null() -> WidthHeuristics {
338341
WidthHeuristics {
339342
fn_call_width: usize::max_value(),
343+
attr_fn_like_width: usize::max_value(),
340344
struct_lit_width: 0,
341345
struct_variant_width: 0,
342346
array_width: usize::max_value(),
@@ -348,6 +352,7 @@ impl WidthHeuristics {
348352
pub fn set(max_width: usize) -> WidthHeuristics {
349353
WidthHeuristics {
350354
fn_call_width: max_width,
355+
attr_fn_like_width: max_width,
351356
struct_lit_width: max_width,
352357
struct_variant_width: max_width,
353358
array_width: max_width,
@@ -368,6 +373,7 @@ impl WidthHeuristics {
368373
};
369374
WidthHeuristics {
370375
fn_call_width: (60.0 * max_width_ratio).round() as usize,
376+
attr_fn_like_width: (70.0 * max_width_ratio).round() as usize,
371377
struct_lit_width: (18.0 * max_width_ratio).round() as usize,
372378
struct_variant_width: (35.0 * max_width_ratio).round() as usize,
373379
array_width: (60.0 * max_width_ratio).round() as usize,

tests/source/enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub enum QlError {
189189
// (from, to)
190190
#[fail(display = "Translation error: from {} to {}", 0, 1)] TranslationError(String, String),
191191
// (kind, input, expected)
192-
#[fail(display = "Could not find {}: Found: {}, expected: {:?}", 0, 1, 2)] ResolveError(&'static str, String, Option<String>),
192+
#[fail(display = "aaaaaaaaaaaaCould not find {}: Found: {}, expected: {:?}", 0, 1, 2)] ResolveError(&'static str, String, Option<String>),
193193
}
194194

195195
// #2594

tests/target/enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub enum QlError {
255255
TranslationError(String, String),
256256
// (kind, input, expected)
257257
#[fail(
258-
display = "Could not find {}: Found: {}, expected: {:?}",
258+
display = "aaaaaaaaaaaaCould not find {}: Found: {}, expected: {:?}",
259259
0, 1, 2
260260
)]
261261
ResolveError(&'static str, String, Option<String>),

0 commit comments

Comments
 (0)