diff --git a/src/closures.rs b/src/closures.rs index bb85b62dc86..bd41d4a1c19 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -3,7 +3,7 @@ use syntax::{ast, ptr}; use crate::attr::get_attrs_from_stmt; use crate::config::lists::*; -use crate::config::{IndentStyle, SeparatorTactic, Version}; +use crate::config::{IndentStyle, SeparatorTactic}; use crate::expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond}; use crate::items::{span_hi_for_param, span_lo_for_param}; use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; @@ -409,19 +409,19 @@ fn is_block_closure_forced(context: &RewriteContext<'_>, expr: &ast::Expr) -> bo if context.inside_macro() { false } else { - is_block_closure_forced_inner(expr, context.config.version()) + is_block_closure_forced_inner(expr) } } -fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool { +fn is_block_closure_forced_inner(expr: &ast::Expr) -> bool { match expr.kind { ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) => true, - ast::ExprKind::Loop(..) if version == Version::Two => true, + ast::ExprKind::Loop(..) => true, ast::ExprKind::AddrOf(_, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) - | ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, version), + | ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr), _ => false, } } diff --git a/src/comment.rs b/src/comment.rs index c5937b9e2ab..47246c4ed65 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -10,7 +10,8 @@ use crate::rewrite::RewriteContext; use crate::shape::{Indent, Shape}; use crate::string::{rewrite_string, StringFormat}; use crate::utils::{ - count_newlines, first_line_width, last_line_width, trim_left_preserve_layout, unicode_str_width, + count_newlines, first_line_width, last_line_width, tab_to_spaces, trim_left_preserve_layout, + unicode_str_width, }; use crate::{ErrorKind, FormattingError}; @@ -1162,14 +1163,6 @@ impl FullCodeCharKind { self == FullCodeCharKind::InStringCommented || self == FullCodeCharKind::StartStringCommented } - - fn to_codecharkind(self) -> CodeCharKind { - if self.is_comment() { - CodeCharKind::Comment - } else { - CodeCharKind::Normal - } - } } impl CharClasses @@ -1484,16 +1477,31 @@ impl<'a> Iterator for UngroupedCommentCodeSlices<'a> { /// functional text. Line style comments contain their ending newlines. pub(crate) struct CommentCodeSlices<'a> { slice: &'a str, - last_slice_kind: CodeCharKind, - last_slice_end: usize, + ungrouped_code_slices: MultiPeek>, + offset: Option, + tab_spaces: usize, } impl<'a> CommentCodeSlices<'a> { pub(crate) fn new(slice: &'a str) -> CommentCodeSlices<'a> { CommentCodeSlices { slice, - last_slice_kind: CodeCharKind::Comment, - last_slice_end: 0, + tab_spaces: 4, + ungrouped_code_slices: multipeek(UngroupedCommentCodeSlices::new(slice)), + offset: None, + } + } + + pub(crate) fn with_offset( + slice: &'a str, + offset: usize, + tab_spaces: usize, + ) -> CommentCodeSlices<'a> { + CommentCodeSlices { + slice, + tab_spaces, + ungrouped_code_slices: multipeek(UngroupedCommentCodeSlices::new(slice)), + offset: Some(offset).filter(|o| *o != 0), } } } @@ -1502,59 +1510,50 @@ impl<'a> Iterator for CommentCodeSlices<'a> { type Item = (CodeCharKind, usize, &'a str); fn next(&mut self) -> Option { - if self.last_slice_end == self.slice.len() { - return None; - } - - let mut sub_slice_end = self.last_slice_end; - let mut first_whitespace = None; - let subslice = &self.slice[self.last_slice_end..]; - let mut iter = CharClasses::new(subslice.char_indices()); - - for (kind, (i, c)) in &mut iter { - let is_comment_connector = self.last_slice_kind == CodeCharKind::Normal - && &subslice[..2] == "//" - && [' ', '\t'].contains(&c); - - if is_comment_connector && first_whitespace.is_none() { - first_whitespace = Some(i); + let first_chunk = self.ungrouped_code_slices.next()?; + if first_chunk.0 == CodeCharKind::Normal { + if !first_chunk.2.trim().is_empty() { + self.offset = Some(last_line_width(first_chunk.2)).filter(|o| *o != 0); } + return Some(first_chunk); + } - if kind.to_codecharkind() == self.last_slice_kind && !is_comment_connector { - let last_index = match first_whitespace { - Some(j) => j, - None => i, - }; - sub_slice_end = self.last_slice_end + last_index; - break; - } + let mut comment_end_index = first_chunk.1 + first_chunk.2.len(); + while let Some(&(k, i, s)) = self.ungrouped_code_slices.peek() { + match k { + CodeCharKind::Comment if self.offset.is_none() => { + comment_end_index = i + s.len(); + self.ungrouped_code_slices.next()?; + } + CodeCharKind::Comment => break, + CodeCharKind::Normal if s.trim().is_empty() && count_newlines(s) == 0 => { + let indent_width = tab_to_spaces(s, self.tab_spaces); + if self.offset.map_or(false, |comment_offset| { + !(indent_width < comment_offset + 2 && comment_offset < indent_width + 2) + }) { + break; + } - if !is_comment_connector { - first_whitespace = None; + match self.ungrouped_code_slices.peek() { + Some((CodeCharKind::Comment, index, s)) => { + comment_end_index = index + s.len(); + // Advance twice. + self.ungrouped_code_slices.next()?; + self.ungrouped_code_slices.next()?; + } + _ => break, + } + } + CodeCharKind::Normal => break, } } - if let (None, true) = (iter.next(), sub_slice_end == self.last_slice_end) { - // This was the last subslice. - sub_slice_end = match first_whitespace { - Some(i) => self.last_slice_end + i, - None => self.slice.len(), - }; - } - - let kind = match self.last_slice_kind { - CodeCharKind::Comment => CodeCharKind::Normal, - CodeCharKind::Normal => CodeCharKind::Comment, - }; - let res = ( - kind, - self.last_slice_end, - &self.slice[self.last_slice_end..sub_slice_end], - ); - self.last_slice_end = sub_slice_end; - self.last_slice_kind = kind; - - Some(res) + let comment_start_index = first_chunk.1; + Some(( + CodeCharKind::Comment, + comment_start_index, + &self.slice[comment_start_index..comment_end_index], + )) } } @@ -1728,7 +1727,6 @@ mod test { let input = "// comment\n test();"; let mut iter = CommentCodeSlices::new(input); - assert_eq!((CodeCharKind::Normal, 0, ""), iter.next().unwrap()); assert_eq!( (CodeCharKind::Comment, 0, "// comment\n"), iter.next().unwrap() @@ -1742,18 +1740,67 @@ mod test { #[test] fn comment_code_slices_three() { - let input = "1 // comment\n // comment2\n\n"; + let input = "1 // comment\n // comment2\n\n"; let mut iter = CommentCodeSlices::new(input); assert_eq!((CodeCharKind::Normal, 0, "1 "), iter.next().unwrap()); assert_eq!( - (CodeCharKind::Comment, 2, "// comment\n // comment2\n"), + (CodeCharKind::Comment, 2, "// comment\n // comment2\n"), + iter.next().unwrap() + ); + assert_eq!((CodeCharKind::Normal, 27, "\n"), iter.next().unwrap()); + assert_eq!(None, iter.next()); + } + + #[test] + fn comment_code_slices_four() { + let input = r#" +if x == 3 { + x = 4; +} // if x == 3 +// end of block +"#; + let mut iter = CommentCodeSlices::new(input); + + assert_eq!( + ( + CodeCharKind::Normal, + 0, + r#" +if x == 3 { + x = 4; +} "# + ), + iter.next().unwrap() + ); + assert_eq!( + (CodeCharKind::Comment, 26, "// if x == 3\n",), + iter.next().unwrap() + ); + assert_eq!( + (CodeCharKind::Comment, 39, "// end of block\n"), iter.next().unwrap() ); - assert_eq!((CodeCharKind::Normal, 29, "\n"), iter.next().unwrap()); assert_eq!(None, iter.next()); } + #[test] + fn comment_code_slices_five() { + let input = "1 // comment\r\n\r\n // comment2\r\n"; + let mut iter = CommentCodeSlices::new(input); + + assert_eq!((CodeCharKind::Normal, 0, "1 "), iter.next().unwrap()); + assert_eq!( + (CodeCharKind::Comment, 2, "// comment\r\n"), + iter.next().unwrap() + ); + assert_eq!((CodeCharKind::Normal, 14, "\r\n ",), iter.next().unwrap()); + assert_eq!( + (CodeCharKind::Comment, 18, "// comment2\r\n"), + iter.next().unwrap() + ); + assert_eq!(None, iter.next()); + } #[test] #[rustfmt::skip] fn format_doc_comments() { diff --git a/src/expr.rs b/src/expr.rs index 186425d70ee..181a1a61552 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -13,7 +13,7 @@ use crate::comment::{ rewrite_comment, rewrite_missing_comment, CharClasses, FindUncommented, }; use crate::config::lists::*; -use crate::config::{Config, ControlBraceStyle, IndentStyle, Version}; +use crate::config::{Config, ControlBraceStyle, IndentStyle}; use crate::lists::{ definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, struct_lit_tactic, write_list, ListFormatting, Separator, @@ -1238,7 +1238,6 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) -> .lines() .dropping_back(1) .all(|line| line.ends_with('\\')) - && context.config.version() == Version::Two { return Some(string_lit.to_owned()); } else { diff --git a/src/items.rs b/src/items.rs index cbeb34ce9f5..1ecbdbceb9e 100644 --- a/src/items.rs +++ b/src/items.rs @@ -16,7 +16,7 @@ use crate::comment::{ FindUncommented, }; use crate::config::lists::*; -use crate::config::{BraceStyle, Config, IndentStyle, Version}; +use crate::config::{BraceStyle, Config, IndentStyle}; use crate::expr::{ is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_expr, rewrite_assign_rhs_with, RhsTactics, @@ -860,15 +860,7 @@ fn format_impl_ref_and_type( result.push_str(format_defaultness(defaultness)); result.push_str(format_unsafety(unsafety)); - let shape = if context.config.version() == Version::Two { - Shape::indented(offset + last_line_width(&result), context.config) - } else { - generics_shape_from_config( - context.config, - Shape::indented(offset + last_line_width(&result), context.config), - 0, - )? - }; + let shape = Shape::indented(offset + last_line_width(&result), context.config); let generics_str = rewrite_generics(context, "impl", generics, shape)?; result.push_str(&generics_str); @@ -1940,9 +1932,7 @@ impl Rewrite for ast::FunctionRetTy { match *self { ast::FunctionRetTy::Default(_) => Some(String::new()), ast::FunctionRetTy::Ty(ref ty) => { - if context.config.version() == Version::One - || context.config.indent_style() == IndentStyle::Visual - { + if context.config.indent_style() == IndentStyle::Visual { let inner_width = shape.width.checked_sub(3)?; return ty .rewrite(context, Shape::legacy(inner_width, shape.indent + 3)) @@ -2296,22 +2286,15 @@ fn rewrite_fn_base( .last() .map_or(false, |last_line| last_line.contains("//")); - if context.config.version() == Version::Two { - if closing_paren_overflow_max_width { - result.push(')'); - result.push_str(&indent.to_string_with_newline(context.config)); - no_params_and_over_max_width = true; - } else if params_last_line_contains_comment { - result.push_str(&indent.to_string_with_newline(context.config)); - result.push(')'); - no_params_and_over_max_width = true; - } else { - result.push(')'); - } + if closing_paren_overflow_max_width { + result.push(')'); + result.push_str(&indent.to_string_with_newline(context.config)); + no_params_and_over_max_width = true; + } else if params_last_line_contains_comment { + result.push_str(&indent.to_string_with_newline(context.config)); + result.push(')'); + no_params_and_over_max_width = true; } else { - if closing_paren_overflow_max_width || params_last_line_contains_comment { - result.push_str(&indent.to_string_with_newline(context.config)); - } result.push(')'); } } @@ -2339,9 +2322,7 @@ fn rewrite_fn_base( } }; let ret_shape = if ret_should_indent { - if context.config.version() == Version::One - || context.config.indent_style() == IndentStyle::Visual - { + if context.config.indent_style() == IndentStyle::Visual { let indent = if param_str.is_empty() { // Aligning with non-existent params looks silly. force_new_line_for_brace = true; @@ -2372,11 +2353,7 @@ fn rewrite_fn_base( ret_shape } } else { - if context.config.version() == Version::Two { - if !param_str.is_empty() || !no_params_and_over_max_width { - result.push(' '); - } - } else { + if !param_str.is_empty() || !no_params_and_over_max_width { result.push(' '); } @@ -2698,20 +2675,6 @@ fn rewrite_generics( overflow::rewrite_with_angle_brackets(context, ident, params, shape, generics.span) } -fn generics_shape_from_config(config: &Config, shape: Shape, offset: usize) -> Option { - match config.indent_style() { - IndentStyle::Visual => shape.visual_indent(1 + offset).sub_width(offset + 2), - IndentStyle::Block => { - // 1 = "," - shape - .block() - .block_indent(config.tab_spaces()) - .with_max_width(config) - .sub_width(1) - } - } -} - fn rewrite_where_clause_rfc_style( context: &RewriteContext<'_>, where_clause: &ast::WhereClause, diff --git a/src/lib.rs b/src/lib.rs index b68edfd6894..651007732eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -328,7 +328,7 @@ fn format_code_block(code_snippet: &str, config: &Config) -> Option Option FmtVisitor<'a> { ); (lf_count, crlf_count, within_file_lines_range) }; - for (kind, offset, subslice) in CommentCodeSlices::new(snippet) { + let last_line_offset = if last_line_contains_single_line_comment(&self.buffer) { + 0 + } else { + last_line_width(&&self.buffer) + }; + for (kind, offset, subslice) in + CommentCodeSlices::with_offset(snippet, last_line_offset, self.config.tab_spaces()) + { debug!("{:?}: {:?}", kind, subslice); let (lf_count, crlf_count, within_file_lines_range) = @@ -236,7 +244,6 @@ impl<'a> FmtVisitor<'a> { .next(); let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c)); - let mut on_same_line = false; let comment_indent = if fix_indent { if let Some('{') = last_char { @@ -245,13 +252,6 @@ impl<'a> FmtVisitor<'a> { let indent_str = self.block_indent.to_string(self.config); self.push_str(&indent_str); self.block_indent - } else if self.config.version() == Version::Two && !snippet.starts_with('\n') { - // The comment appears on the same line as the previous formatted code. - // Assuming that comment is logically associated with that code, we want to keep it on - // the same level and avoid mixing it with possible other comment. - on_same_line = true; - self.push_str(" "); - self.block_indent } else { self.push_str(" "); Indent::from_width(self.config, last_line_width(&self.buffer)) @@ -262,34 +262,9 @@ impl<'a> FmtVisitor<'a> { self.config.max_width() - self.block_indent.width(), ); let comment_shape = Shape::legacy(comment_width, comment_indent); - - if on_same_line { - match subslice.find("\n") { - None => { - self.push_str(subslice); - } - Some(offset) if offset + 1 == subslice.len() => { - self.push_str(&subslice[..offset]); - } - Some(offset) => { - // keep first line as is: if it were too long and wrapped, it may get mixed - // with the other lines. - let first_line = &subslice[..offset]; - self.push_str(first_line); - self.push_str(&comment_indent.to_string_with_newline(self.config)); - - let other_lines = &subslice[offset + 1..]; - let comment_str = - rewrite_comment(other_lines, false, comment_shape, self.config) - .unwrap_or_else(|| String::from(other_lines)); - self.push_str(&comment_str); - } - } - } else { - let comment_str = rewrite_comment(subslice, false, comment_shape, self.config) - .unwrap_or_else(|| String::from(subslice)); - self.push_str(&comment_str); - } + let comment_str = rewrite_comment(subslice, false, comment_shape, self.config) + .unwrap_or_else(|| String::from(subslice)); + self.push_str(&comment_str); status.last_wspace = None; status.line_start = offset + subslice.len(); diff --git a/src/overflow.rs b/src/overflow.rs index 3b85c0b8e57..7b13bd4936f 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -9,7 +9,6 @@ use syntax::{ast, ptr}; use crate::closures; use crate::config::lists::*; -use crate::config::Version; use crate::expr::{ can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr, rewrite_cond, @@ -473,9 +472,7 @@ impl<'a> Context<'a> { self.context.force_one_line_chain.replace(true); } Some(OverflowableItem::MacroArg(MacroArg::Expr(expr))) - if !combine_arg_with_callee - && is_method_call(expr) - && self.context.config.version() == Version::Two => + if !combine_arg_with_callee && is_method_call(expr) => { self.context.force_one_line_chain.replace(true); } @@ -660,15 +657,8 @@ impl<'a> Context<'a> { ); result.push_str(self.ident); result.push_str(prefix); - let force_single_line = if self.context.config.version() == Version::Two { - !self.context.use_block_indent() || (is_extendable && extend_width <= shape.width) - } else { - // 2 = `()` - let fits_one_line = items_str.len() + 2 <= shape.width; - !self.context.use_block_indent() - || (self.context.inside_macro() && !items_str.contains('\n') && fits_one_line) - || (is_extendable && extend_width <= shape.width) - }; + let force_single_line = + !self.context.use_block_indent() || (is_extendable && extend_width <= shape.width); if force_single_line { result.push_str(items_str); } else { diff --git a/src/stmt.rs b/src/stmt.rs index a7aa6de0b13..36b46988699 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -2,7 +2,6 @@ use syntax::ast; use syntax_pos::Span; use crate::comment::recover_comment_removed; -use crate::config::Version; use crate::expr::{format_expr, ExprType}; use crate::rewrite::{Rewrite, RewriteContext}; use crate::shape::Shape; @@ -71,7 +70,7 @@ impl<'a> Stmt<'a> { impl<'a> Rewrite for Stmt<'a> { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { - let expr_type = if context.config.version() == Version::Two && self.is_last_expr() { + let expr_type = if self.is_last_expr() { ExprType::SubExpression } else { ExprType::Statement diff --git a/src/types.rs b/src/types.rs index b7ca3e96a51..017e4ca9f51 100644 --- a/src/types.rs +++ b/src/types.rs @@ -6,7 +6,7 @@ use syntax::source_map::{BytePos, Span, DUMMY_SP}; use syntax::symbol::kw; use crate::config::lists::*; -use crate::config::{IndentStyle, TypeDensity, Version}; +use crate::config::{IndentStyle, TypeDensity}; use crate::expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType}; use crate::lists::{ definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator, @@ -678,9 +678,7 @@ impl Rewrite for ast::Ty { // FIXME: we drop any comments here, even though it's a silly place to put // comments. ast::TyKind::Paren(ref ty) => { - if context.config.version() == Version::One - || context.config.indent_style() == IndentStyle::Visual - { + if context.config.indent_style() == IndentStyle::Visual { let budget = shape.width.checked_sub(2)?; return ty .rewrite(context, Shape::legacy(budget, shape.indent + 1)) @@ -745,11 +743,7 @@ impl Rewrite for ast::Ty { if it.is_empty() { return Some("impl".to_owned()); } - let rw = if context.config.version() == Version::One { - it.rewrite(context, shape) - } else { - join_bounds(context, shape, it, false) - }; + let rw = join_bounds(context, shape, it, false); rw.map(|it_str| { let space = if it_str.is_empty() { "" } else { " " }; format!("impl{}{}", space, it_str) diff --git a/src/utils.rs b/src/utils.rs index 6f68f205a93..05de4b53ca2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,7 +12,7 @@ use syntax_pos::ExpnId; use unicode_width::UnicodeWidthStr; use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses}; -use crate::config::{Config, Version}; +use crate::config::Config; use crate::rewrite::RewriteContext; use crate::shape::{Indent, Shape}; @@ -568,8 +568,7 @@ pub(crate) fn trim_left_preserve_layout( // just InString{Commented} in order to allow the start of a string to be indented let new_veto_trim_value = (kind == FullCodeCharKind::InString - || (config.version() == Version::Two - && kind == FullCodeCharKind::InStringCommented)) + || kind == FullCodeCharKind::InStringCommented) && !line.ends_with('\\'); let line = if veto_trim || new_veto_trim_value { veto_trim = new_veto_trim_value; @@ -583,11 +582,7 @@ pub(crate) fn trim_left_preserve_layout( // Because there is a veto against trimming and indenting lines within a string, // such lines should not be taken into account when computing the minimum. match kind { - FullCodeCharKind::InStringCommented | FullCodeCharKind::EndStringCommented - if config.version() == Version::Two => - { - None - } + FullCodeCharKind::InStringCommented | FullCodeCharKind::EndStringCommented => None, FullCodeCharKind::InString | FullCodeCharKind::EndString => None, _ => prefix_space_width, } @@ -618,8 +613,8 @@ pub(crate) fn trim_left_preserve_layout( /// Based on the given line, determine if the next line can be indented or not. /// This allows to preserve the indentation of multi-line literals. -pub(crate) fn indent_next_line(kind: FullCodeCharKind, _line: &str, config: &Config) -> bool { - !(kind.is_string() || (config.version() == Version::Two && kind.is_commented_string())) +pub(crate) fn indent_next_line(kind: FullCodeCharKind) -> bool { + !(kind.is_string() || kind.is_commented_string()) } pub(crate) fn is_empty_line(s: &str) -> bool { @@ -638,6 +633,12 @@ fn get_prefix_space_width(config: &Config, s: &str) -> usize { width } +pub(crate) fn tab_to_spaces(s: &str, tab_spaces: usize) -> usize { + s.chars() + .map(|s| if s == '\t' { tab_spaces } else { 1 }) + .sum() +} + pub(crate) trait NodeIdExt { fn root() -> Self; } diff --git a/src/visitor.rs b/src/visitor.rs index f1dc6a5d370..ad1ec309371 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -6,7 +6,6 @@ use syntax::{ast, visit}; use crate::attr::*; use crate::comment::{rewrite_comment, CodeCharKind, CommentCodeSlices}; -use crate::config::Version; use crate::config::{BraceStyle, Config}; use crate::coverage::transform_missing_snippet; use crate::items::{ @@ -24,8 +23,9 @@ use crate::spanned::Spanned; use crate::stmt::Stmt; use crate::syntux::session::ParseSess; use crate::utils::{ - self, contains_skip, count_newlines, depr_skip_annotation, inner_attributes, last_line_width, - mk_sp, ptr_vec_to_ref_vec, rewrite_ident, stmt_expr, + self, contains_skip, count_newlines, depr_skip_annotation, inner_attributes, + last_line_contains_single_line_comment, last_line_width, mk_sp, ptr_vec_to_ref_vec, + rewrite_ident, stmt_expr, }; use crate::{ErrorKind, FormatReport, FormattingError}; @@ -240,107 +240,96 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { fn close_block(&mut self, span: Span, unindent_comment: bool) { let config = self.config; - let mut last_hi = span.lo(); - let mut unindented = false; - let mut prev_ends_with_newline = false; - let mut extra_newline = false; + let mut prev_kind = CodeCharKind::Normal; + let mut newline_inserted = false; let skip_normal = |s: &str| { let trimmed = s.trim(); - trimmed.is_empty() || trimmed.chars().all(|c| c == ';') + !trimmed.is_empty() && trimmed.chars().all(|c| c == ';') }; - for (kind, offset, sub_slice) in CommentCodeSlices::new(self.snippet(span)) { + let last_line_offset = if last_line_contains_single_line_comment(&self.buffer) { + 0 + } else { + last_line_width(&self.buffer) + 1 + }; + + if unindent_comment { + self.block_indent = self.block_indent.block_unindent(config); + } + + let mut iter = CommentCodeSlices::with_offset( + self.snippet(span), + last_line_offset, + self.config.tab_spaces(), + ) + .peekable(); + while let Some((kind, offset, sub_slice)) = iter.next() { let sub_slice = transform_missing_snippet(config, sub_slice); debug!("close_block: {:?} {:?} {:?}", kind, offset, sub_slice); match kind { CodeCharKind::Comment => { - if !unindented && unindent_comment { - unindented = true; - self.block_indent = self.block_indent.block_unindent(config); - } - let span_in_between = mk_sp(last_hi, span.lo() + BytePos::from_usize(offset)); - let snippet_in_between = self.snippet(span_in_between); - let mut comment_on_same_line = !snippet_in_between.contains("\n"); - - let mut comment_shape = - Shape::indented(self.block_indent, config).comment(config); - if self.config.version() == Version::Two && comment_on_same_line { - self.push_str(" "); - // put the first line of the comment on the same line as the - // block's last line - match sub_slice.find("\n") { - None => { - self.push_str(&sub_slice); - } - Some(offset) if offset + 1 == sub_slice.len() => { - self.push_str(&sub_slice[..offset]); - } - Some(offset) => { - let first_line = &sub_slice[..offset]; - self.push_str(first_line); - - // put the other lines below it, shaping it as needed - let other_lines = &sub_slice[offset + 1..]; - if !other_lines.trim().is_empty() { - self.push_str( - &self.block_indent.to_string_with_newline(config), - ); - let comment_str = - rewrite_comment(other_lines, false, comment_shape, config); - match comment_str { - Some(ref s) => self.push_str(s), - None => self.push_str(other_lines), - } - } - } - } + let comment_shape = if newline_inserted { + self.shape().comment(self.config) } else { - let sub_slice = sub_slice.trim(); - if comment_on_same_line { - // 1 = a space before `//` - let offset_len = 1 + last_line_width(&self.buffer) - .saturating_sub(self.block_indent.width()); - match comment_shape - .visual_indent(offset_len) - .sub_width(offset_len) - { - Some(shp) => comment_shape = shp, - None => comment_on_same_line = false, - } - }; - - if comment_on_same_line { - self.push_str(" "); - } else { - if count_newlines(snippet_in_between) >= 2 || extra_newline { - self.push_str("\n"); - } - self.push_str(&self.block_indent.to_string_with_newline(config)); - } - - let comment_str = rewrite_comment(&sub_slice, false, comment_shape, config); - match comment_str { - Some(ref s) => self.push_str(s), - None => self.push_str(&sub_slice), + Shape { + width: self.config.comment_width(), + indent: Indent::from_width(self.config, last_line_offset), + offset: 0, } + }; + let comment_str = + rewrite_comment(sub_slice.trim(), false, comment_shape, config); + if self + .buffer + .chars() + .last() + .map_or(false, |c| !c.is_whitespace() && c != '/') + { + self.push_str(" "); + } + match comment_str { + Some(ref s) => self.push_str(s), + None => self.push_str(&sub_slice), } } CodeCharKind::Normal if skip_normal(&sub_slice) => { - extra_newline = prev_ends_with_newline && sub_slice.contains('\n'); + prev_kind = kind; continue; } CodeCharKind::Normal => { + let prev_is_comment = prev_kind == CodeCharKind::Comment; + prev_kind = kind; + + if iter.peek().is_none() { + continue; + } + + match count_newlines(&sub_slice) { + 0 if !prev_is_comment + || !last_line_contains_single_line_comment(&self.buffer) => + { + self.push_str(" "); + continue; + } + 0 => (), + 1 if prev_is_comment + && last_line_contains_single_line_comment(&self.buffer) => + { + self.push_str("\n") + } + 1 => (), + _ => self.push_str("\n"), + } + newline_inserted = true; + self.push_str(&self.block_indent.to_string_with_newline(config)); - self.push_str(sub_slice.trim()); } } - prev_ends_with_newline = sub_slice.ends_with('\n'); - extra_newline = false; - last_hi = span.lo() + BytePos::from_usize(offset + sub_slice.len()); + prev_kind = kind; } - if unindented { + if unindent_comment { self.block_indent = self.block_indent.block_indent(self.config); } self.block_indent = self.block_indent.block_unindent(self.config); diff --git a/tests/source/configs/indent_style/block_trailing_comma_call/one.rs b/tests/source/configs/indent_style/block_trailing_comma_call/one.rs deleted file mode 100644 index 6d48ea742fc..00000000000 --- a/tests/source/configs/indent_style/block_trailing_comma_call/one.rs +++ /dev/null @@ -1,9 +0,0 @@ -// rustfmt-version: One -// rustfmt-error_on_line_overflow: false -// rustfmt-indent_style: Block - -// rustfmt should not add trailing comma when rewriting macro. See #1528. -fn a() { - panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"); - foo(a, oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt()); -} diff --git a/tests/source/fn-single-line/version_one.rs b/tests/source/fn-single-line/version_one.rs deleted file mode 100644 index 469ab621567..00000000000 --- a/tests/source/fn-single-line/version_one.rs +++ /dev/null @@ -1,80 +0,0 @@ -// rustfmt-fn_single_line: true -// rustfmt-version: One -// Test single-line functions. - -fn foo_expr() { - 1 -} - -fn foo_stmt() { - foo(); -} - -fn foo_decl_local() { - let z = 5; - } - -fn foo_decl_item(x: &mut i32) { - x = 3; -} - - fn empty() { - -} - -fn foo_return() -> String { - "yay" -} - -fn foo_where() -> T where T: Sync { - let x = 2; -} - -fn fooblock() { - { - "inner-block" - } -} - -fn fooblock2(x: i32) { - let z = match x { - _ => 2, - }; -} - -fn comment() { - // this is a test comment - 1 -} - -fn comment2() { - // multi-line comment - let z = 2; - 1 -} - -fn only_comment() { - // Keep this here -} - -fn aaaaaaaaaaaaaaaaa_looooooooooooooooooooooong_name() { - let z = "aaaaaaawwwwwwwwwwwwwwwwwwwwwwwwwwww"; -} - -fn lots_of_space () { - 1 -} - -fn mac() -> Vec { vec![] } - -trait CoolTypes { - fn dummy(&self) { - } -} - -trait CoolerTypes { fn dummy(&self) { -} -} - -fn Foo() where T: Bar { -} diff --git a/tests/source/issue-2179/one.rs b/tests/source/issue-2179/one.rs deleted file mode 100644 index d23947931ff..00000000000 --- a/tests/source/issue-2179/one.rs +++ /dev/null @@ -1,36 +0,0 @@ -// rustfmt-version: One -// rustfmt-error_on_line_overflow: false - -fn issue_2179() { - let (opts, rustflags, clear_env_rust_log) = - { - // We mustn't lock configuration for the whole build process - let rls_config = rls_config.lock().unwrap(); - - let opts = CargoOptions::new(&rls_config); - trace!("Cargo compilation options:\n{:?}", opts); - let rustflags = prepare_cargo_rustflags(&rls_config); - - // Warn about invalid specified bin target or package depending on current mode - // TODO: Return client notifications along with diagnostics to inform the user - if !rls_config.workspace_mode { - let cur_pkg_targets = ws.current().unwrap().targets(); - - if let &Some(ref build_bin) = rls_config.build_bin.as_ref() { - let mut bins = cur_pkg_targets.iter().filter(|x| x.is_bin()); - if let None = bins.find(|x| x.name() == build_bin) { - warn!("cargo - couldn't find binary `{}` specified in `build_bin` configuration", build_bin); - } - } - } else { - for package in &opts.package { - if let None = ws.members().find(|x| x.name() == package) { - warn!("cargo - couldn't find member package `{}` specified in `analyze_package` configuration", package); - } - } - } - - (opts, rustflags, rls_config.clear_env_rust_log) - }; - -} diff --git a/tests/source/issue-3213/version_one.rs b/tests/source/issue-3213/version_one.rs deleted file mode 100644 index f9f4cab55e3..00000000000 --- a/tests/source/issue-3213/version_one.rs +++ /dev/null @@ -1,9 +0,0 @@ -// rustfmt-version: One - -fn foo() { - match 0 { - 0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, - 1 => AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, - _ => "", - }; -} diff --git a/tests/source/issue-3270/one.rs b/tests/source/issue-3270/one.rs deleted file mode 100644 index 3c2e27e2293..00000000000 --- a/tests/source/issue-3270/one.rs +++ /dev/null @@ -1,12 +0,0 @@ -// rustfmt-version: One - -pub fn main() { - /* let s = String::from( - " -hello -world -", - ); */ - - assert_eq!(s, "\nhello\nworld\n"); -} diff --git a/tests/source/issue-3272/v1.rs b/tests/source/issue-3272/v1.rs deleted file mode 100644 index f4c1b7c992b..00000000000 --- a/tests/source/issue-3272/v1.rs +++ /dev/null @@ -1,15 +0,0 @@ -// rustfmt-version: One - -fn main() { - assert!(HAYSTACK - .par_iter() - .find_any(|&&x| x[0] % 1000 == 999) - .is_some()); - - assert( - HAYSTACK - .par_iter() - .find_any(|&&x| x[0] % 1000 == 999) - .is_some(), - ); -} diff --git a/tests/source/issue-3278/version_one.rs b/tests/source/issue-3278/version_one.rs deleted file mode 100644 index 580679fbae3..00000000000 --- a/tests/source/issue-3278/version_one.rs +++ /dev/null @@ -1,8 +0,0 @@ -// rustfmt-version: One - -pub fn parse_conditional<'a, I: 'a>( -) -> impl Parser + 'a -where - I: Stream, -{ -} diff --git a/tests/source/issue-3701/one.rs b/tests/source/issue-3701/one.rs deleted file mode 100644 index a7f0bd3aa17..00000000000 --- a/tests/source/issue-3701/one.rs +++ /dev/null @@ -1,12 +0,0 @@ -// rustfmt-version: One - -fn build_sorted_static_get_entry_names( - mut entries: Vec<(u8, &'static str)>, -) -> (impl Fn( - AlphabeticalTraversal, - Box>, -) -> BoxFuture<'static, Result, Status>> - + Send - + Sync - + 'static) { -} diff --git a/tests/source/issue-3840/version-one_hard-tabs.rs b/tests/source/issue-3840/version-one_hard-tabs.rs deleted file mode 100644 index bf7ea7da0eb..00000000000 --- a/tests/source/issue-3840/version-one_hard-tabs.rs +++ /dev/null @@ -1,15 +0,0 @@ -// rustfmt-hard_tabs: true - -impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter -{ - type Ctx = C; - type Event = Vec; -} - -mod foo { - impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter - { - type Ctx = C; - type Event = Vec; - } -} diff --git a/tests/source/issue-3840/version-one_soft-tabs.rs b/tests/source/issue-3840/version-one_soft-tabs.rs deleted file mode 100644 index 3fc26224d50..00000000000 --- a/tests/source/issue-3840/version-one_soft-tabs.rs +++ /dev/null @@ -1,13 +0,0 @@ -impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter -{ - type Ctx = C; - type Event = Vec; -} - -mod foo { - impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter - { - type Ctx = C; - type Event = Vec; - } -} diff --git a/tests/source/issue-3904/one.rs b/tests/source/issue-3904/one.rs deleted file mode 100644 index 3303ff0ab65..00000000000 --- a/tests/source/issue-3904/one.rs +++ /dev/null @@ -1,7 +0,0 @@ -// rustfmt-version: One - -fn main() { - let checkkwd = (0x2i32 | 0x1i32) as i64; /* unrecognized "\z": print both chars unless ' or " */ - - -} diff --git a/tests/source/long-fn-1/version_one.rs b/tests/source/long-fn-1/version_one.rs deleted file mode 100644 index d6832c2af09..00000000000 --- a/tests/source/long-fn-1/version_one.rs +++ /dev/null @@ -1,21 +0,0 @@ -// rustfmt-version: One -// Tests that a function which is almost short enough, but not quite, gets -// formatted correctly. - -impl Foo { - fn some_input(&mut self, input: Input, input_path: Option, ) -> (Input, Option) {} - - fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) {} -} - -// #1843 -#[allow(non_snake_case)] -pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash() -> bool { - false -} - -// #3009 -impl Something { - fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine( -) -> Result< (), String > {} -} diff --git a/tests/source/one_line_if_v1.rs b/tests/source/one_line_if_v1.rs deleted file mode 100644 index d3dcbe6787a..00000000000 --- a/tests/source/one_line_if_v1.rs +++ /dev/null @@ -1,42 +0,0 @@ -// rustfmt-version: One - -fn plain_if(x: bool) -> u8 { - if x { - 0 - } else { - 1 - } -} - -fn paren_if(x: bool) -> u8 { - (if x { 0 } else { 1 }) -} - -fn let_if(x: bool) -> u8 { - let x = if x { - foo() - } else { - bar() - }; - x -} - -fn return_if(x: bool) -> u8 { - return if x { - 0 - } else { - 1 - }; -} - -fn multi_if() { - use std::io; - if x { foo() } else { bar() } - if x { foo() } else { bar() } -} - -fn middle_if() { - use std::io; - if x { foo() } else { bar() } - let x = 1; -} diff --git a/tests/source/single-line-macro/v1.rs b/tests/source/single-line-macro/v1.rs deleted file mode 100644 index a3aa631ed4a..00000000000 --- a/tests/source/single-line-macro/v1.rs +++ /dev/null @@ -1,10 +0,0 @@ -// rustfmt-version: One - -// #2652 -// Preserve trailing comma inside macro, even if it looks an array. -macro_rules! bar { - ($m:ident) => { - $m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,]); - $m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]); - }; -} diff --git a/tests/target/comment5.rs b/tests/target/comment5.rs index 82d171e6f6a..2ecbea9a344 100644 --- a/tests/target/comment5.rs +++ b/tests/target/comment5.rs @@ -12,5 +12,5 @@ fn test() {} //@@@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec adiam //@@@ lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam //@@@ -//@@@ foo +//@@@foo fn bar() {} diff --git a/tests/target/configs/indent_style/block_trailing_comma_call/one.rs b/tests/target/configs/indent_style/block_trailing_comma_call/one.rs deleted file mode 100644 index 6b9489bef55..00000000000 --- a/tests/target/configs/indent_style/block_trailing_comma_call/one.rs +++ /dev/null @@ -1,12 +0,0 @@ -// rustfmt-version: One -// rustfmt-error_on_line_overflow: false -// rustfmt-indent_style: Block - -// rustfmt should not add trailing comma when rewriting macro. See #1528. -fn a() { - panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"); - foo( - a, - oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt(), - ); -} diff --git a/tests/target/expr.rs b/tests/target/expr.rs index c50693049a2..fe5b21dc163 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -32,9 +32,7 @@ fn foo() -> bool { { { - { - {} - } + { {} } } } @@ -589,7 +587,9 @@ fn issue3457() { { { { - println!("Test"); + println!( + "Test" + ); } } } diff --git a/tests/target/fn-single-line/version_one.rs b/tests/target/fn-single-line/version_one.rs deleted file mode 100644 index 013b2cd7216..00000000000 --- a/tests/target/fn-single-line/version_one.rs +++ /dev/null @@ -1,71 +0,0 @@ -// rustfmt-fn_single_line: true -// rustfmt-version: One -// Test single-line functions. - -fn foo_expr() { 1 } - -fn foo_stmt() { foo(); } - -fn foo_decl_local() { let z = 5; } - -fn foo_decl_item(x: &mut i32) { x = 3; } - -fn empty() {} - -fn foo_return() -> String { "yay" } - -fn foo_where() -> T -where - T: Sync, -{ - let x = 2; -} - -fn fooblock() { - { - "inner-block" - } -} - -fn fooblock2(x: i32) { - let z = match x { - _ => 2, - }; -} - -fn comment() { - // this is a test comment - 1 -} - -fn comment2() { - // multi-line comment - let z = 2; - 1 -} - -fn only_comment() { - // Keep this here -} - -fn aaaaaaaaaaaaaaaaa_looooooooooooooooooooooong_name() { - let z = "aaaaaaawwwwwwwwwwwwwwwwwwwwwwwwwwww"; -} - -fn lots_of_space() { 1 } - -fn mac() -> Vec { vec![] } - -trait CoolTypes { - fn dummy(&self) {} -} - -trait CoolerTypes { - fn dummy(&self) {} -} - -fn Foo() -where - T: Bar, -{ -} diff --git a/tests/target/issue-2179/one.rs b/tests/target/issue-2179/one.rs deleted file mode 100644 index 3f98acc8dcd..00000000000 --- a/tests/target/issue-2179/one.rs +++ /dev/null @@ -1,37 +0,0 @@ -// rustfmt-version: One -// rustfmt-error_on_line_overflow: false - -fn issue_2179() { - let (opts, rustflags, clear_env_rust_log) = { - // We mustn't lock configuration for the whole build process - let rls_config = rls_config.lock().unwrap(); - - let opts = CargoOptions::new(&rls_config); - trace!("Cargo compilation options:\n{:?}", opts); - let rustflags = prepare_cargo_rustflags(&rls_config); - - // Warn about invalid specified bin target or package depending on current mode - // TODO: Return client notifications along with diagnostics to inform the user - if !rls_config.workspace_mode { - let cur_pkg_targets = ws.current().unwrap().targets(); - - if let &Some(ref build_bin) = rls_config.build_bin.as_ref() { - let mut bins = cur_pkg_targets.iter().filter(|x| x.is_bin()); - if let None = bins.find(|x| x.name() == build_bin) { - warn!( - "cargo - couldn't find binary `{}` specified in `build_bin` configuration", - build_bin - ); - } - } - } else { - for package in &opts.package { - if let None = ws.members().find(|x| x.name() == package) { - warn!("cargo - couldn't find member package `{}` specified in `analyze_package` configuration", package); - } - } - } - - (opts, rustflags, rls_config.clear_env_rust_log) - }; -} diff --git a/tests/target/issue-3124.rs b/tests/target/issue-3124.rs index 1083050d8f4..c5d2eb1956e 100644 --- a/tests/target/issue-3124.rs +++ b/tests/target/issue-3124.rs @@ -1,6 +1,9 @@ pub fn fail1() { // Some comment. /**/// + /**/ // + /**/ + // } pub fn fail2() { diff --git a/tests/target/issue-3213/version_one.rs b/tests/target/issue-3213/version_one.rs deleted file mode 100644 index 307903b128b..00000000000 --- a/tests/target/issue-3213/version_one.rs +++ /dev/null @@ -1,13 +0,0 @@ -// rustfmt-version: One - -fn foo() { - match 0 { - 0 => { - return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - } - 1 => { - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - } - _ => "", - }; -} diff --git a/tests/target/issue-3217.rs b/tests/target/issue-3217.rs index 5121320a097..0143146a1a0 100644 --- a/tests/target/issue-3217.rs +++ b/tests/target/issue-3217.rs @@ -15,10 +15,6 @@ fn main() { } } let toto = || { - if true { - 42 - } else { - 24 - } + if true { 42 } else { 24 } }; } diff --git a/tests/target/issue-3227/one.rs b/tests/target/issue-3227/one.rs deleted file mode 100644 index fcc8331000d..00000000000 --- a/tests/target/issue-3227/one.rs +++ /dev/null @@ -1,13 +0,0 @@ -// rustfmt-version: One - -fn main() { - thread::spawn(|| { - while true { - println!("iteration"); - } - }); - - thread::spawn(|| loop { - println!("iteration"); - }); -} diff --git a/tests/target/issue-3270/one.rs b/tests/target/issue-3270/one.rs deleted file mode 100644 index 78de9473243..00000000000 --- a/tests/target/issue-3270/one.rs +++ /dev/null @@ -1,12 +0,0 @@ -// rustfmt-version: One - -pub fn main() { - /* let s = String::from( - " - hello - world - ", - ); */ - - assert_eq!(s, "\nhello\nworld\n"); -} diff --git a/tests/target/issue-3272/v1.rs b/tests/target/issue-3272/v1.rs deleted file mode 100644 index aab201027d5..00000000000 --- a/tests/target/issue-3272/v1.rs +++ /dev/null @@ -1,15 +0,0 @@ -// rustfmt-version: One - -fn main() { - assert!(HAYSTACK - .par_iter() - .find_any(|&&x| x[0] % 1000 == 999) - .is_some()); - - assert( - HAYSTACK - .par_iter() - .find_any(|&&x| x[0] % 1000 == 999) - .is_some(), - ); -} diff --git a/tests/target/issue-3278/version_one.rs b/tests/target/issue-3278/version_one.rs deleted file mode 100644 index 580679fbae3..00000000000 --- a/tests/target/issue-3278/version_one.rs +++ /dev/null @@ -1,8 +0,0 @@ -// rustfmt-version: One - -pub fn parse_conditional<'a, I: 'a>( -) -> impl Parser + 'a -where - I: Stream, -{ -} diff --git a/tests/target/issue-3614/version_one.rs b/tests/target/issue-3614/version_one.rs deleted file mode 100644 index 8ab28304732..00000000000 --- a/tests/target/issue-3614/version_one.rs +++ /dev/null @@ -1,15 +0,0 @@ -// rustfmt-version: One - -fn main() { - let toto = || { - if true { - 42 - } else { - 24 - } - }; - - { - T - } -} diff --git a/tests/target/issue-3701/one.rs b/tests/target/issue-3701/one.rs deleted file mode 100644 index 9d1ef9eed9a..00000000000 --- a/tests/target/issue-3701/one.rs +++ /dev/null @@ -1,12 +0,0 @@ -// rustfmt-version: One - -fn build_sorted_static_get_entry_names( - mut entries: Vec<(u8, &'static str)>, -) -> (impl Fn( - AlphabeticalTraversal, - Box>, -) -> BoxFuture<'static, Result, Status>> - + Send - + Sync - + 'static) { -} diff --git a/tests/target/issue-3840/version-one_hard-tabs.rs b/tests/target/issue-3840/version-one_hard-tabs.rs deleted file mode 100644 index 4aa905ce9e5..00000000000 --- a/tests/target/issue-3840/version-one_hard-tabs.rs +++ /dev/null @@ -1,25 +0,0 @@ -// rustfmt-hard_tabs: true - -impl< - Target: FromEvent + FromEvent, - A: Widget2, - B: Widget2, - C: for<'a> CtxFamily<'a>, - > Widget2 for WidgetEventLifter -{ - type Ctx = C; - type Event = Vec; -} - -mod foo { - impl< - Target: FromEvent + FromEvent, - A: Widget2, - B: Widget2, - C: for<'a> CtxFamily<'a>, - > Widget2 for WidgetEventLifter - { - type Ctx = C; - type Event = Vec; - } -} diff --git a/tests/target/issue-3840/version-one_soft-tabs.rs b/tests/target/issue-3840/version-one_soft-tabs.rs deleted file mode 100644 index 099e6801823..00000000000 --- a/tests/target/issue-3840/version-one_soft-tabs.rs +++ /dev/null @@ -1,23 +0,0 @@ -impl< - Target: FromEvent + FromEvent, - A: Widget2, - B: Widget2, - C: for<'a> CtxFamily<'a>, - > Widget2 for WidgetEventLifter -{ - type Ctx = C; - type Event = Vec; -} - -mod foo { - impl< - Target: FromEvent + FromEvent, - A: Widget2, - B: Widget2, - C: for<'a> CtxFamily<'a>, - > Widget2 for WidgetEventLifter - { - type Ctx = C; - type Event = Vec; - } -} diff --git a/tests/target/issue-3904/one.rs b/tests/target/issue-3904/one.rs deleted file mode 100644 index 85e7f0589a0..00000000000 --- a/tests/target/issue-3904/one.rs +++ /dev/null @@ -1,5 +0,0 @@ -// rustfmt-version: One - -fn main() { - let checkkwd = (0x2i32 | 0x1i32) as i64; /* unrecognized "\z": print both chars unless ' or " */ -} diff --git a/tests/target/issue-3923.rs b/tests/target/issue-3923.rs index f4d5cdb8c37..21aa529e850 100644 --- a/tests/target/issue-3923.rs +++ b/tests/target/issue-3923.rs @@ -1,4 +1,3 @@ -const TEST: &str = - "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"; +const TEST: &str = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"; const TEST2: &str = "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"; diff --git a/tests/target/long-fn-1/version_one.rs b/tests/target/long-fn-1/version_one.rs deleted file mode 100644 index 05f69953c26..00000000000 --- a/tests/target/long-fn-1/version_one.rs +++ /dev/null @@ -1,29 +0,0 @@ -// rustfmt-version: One -// Tests that a function which is almost short enough, but not quite, gets -// formatted correctly. - -impl Foo { - fn some_input( - &mut self, - input: Input, - input_path: Option, - ) -> (Input, Option) { - } - - fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) { - } -} - -// #1843 -#[allow(non_snake_case)] -pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash( -) -> bool { - false -} - -// #3009 -impl Something { - fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine( - ) -> Result<(), String> { - } -} diff --git a/tests/target/one_line_if_v1.rs b/tests/target/one_line_if_v1.rs deleted file mode 100644 index b3c6c4cbeb2..00000000000 --- a/tests/target/one_line_if_v1.rs +++ /dev/null @@ -1,46 +0,0 @@ -// rustfmt-version: One - -fn plain_if(x: bool) -> u8 { - if x { - 0 - } else { - 1 - } -} - -fn paren_if(x: bool) -> u8 { - (if x { 0 } else { 1 }) -} - -fn let_if(x: bool) -> u8 { - let x = if x { foo() } else { bar() }; - x -} - -fn return_if(x: bool) -> u8 { - return if x { 0 } else { 1 }; -} - -fn multi_if() { - use std::io; - if x { - foo() - } else { - bar() - } - if x { - foo() - } else { - bar() - } -} - -fn middle_if() { - use std::io; - if x { - foo() - } else { - bar() - } - let x = 1; -} diff --git a/tests/target/single-line-macro/v1.rs b/tests/target/single-line-macro/v1.rs deleted file mode 100644 index a3aa631ed4a..00000000000 --- a/tests/target/single-line-macro/v1.rs +++ /dev/null @@ -1,10 +0,0 @@ -// rustfmt-version: One - -// #2652 -// Preserve trailing comma inside macro, even if it looks an array. -macro_rules! bar { - ($m:ident) => { - $m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,]); - $m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]); - }; -} diff --git a/tests/target/trailing_comments/hard_tabs.rs b/tests/target/trailing_comments/hard_tabs.rs index 35e72f1affd..9044ef6c334 100644 --- a/tests/target/trailing_comments/hard_tabs.rs +++ b/tests/target/trailing_comments/hard_tabs.rs @@ -12,7 +12,8 @@ impl Foo { } fn lorem_ipsum() { - let f = bar(); // Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla. Lorem. + let f = bar(); // Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla. + // Lorem. // Id turpis. Nam posuere lectus vitae nibh. Etiam tortor orci, sagittis // malesuada, rhoncus quis, hendrerit eget, libero. Quisque commodo nulla at // nunc. Mauris consequat, enim vitae venenatis sollicitudin, dolor orci diff --git a/tests/target/trailing_comments/soft_tabs.rs b/tests/target/trailing_comments/soft_tabs.rs index eba943042ad..116f55f6aab 100644 --- a/tests/target/trailing_comments/soft_tabs.rs +++ b/tests/target/trailing_comments/soft_tabs.rs @@ -12,7 +12,8 @@ pub const SQ_CREIDX: u16 = 0x0010; // CREATE INDEX //const SQ_REVOKE: u16 = 0x0013; // REVOKE fn foo() { - let f = bar(); // Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla. Lorem. + let f = bar(); // Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla. + // Lorem. // Id turpis. Nam posuere lectus vitae nibh. Etiam tortor orci, sagittis // malesuada, rhoncus quis, hendrerit eget, libero. Quisque commodo nulla at // nunc. Mauris consequat, enim vitae venenatis sollicitudin, dolor orci diff --git a/tests/writemode/target/checkstyle.xml b/tests/writemode/target/checkstyle.xml index 05bc3a2525d..2cc4e0dbeff 100644 --- a/tests/writemode/target/checkstyle.xml +++ b/tests/writemode/target/checkstyle.xml @@ -1,2 +1,2 @@ - + diff --git a/tests/writemode/target/output.json b/tests/writemode/target/output.json index acb33dea7ef..611468669a5 100644 --- a/tests/writemode/target/output.json +++ b/tests/writemode/target/output.json @@ -1 +1 @@ -[{"name":"tests/writemode/source/json.rs","mismatches":[{"original_begin_line":5,"original_end_line":7,"expected_begin_line":5,"expected_end_line":5,"original":"fn foo_expr() {\n 1\n}","expected":"fn foo_expr() { 1 }"},{"original_begin_line":9,"original_end_line":11,"expected_begin_line":7,"expected_end_line":7,"original":"fn foo_stmt() {\n foo();\n}","expected":"fn foo_stmt() { foo(); }"},{"original_begin_line":13,"original_end_line":15,"expected_begin_line":9,"expected_end_line":9,"original":"fn foo_decl_local() {\n let z = 5;\n }","expected":"fn foo_decl_local() { let z = 5; }"},{"original_begin_line":17,"original_end_line":19,"expected_begin_line":11,"expected_end_line":11,"original":"fn foo_decl_item(x: &mut i32) {\n x = 3;\n}","expected":"fn foo_decl_item(x: &mut i32) { x = 3; }"},{"original_begin_line":21,"original_end_line":21,"expected_begin_line":13,"expected_end_line":13,"original":" fn empty() {","expected":"fn empty() {}"},{"original_begin_line":23,"original_end_line":23,"expected_begin_line":15,"expected_end_line":15,"original":"}","expected":"fn foo_return() -> String { \"yay\" }"},{"original_begin_line":25,"original_end_line":29,"expected_begin_line":17,"expected_end_line":20,"original":"fn foo_return() -> String {\n \"yay\"\n}\n\nfn foo_where() -> T where T: Sync {","expected":"fn foo_where() -> T\nwhere\n T: Sync,\n{"},{"original_begin_line":64,"original_end_line":66,"expected_begin_line":55,"expected_end_line":55,"original":"fn lots_of_space () {\n 1 \n}","expected":"fn lots_of_space() { 1 }"},{"original_begin_line":71,"original_end_line":72,"expected_begin_line":60,"expected_end_line":60,"original":" fn dummy(&self) {\n }","expected":" fn dummy(&self) {}"},{"original_begin_line":75,"original_end_line":75,"expected_begin_line":63,"expected_end_line":64,"original":"trait CoolerTypes { fn dummy(&self) { ","expected":"trait CoolerTypes {\n fn dummy(&self) {}"},{"original_begin_line":77,"original_end_line":77,"expected_begin_line":66,"expected_end_line":66,"original":"}","expected":""},{"original_begin_line":79,"original_end_line":79,"expected_begin_line":67,"expected_end_line":70,"original":"fn Foo() where T: Bar {","expected":"fn Foo()\nwhere\n T: Bar,\n{"}]}] +[{"name":"tests/writemode/source/json.rs","mismatches":[{"original_begin_line":5,"original_end_line":7,"expected_begin_line":5,"expected_end_line":5,"original":"fn foo_expr() {\n 1\n}","expected":"fn foo_expr() { 1 }"},{"original_begin_line":9,"original_end_line":11,"expected_begin_line":7,"expected_end_line":7,"original":"fn foo_stmt() {\n foo();\n}","expected":"fn foo_stmt() { foo(); }"},{"original_begin_line":13,"original_end_line":15,"expected_begin_line":9,"expected_end_line":9,"original":"fn foo_decl_local() {\n let z = 5;\n }","expected":"fn foo_decl_local() { let z = 5; }"},{"original_begin_line":17,"original_end_line":19,"expected_begin_line":11,"expected_end_line":11,"original":"fn foo_decl_item(x: &mut i32) {\n x = 3;\n}","expected":"fn foo_decl_item(x: &mut i32) { x = 3; }"},{"original_begin_line":21,"original_end_line":21,"expected_begin_line":13,"expected_end_line":13,"original":" fn empty() {","expected":"fn empty() {}"},{"original_begin_line":23,"original_end_line":23,"expected_begin_line":15,"expected_end_line":15,"original":"}","expected":"fn foo_return() -> String { \"yay\" }"},{"original_begin_line":25,"original_end_line":29,"expected_begin_line":17,"expected_end_line":20,"original":"fn foo_return() -> String {\n \"yay\"\n}\n\nfn foo_where() -> T where T: Sync {","expected":"fn foo_where() -> T\nwhere\n T: Sync,\n{"},{"original_begin_line":33,"original_end_line":37,"expected_begin_line":24,"expected_end_line":24,"original":"fn fooblock() {\n {\n \"inner-block\"\n }\n}","expected":"fn fooblock() { { \"inner-block\" } }"},{"original_begin_line":64,"original_end_line":66,"expected_begin_line":51,"expected_end_line":51,"original":"fn lots_of_space () {\n 1 \n}","expected":"fn lots_of_space() { 1 }"},{"original_begin_line":71,"original_end_line":72,"expected_begin_line":56,"expected_end_line":56,"original":" fn dummy(&self) {\n }","expected":" fn dummy(&self) {}"},{"original_begin_line":75,"original_end_line":75,"expected_begin_line":59,"expected_end_line":60,"original":"trait CoolerTypes { fn dummy(&self) { ","expected":"trait CoolerTypes {\n fn dummy(&self) {}"},{"original_begin_line":77,"original_end_line":77,"expected_begin_line":62,"expected_end_line":62,"original":"}","expected":""},{"original_begin_line":79,"original_end_line":79,"expected_begin_line":63,"expected_end_line":66,"original":"fn Foo() where T: Bar {","expected":"fn Foo()\nwhere\n T: Bar,\n{"}]}]