Skip to content

Commit b07e433

Browse files
authored
Merge pull request #2221 from topecongiro/rfc/blank-lines
Keep vertical spaces between items or statements within range
2 parents ae51f69 + 9ed0541 commit b07e433

33 files changed

+267
-163
lines changed

build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::io::Write;
1414
use std::path::PathBuf;
1515
use std::process::Command;
1616

17-
1817
fn main() {
1918
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
2019

src/bin/git-fmt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use getopts::{Matches, Options};
1414
use rustfmt::{run, Input};
1515
use rustfmt::config;
1616

17-
1817
fn prune_files(files: Vec<&str>) -> Vec<&str> {
1918
let prefixes: Vec<_> = files
2019
.iter()

src/bin/rustfmt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#![cfg(not(test))]
1212

13-
1413
extern crate env_logger;
1514
extern crate getopts;
1615
extern crate rustfmt_nightly as rustfmt;

src/closures.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use utils::{last_line_width, left_most_sub_expr, stmt_expr};
3131
// statement without needing a semi-colon), then adding or removing braces
3232
// can change whether it is treated as an expression or statement.
3333

34-
3534
pub fn rewrite_closure(
3635
capture: ast::CaptureBy,
3736
fn_decl: &ast::FnDecl,

src/comment.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use config::Config;
1818
use rewrite::RewriteContext;
1919
use shape::{Indent, Shape};
2020
use string::{rewrite_string, StringFormat};
21-
use utils::{first_line_width, last_line_width};
21+
use utils::{count_newlines, first_line_width, last_line_width};
2222

2323
fn is_custom_comment(comment: &str) -> bool {
2424
if !comment.starts_with("//") {
@@ -292,7 +292,7 @@ fn rewrite_comment_inner(
292292
config: config,
293293
};
294294

295-
let line_breaks = orig.trim_right().chars().filter(|&c| c == '\n').count();
295+
let line_breaks = count_newlines(orig.trim_right());
296296
let lines = orig.lines()
297297
.enumerate()
298298
.map(|(i, mut line)| {
@@ -829,9 +829,6 @@ impl<'a> Iterator for UngroupedCommentCodeSlices<'a> {
829829
}
830830
}
831831

832-
833-
834-
835832
/// Iterator over an alternating sequence of functional and commented parts of
836833
/// a string. The first item is always a, possibly zero length, subslice of
837834
/// functional text. Line style comments contain their ending newlines.
@@ -953,7 +950,6 @@ fn changed_comment_content(orig: &str, new: &str) -> bool {
953950
res
954951
}
955952

956-
957953
/// Iterator over the 'payload' characters of a comment.
958954
/// It skips whitespace, comment start/end marks, and '*' at the beginning of lines.
959955
/// The comment must be one comment, ie not more than one start mark (no multiple line comments,
@@ -999,7 +995,6 @@ impl<'a> Iterator for CommentReducer<'a> {
999995
}
1000996
}
1001997

1002-
1003998
fn remove_comment_header(comment: &str) -> &str {
1004999
if comment.starts_with("///") || comment.starts_with("//!") {
10051000
&comment[3..]

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use file_lines::FileLines;
2121
use lists::{ListTactic, SeparatorPlace, SeparatorTactic};
2222
use Summary;
2323

24-
2524
macro_rules! is_nightly_channel {
2625
() => {
2726
option_env!("CFG_RELEASE_CHANNEL")
@@ -88,7 +87,6 @@ configuration_option_enum! { TypeDensity:
8887
Wide,
8988
}
9089

91-
9290
impl Density {
9391
pub fn to_list_tactic(self) -> ListTactic {
9492
match self {
@@ -579,8 +577,6 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
579577
Ok(None)
580578
}
581579

582-
583-
584580
create_config! {
585581
// Fundamental stuff
586582
max_width: usize, 100, true, "Maximum width of each line";
@@ -651,6 +647,10 @@ create_config! {
651647
"Add trailing semicolon after break, continue and return";
652648
match_block_trailing_comma: bool, false, false,
653649
"Put a trailing comma after a block based match arm (non-block arms are not affected)";
650+
blank_lines_upper_bound: usize, 1, false,
651+
"Maximum number of blank lines which can be put between items.";
652+
blank_lines_lower_bound: usize, 0, false,
653+
"Minimum number of blank lines which must be put between items.";
654654

655655
// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
656656
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";

src/expr.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,12 +2807,8 @@ pub fn choose_rhs<R: Rewrite>(
28072807
}
28082808

28092809
fn prefer_next_line(orig_rhs: &str, next_line_rhs: &str) -> bool {
2810-
fn count_line_breaks(src: &str) -> usize {
2811-
src.chars().filter(|&x| x == '\n').count()
2812-
}
2813-
2814-
!next_line_rhs.contains('\n')
2815-
|| count_line_breaks(orig_rhs) > count_line_breaks(next_line_rhs) + 1
2810+
use utils::count_newlines;
2811+
!next_line_rhs.contains('\n') || count_newlines(orig_rhs) > count_newlines(next_line_rhs) + 1
28162812
}
28172813

28182814
fn rewrite_expr_addrof(

src/filemap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
// TODO: add tests
1312

1413
use std::fs::{self, File};

src/imports.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::cmp::Ordering;
1313
use syntax::ast;
1414
use syntax::codemap::{BytePos, Span};
1515

16-
1716
use spanned::Spanned;
1817
use codemap::SpanUtils;
1918
use comment::combine_strs_with_missing_comments;

src/items.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ impl<'a> FmtVisitor<'a> {
283283
self.format_item(item);
284284
}
285285

286-
287286
fn format_foreign_item(&mut self, item: &ast::ForeignItem) {
288287
let rewrite = item.rewrite(&self.get_context(), self.shape());
289288
self.push_rewrite(item.span(), rewrite);

src/lists.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use comment::{find_comment_end, rewrite_comment, FindUncommented};
1717
use config::{Config, IndentStyle};
1818
use rewrite::RewriteContext;
1919
use shape::{Indent, Shape};
20-
use utils::{first_line_width, last_line_width, mk_sp, starts_with_newline};
20+
use utils::{count_newlines, first_line_width, last_line_width, mk_sp, starts_with_newline};
2121

2222
/// Formatting tactic for lists. This will be cast down to a
2323
/// `DefinitiveListTactic` depending on the number and length of the items and
@@ -677,7 +677,7 @@ where
677677
// From the end of the first line of comments to the next non-whitespace char.
678678
let test_snippet = &test_snippet[..first];
679679

680-
if test_snippet.chars().filter(|c| c == &'\n').count() > 1 {
680+
if count_newlines(test_snippet) > 1 {
681681
// There were multiple line breaks which got trimmed to nothing.
682682
new_lines = true;
683683
}

0 commit comments

Comments
 (0)