Skip to content

Keep vertical spaces between items or statements within range #2221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::io::Write;
use std::path::PathBuf;
use std::process::Command;


fn main() {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

Expand Down
1 change: 0 additions & 1 deletion src/bin/git-fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use getopts::{Matches, Options};
use rustfmt::{run, Input};
use rustfmt::config;


fn prune_files(files: Vec<&str>) -> Vec<&str> {
let prefixes: Vec<_> = files
.iter()
Expand Down
1 change: 0 additions & 1 deletion src/bin/rustfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#![cfg(not(test))]


extern crate env_logger;
extern crate getopts;
extern crate rustfmt_nightly as rustfmt;
Expand Down
1 change: 0 additions & 1 deletion src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use utils::{last_line_width, left_most_sub_expr, stmt_expr};
// statement without needing a semi-colon), then adding or removing braces
// can change whether it is treated as an expression or statement.


pub fn rewrite_closure(
capture: ast::CaptureBy,
fn_decl: &ast::FnDecl,
Expand Down
9 changes: 2 additions & 7 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use config::Config;
use rewrite::RewriteContext;
use shape::{Indent, Shape};
use string::{rewrite_string, StringFormat};
use utils::{first_line_width, last_line_width};
use utils::{count_newlines, first_line_width, last_line_width};

fn is_custom_comment(comment: &str) -> bool {
if !comment.starts_with("//") {
Expand Down Expand Up @@ -296,7 +296,7 @@ fn rewrite_comment_inner(
config: config,
};

let line_breaks = orig.trim_right().chars().filter(|&c| c == '\n').count();
let line_breaks = count_newlines(orig.trim_right());
let lines = orig.lines()
.enumerate()
.map(|(i, mut line)| {
Expand Down Expand Up @@ -824,9 +824,6 @@ impl<'a> Iterator for UngroupedCommentCodeSlices<'a> {
}
}




/// Iterator over an alternating sequence of functional and commented parts of
/// a string. The first item is always a, possibly zero length, subslice of
/// functional text. Line style comments contain their ending newlines.
Expand Down Expand Up @@ -948,7 +945,6 @@ fn changed_comment_content(orig: &str, new: &str) -> bool {
res
}


/// Iterator over the 'payload' characters of a comment.
/// It skips whitespace, comment start/end marks, and '*' at the beginning of lines.
/// The comment must be one comment, ie not more than one start mark (no multiple line comments,
Expand Down Expand Up @@ -994,7 +990,6 @@ impl<'a> Iterator for CommentReducer<'a> {
}
}


fn remove_comment_header(comment: &str) -> &str {
if comment.starts_with("///") || comment.starts_with("//!") {
&comment[3..]
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use file_lines::FileLines;
use lists::{ListTactic, SeparatorPlace, SeparatorTactic};
use Summary;


macro_rules! is_nightly_channel {
() => {
env::var("CFG_RELEASE_CHANNEL")
Expand Down Expand Up @@ -88,7 +87,6 @@ configuration_option_enum! { TypeDensity:
Wide,
}


impl Density {
pub fn to_list_tactic(self) -> ListTactic {
match self {
Expand Down Expand Up @@ -579,8 +577,6 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
Ok(None)
}



create_config! {
// Fundamental stuff
max_width: usize, 100, true, "Maximum width of each line";
Expand Down Expand Up @@ -651,6 +647,10 @@ create_config! {
"Add trailing semicolon after break, continue and return";
match_block_trailing_comma: bool, false, false,
"Put a trailing comma after a block based match arm (non-block arms are not affected)";
blank_lines_upper_bound: usize, 1, false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default here should be 2.

"Maximum number of blank lines which can be put between items.";
blank_lines_lower_bound: usize, 0, false,
"Minimum number of blank lines which must be put between items.";

// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
Expand Down
8 changes: 2 additions & 6 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2712,12 +2712,8 @@ pub fn choose_rhs<R: Rewrite>(
}

fn prefer_next_line(orig_rhs: &str, next_line_rhs: &str) -> bool {
fn count_line_breaks(src: &str) -> usize {
src.chars().filter(|&x| x == '\n').count()
}

!next_line_rhs.contains('\n')
|| count_line_breaks(orig_rhs) > count_line_breaks(next_line_rhs) + 1
use utils::count_newlines;
!next_line_rhs.contains('\n') || count_newlines(orig_rhs) > count_newlines(next_line_rhs) + 1
}

fn rewrite_expr_addrof(
Expand Down
1 change: 0 additions & 1 deletion src/filemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.


// TODO: add tests

use std::fs::{self, File};
Expand Down
1 change: 0 additions & 1 deletion src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::cmp::Ordering;
use syntax::ast;
use syntax::codemap::{BytePos, Span};


use spanned::Spanned;
use codemap::SpanUtils;
use comment::combine_strs_with_missing_comments;
Expand Down
1 change: 0 additions & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ impl<'a> FmtVisitor<'a> {
self.format_item(item);
}


fn format_foreign_item(&mut self, item: &ast::ForeignItem) {
let rewrite = item.rewrite(&self.get_context(), self.shape());
self.push_rewrite(item.span(), rewrite);
Expand Down
4 changes: 2 additions & 2 deletions src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use comment::{find_comment_end, rewrite_comment, FindUncommented};
use config::{Config, IndentStyle};
use rewrite::RewriteContext;
use shape::{Indent, Shape};
use utils::{first_line_width, last_line_width, mk_sp, starts_with_newline};
use utils::{count_newlines, first_line_width, last_line_width, mk_sp, starts_with_newline};

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

if test_snippet.chars().filter(|c| c == &'\n').count() > 1 {
if count_newlines(test_snippet) > 1 {
// There were multiple line breaks which got trimmed to nothing.
new_lines = true;
}
Expand Down
Loading