Skip to content

Commit

Permalink
Auto merge of #60168 - varkor:tidy-leading-newline, r=alexcrichton
Browse files Browse the repository at this point in the history
Add a tidy check for leading newlines

This is fairly uncommon, but it can slip through when refactoring (as evidenced by the files with leading newlines here).
  • Loading branch information
bors committed Apr 22, 2019
2 parents c21fbfe + 0964955 commit 6d59933
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/rustc/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

fn main() {
// Pull in jemalloc when enabled.
//
Expand Down
1 change: 0 additions & 1 deletion src/test/incremental/change_name_of_static_in_fn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// revisions:rpass1 rpass2 rpass3

// See issue #57692.
Expand Down
1 change: 0 additions & 1 deletion src/test/run-make-fulldeps/lto-dylib-dep/a_dylib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pub fn foo() {
println!("bar");
}
1 change: 0 additions & 1 deletion src/test/run-make-fulldeps/lto-dylib-dep/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

extern crate a_dylib;

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

pub trait Backend{}
pub trait Backend {}
pub trait SupportsDefaultKeyword {}

impl SupportsDefaultKeyword for Postgres {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

pub trait Backend{}
pub trait Backend {}
pub trait SupportsDefaultKeyword {}

impl SupportsDefaultKeyword for Postgres {}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/e0119/conflict-with-std.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use std::marker::PhantomData;
use std::convert::{TryFrom, AsRef};

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/e0119/conflict-with-std.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for type `std::boxed::Box<Q>`:
--> $DIR/conflict-with-std.rs:6:1
--> $DIR/conflict-with-std.rs:5:1
|
LL | impl AsRef<Q> for Box<Q> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | impl AsRef<Q> for Box<Q> {
where T: ?Sized;

error[E0119]: conflicting implementations of trait `std::convert::From<S>` for type `S`:
--> $DIR/conflict-with-std.rs:13:1
--> $DIR/conflict-with-std.rs:12:1
|
LL | impl From<S> for S {
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -18,7 +18,7 @@ LL | impl From<S> for S {
- impl<T> std::convert::From<T> for T;

error[E0119]: conflicting implementations of trait `std::convert::TryFrom<X>` for type `X`:
--> $DIR/conflict-with-std.rs:20:1
--> $DIR/conflict-with-std.rs:19:1
|
LL | impl TryFrom<X> for X {
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

pub trait Backend{}
pub trait Backend {}
pub trait SupportsDefaultKeyword {}

impl SupportsDefaultKeyword for Postgres {}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/mod-subitem-as-enum-variant.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

mod Mod {
pub struct FakeVariant<T>(pub T);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mod-subitem-as-enum-variant.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0109]: type arguments are not allowed for this type
--> $DIR/mod-subitem-as-enum-variant.rs:8:11
--> $DIR/mod-subitem-as-enum-variant.rs:7:11
|
LL | Mod::<i32>::FakeVariant(0);
| ^^^ type argument not allowed
Expand Down
7 changes: 7 additions & 0 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn check(path: &Path, bad: &mut bool) {
let skip_length = contents.contains("ignore-tidy-linelength");
let skip_end_whitespace = contents.contains("ignore-tidy-end-whitespace");
let skip_copyright = contents.contains("ignore-tidy-copyright");
let mut leading_new_lines = false;
let mut trailing_new_lines = 0;
for (i, line) in contents.split('\n').enumerate() {
let mut err = |msg: &str| {
Expand Down Expand Up @@ -152,11 +153,17 @@ pub fn check(path: &Path, bad: &mut bool) {
err(LLVM_UNREACHABLE_INFO);
}
if line.is_empty() {
if i == 0 {
leading_new_lines = true;
}
trailing_new_lines += 1;
} else {
trailing_new_lines = 0;
}
}
if leading_new_lines {
tidy_error!(bad, "{}: leading newline", file.display());
}
match trailing_new_lines {
0 => tidy_error!(bad, "{}: missing trailing newline", file.display()),
1 | 2 => {}
Expand Down

0 comments on commit 6d59933

Please sign in to comment.