Skip to content

Commit 3abebf9

Browse files
committed
Apply short function call heuristic to attributes
Closes #2620
1 parent 42f0345 commit 3abebf9

File tree

5 files changed

+72
-10
lines changed

5 files changed

+72
-10
lines changed

src/attr.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ fn format_derive(
9898
argument_shape,
9999
// 10 = "[derive()]", 3 = "()" and "]"
100100
shape.offset_left(10 + prefix.len())?.sub_width(3)?,
101+
None,
101102
)?;
102103

103104
result.push_str(&item_str);
@@ -227,6 +228,7 @@ impl Rewrite for ast::MetaItem {
227228
shape
228229
.offset_left(path.len())?
229230
.sub_width(3 + trailing_comma.len())?,
231+
Some(context.config.width_heuristics().fn_call_width),
230232
)?;
231233

232234
let indent = if item_str.starts_with('\n') {
@@ -264,6 +266,7 @@ fn format_arg_list<I, T, F1, F2, F3>(
264266
context: &RewriteContext,
265267
shape: Shape,
266268
one_line_shape: Shape,
269+
one_line_limit: Option<usize>,
267270
) -> Option<String>
268271
where
269272
I: Iterator<Item = T>,
@@ -284,12 +287,14 @@ where
284287
false,
285288
);
286289
let item_vec = items.collect::<Vec<_>>();
287-
let tactic = ::lists::definitive_tactic(
288-
&item_vec,
289-
ListTactic::HorizontalVertical,
290-
::lists::Separator::Comma,
291-
shape.width,
292-
);
290+
let tactic = if let Some(limit) = one_line_limit {
291+
ListTactic::LimitedHorizontalVertical(limit)
292+
} else {
293+
ListTactic::HorizontalVertical
294+
};
295+
296+
let tactic =
297+
::lists::definitive_tactic(&item_vec, tactic, ::lists::Separator::Comma, shape.width);
293298
let fmt = ListFormatting {
294299
tactic,
295300
separator: ",",

tests/source/attrib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,22 @@ pub fn foo() {}
174174
#[clippy::bar(a, b, c)]
175175
pub fn foo() {}
176176

177+
mod issue_2620 {
178+
#[derive(Debug, StructOpt)]
179+
#[structopt(about = "Display information about the character on FF Logs")]
180+
pub struct Params {
181+
#[structopt(help = "The server the character is on")]
182+
server: String,
183+
#[structopt(help = "The character's first name")]
184+
first_name: String,
185+
#[structopt(help = "The character's last name")]
186+
last_name: String,
187+
#[structopt(
188+
short = "j",
189+
long = "job",
190+
help = "The job to look at",
191+
parse(try_from_str)
192+
)]
193+
job: Option<Job>
194+
}
195+
}

tests/target/attrib.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ struct Foo {
7676
// #1668
7777

7878
/// Default path (*nix)
79-
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
79+
#[cfg(
80+
all(
81+
unix,
82+
not(target_os = "macos"),
83+
not(target_os = "ios"),
84+
not(target_os = "android")
85+
)
86+
)]
8087
fn foo() {
8188
#[cfg(target_os = "freertos")]
8289
match port_id {
@@ -197,3 +204,23 @@ pub fn foo() {}
197204
#[clippy::bar=foo]
198205
#[clippy::bar(a, b, c)]
199206
pub fn foo() {}
207+
208+
mod issue_2620 {
209+
#[derive(Debug, StructOpt)]
210+
#[structopt(about = "Display information about the character on FF Logs")]
211+
pub struct Params {
212+
#[structopt(help = "The server the character is on")]
213+
server: String,
214+
#[structopt(help = "The character's first name")]
215+
first_name: String,
216+
#[structopt(help = "The character's last name")]
217+
last_name: String,
218+
#[structopt(
219+
short = "j",
220+
long = "job",
221+
help = "The job to look at",
222+
parse(try_from_str)
223+
)]
224+
job: Option<Job>,
225+
}
226+
}

tests/target/enum.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ pub enum QlError {
255255
#[fail(display = "Translation error: from {} to {}", 0, 1)]
256256
TranslationError(String, String),
257257
// (kind, input, expected)
258-
#[fail(display = "Could not find {}: Found: {}, expected: {:?}", 0, 1, 2)]
258+
#[fail(
259+
display = "Could not find {}: Found: {}, expected: {:?}",
260+
0,
261+
1,
262+
2
263+
)]
259264
ResolveError(&'static str, String, Option<String>),
260265
}
261266

tests/target/struct-field-attributes.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ fn new_foo() -> Foo {
3939
// #2044
4040
pub enum State {
4141
Closure(
42-
#[cfg_attr(feature = "serde_derive", serde(state_with = "::serialization::closure"))]
42+
#[cfg_attr(
43+
feature = "serde_derive",
44+
serde(state_with = "::serialization::closure")
45+
)]
4346
GcPtr<ClosureData>,
4447
),
4548
}
4649

4750
struct Fields(
48-
#[cfg_attr(feature = "serde_derive", serde(state_with = "::base::serialization::shared"))]
51+
#[cfg_attr(
52+
feature = "serde_derive",
53+
serde(state_with = "::base::serialization::shared")
54+
)]
4955
Arc<Vec<InternedStr>>,
5056
);
5157

0 commit comments

Comments
 (0)