diff --git a/src/comment.rs b/src/comment.rs index 31b6f25bf08..1862dda3581 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -134,6 +134,11 @@ fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle { } } +/// Combine `prev_str` and `next_str` into a single `String`. `span` may contain +/// comments between two strings. If there are such comments, then that will be +/// recovered. If `allow_extend` is true and there is no comment between the two +/// strings, then they will be put on a single line as long as doing so does not +/// exceed max width. pub fn combine_strs_with_missing_comments( context: &RewriteContext, prev_str: &str, diff --git a/src/items.rs b/src/items.rs index fcf545a37bd..d0c5cf361c3 100644 --- a/src/items.rs +++ b/src/items.rs @@ -504,7 +504,7 @@ fn format_variant_list( items = itemize_list_with(0); } - let shape = self.shape().sub_width(2).unwrap(); + let shape = self.shape().sub_width(2)?; let fmt = ListFormatting { tactic: DefinitiveListTactic::Vertical, separator: ",", @@ -558,14 +558,7 @@ fn format_variant(&self, field: &ast::Variant, one_line_width: usize) -> Option< } }; - combine_strs_with_missing_comments( - &context, - &attrs_str, - &variant_body, - span, - shape, - is_attributes_extendable(&attrs_str), - ) + combine_strs_with_missing_comments(&context, &attrs_str, &variant_body, span, shape, false) } } diff --git a/tests/source/enum.rs b/tests/source/enum.rs index f228e5ef646..f3dbae4b84d 100644 --- a/tests/source/enum.rs +++ b/tests/source/enum.rs @@ -180,3 +180,15 @@ enum WidthOf101 { Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error), Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error), } + +// #2389 +pub enum QlError { + #[fail(display = "Parsing error: {}", 0)] LexError(parser::lexer::LexError), + #[fail(display = "Parsing error: {:?}", 0)] ParseError(parser::ParseError), + #[fail(display = "Validation error: {:?}", 0)] ValidationError(Vec), + #[fail(display = "Execution error: {}", 0)] ExecutionError(String), + // (from, to) + #[fail(display = "Translation error: from {} to {}", 0, 1)] TranslationError(String, String), + // (kind, input, expected) + #[fail(display = "Could not find {}: Found: {}, expected: {:?}", 0, 1, 2)] ResolveError(&'static str, String, Option), +} diff --git a/tests/target/enum.rs b/tests/target/enum.rs index 09578d7ec24..de88f610b6a 100644 --- a/tests/target/enum.rs +++ b/tests/target/enum.rs @@ -24,7 +24,8 @@ enum EmtpyWithComment { // C-style enum enum Bar { A = 1, - #[someAttr(test)] B = 2, // comment + #[someAttr(test)] + B = 2, // comment C, } @@ -225,7 +226,8 @@ enum AnError { // #2193 enum WidthOf101 { - #[fail(display = ".....................................................")] Io(::std::io::Error), + #[fail(display = ".....................................................")] + Io(::std::io::Error), #[fail(display = ".....................................................")] Ioo(::std::io::Error), Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error), @@ -233,3 +235,21 @@ enum WidthOf101 { ::std::io::Error, ), } + +// #2389 +pub enum QlError { + #[fail(display = "Parsing error: {}", 0)] + LexError(parser::lexer::LexError), + #[fail(display = "Parsing error: {:?}", 0)] + ParseError(parser::ParseError), + #[fail(display = "Validation error: {:?}", 0)] + ValidationError(Vec), + #[fail(display = "Execution error: {}", 0)] + ExecutionError(String), + // (from, to) + #[fail(display = "Translation error: from {} to {}", 0, 1)] + TranslationError(String, String), + // (kind, input, expected) + #[fail(display = "Could not find {}: Found: {}, expected: {:?}", 0, 1, 2)] + ResolveError(&'static str, String, Option), +}