Skip to content

Commit 4633786

Browse files
authored
Merge pull request #2396 from topecongiro/issue-2389
Put attributes and enum variants on different lines
2 parents dfc67a5 + c60d865 commit 4633786

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

src/comment.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle {
134134
}
135135
}
136136

137+
/// Combine `prev_str` and `next_str` into a single `String`. `span` may contain
138+
/// comments between two strings. If there are such comments, then that will be
139+
/// recovered. If `allow_extend` is true and there is no comment between the two
140+
/// strings, then they will be put on a single line as long as doing so does not
141+
/// exceed max width.
137142
pub fn combine_strs_with_missing_comments(
138143
context: &RewriteContext,
139144
prev_str: &str,

src/items.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl<'a> FmtVisitor<'a> {
504504
items = itemize_list_with(0);
505505
}
506506

507-
let shape = self.shape().sub_width(2).unwrap();
507+
let shape = self.shape().sub_width(2)?;
508508
let fmt = ListFormatting {
509509
tactic: DefinitiveListTactic::Vertical,
510510
separator: ",",
@@ -558,14 +558,7 @@ impl<'a> FmtVisitor<'a> {
558558
}
559559
};
560560

561-
combine_strs_with_missing_comments(
562-
&context,
563-
&attrs_str,
564-
&variant_body,
565-
span,
566-
shape,
567-
is_attributes_extendable(&attrs_str),
568-
)
561+
combine_strs_with_missing_comments(&context, &attrs_str, &variant_body, span, shape, false)
569562
}
570563
}
571564

tests/source/enum.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,15 @@ enum WidthOf101 {
180180
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error),
181181
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error),
182182
}
183+
184+
// #2389
185+
pub enum QlError {
186+
#[fail(display = "Parsing error: {}", 0)] LexError(parser::lexer::LexError),
187+
#[fail(display = "Parsing error: {:?}", 0)] ParseError(parser::ParseError),
188+
#[fail(display = "Validation error: {:?}", 0)] ValidationError(Vec<validation::Error>),
189+
#[fail(display = "Execution error: {}", 0)] ExecutionError(String),
190+
// (from, to)
191+
#[fail(display = "Translation error: from {} to {}", 0, 1)] TranslationError(String, String),
192+
// (kind, input, expected)
193+
#[fail(display = "Could not find {}: Found: {}, expected: {:?}", 0, 1, 2)] ResolveError(&'static str, String, Option<String>),
194+
}

tests/target/enum.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ enum EmtpyWithComment {
2424
// C-style enum
2525
enum Bar {
2626
A = 1,
27-
#[someAttr(test)] B = 2, // comment
27+
#[someAttr(test)]
28+
B = 2, // comment
2829
C,
2930
}
3031

@@ -225,11 +226,30 @@ enum AnError {
225226

226227
// #2193
227228
enum WidthOf101 {
228-
#[fail(display = ".....................................................")] Io(::std::io::Error),
229+
#[fail(display = ".....................................................")]
230+
Io(::std::io::Error),
229231
#[fail(display = ".....................................................")]
230232
Ioo(::std::io::Error),
231233
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error),
232234
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
233235
::std::io::Error,
234236
),
235237
}
238+
239+
// #2389
240+
pub enum QlError {
241+
#[fail(display = "Parsing error: {}", 0)]
242+
LexError(parser::lexer::LexError),
243+
#[fail(display = "Parsing error: {:?}", 0)]
244+
ParseError(parser::ParseError),
245+
#[fail(display = "Validation error: {:?}", 0)]
246+
ValidationError(Vec<validation::Error>),
247+
#[fail(display = "Execution error: {}", 0)]
248+
ExecutionError(String),
249+
// (from, to)
250+
#[fail(display = "Translation error: from {} to {}", 0, 1)]
251+
TranslationError(String, String),
252+
// (kind, input, expected)
253+
#[fail(display = "Could not find {}: Found: {}, expected: {:?}", 0, 1, 2)]
254+
ResolveError(&'static str, String, Option<String>),
255+
}

0 commit comments

Comments
 (0)