From 8423e007142c131ee437ae0a0091a764b579c375 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 15:49:51 +0100 Subject: [PATCH 1/3] Add a tidy check for leading trailing newlines --- src/tools/tidy/src/style.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index a4321cd7571..528a5063ee4 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -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| { @@ -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 => {} From 9736d32f842d1f35b218f4fae219f61460d30607 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 15:50:02 +0100 Subject: [PATCH 2/3] Remove leading newlines --- src/rustc/rustc.rs | 1 - src/test/incremental/change_name_of_static_in_fn.rs | 1 - src/test/run-make-fulldeps/lto-dylib-dep/a_dylib.rs | 1 - src/test/run-make-fulldeps/lto-dylib-dep/main.rs | 1 - .../run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs | 3 +-- src/test/ui/coherence/auxiliary/re_rebalance_coherence_lib.rs | 3 +-- src/test/ui/e0119/conflict-with-std.rs | 1 - .../ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs | 3 +-- src/test/ui/mod-subitem-as-enum-variant.rs | 1 - 9 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/rustc/rustc.rs b/src/rustc/rustc.rs index 626fceb5814..4a1786f89ed 100644 --- a/src/rustc/rustc.rs +++ b/src/rustc/rustc.rs @@ -1,4 +1,3 @@ - fn main() { // Pull in jemalloc when enabled. // diff --git a/src/test/incremental/change_name_of_static_in_fn.rs b/src/test/incremental/change_name_of_static_in_fn.rs index 5b27b6808ea..fd16ad2dca4 100644 --- a/src/test/incremental/change_name_of_static_in_fn.rs +++ b/src/test/incremental/change_name_of_static_in_fn.rs @@ -1,4 +1,3 @@ - // revisions:rpass1 rpass2 rpass3 // See issue #57692. diff --git a/src/test/run-make-fulldeps/lto-dylib-dep/a_dylib.rs b/src/test/run-make-fulldeps/lto-dylib-dep/a_dylib.rs index c5a35296f89..e63457e6eb9 100644 --- a/src/test/run-make-fulldeps/lto-dylib-dep/a_dylib.rs +++ b/src/test/run-make-fulldeps/lto-dylib-dep/a_dylib.rs @@ -1,4 +1,3 @@ - pub fn foo() { println!("bar"); } diff --git a/src/test/run-make-fulldeps/lto-dylib-dep/main.rs b/src/test/run-make-fulldeps/lto-dylib-dep/main.rs index af0955e7f35..4fb3c4730b2 100644 --- a/src/test/run-make-fulldeps/lto-dylib-dep/main.rs +++ b/src/test/run-make-fulldeps/lto-dylib-dep/main.rs @@ -1,4 +1,3 @@ - extern crate a_dylib; fn main() { diff --git a/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs b/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs index c8d027b25c7..41b9d64d5f7 100644 --- a/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs +++ b/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs @@ -1,5 +1,4 @@ - -pub trait Backend{} +pub trait Backend {} pub trait SupportsDefaultKeyword {} impl SupportsDefaultKeyword for Postgres {} diff --git a/src/test/ui/coherence/auxiliary/re_rebalance_coherence_lib.rs b/src/test/ui/coherence/auxiliary/re_rebalance_coherence_lib.rs index c8d027b25c7..41b9d64d5f7 100644 --- a/src/test/ui/coherence/auxiliary/re_rebalance_coherence_lib.rs +++ b/src/test/ui/coherence/auxiliary/re_rebalance_coherence_lib.rs @@ -1,5 +1,4 @@ - -pub trait Backend{} +pub trait Backend {} pub trait SupportsDefaultKeyword {} impl SupportsDefaultKeyword for Postgres {} diff --git a/src/test/ui/e0119/conflict-with-std.rs b/src/test/ui/e0119/conflict-with-std.rs index 6dc81f33dfc..c9db2bab183 100644 --- a/src/test/ui/e0119/conflict-with-std.rs +++ b/src/test/ui/e0119/conflict-with-std.rs @@ -1,4 +1,3 @@ - use std::marker::PhantomData; use std::convert::{TryFrom, AsRef}; diff --git a/src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs b/src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs index c8d027b25c7..41b9d64d5f7 100644 --- a/src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs +++ b/src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs @@ -1,5 +1,4 @@ - -pub trait Backend{} +pub trait Backend {} pub trait SupportsDefaultKeyword {} impl SupportsDefaultKeyword for Postgres {} diff --git a/src/test/ui/mod-subitem-as-enum-variant.rs b/src/test/ui/mod-subitem-as-enum-variant.rs index cd4459ae0ff..9328d1a9045 100644 --- a/src/test/ui/mod-subitem-as-enum-variant.rs +++ b/src/test/ui/mod-subitem-as-enum-variant.rs @@ -1,4 +1,3 @@ - mod Mod { pub struct FakeVariant(pub T); } From 096495531c89076a9a68c01a0b32e6559a23b1d8 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 17:30:54 +0100 Subject: [PATCH 3/3] Update ui tests --- src/test/ui/e0119/conflict-with-std.stderr | 6 +++--- src/test/ui/mod-subitem-as-enum-variant.stderr | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/ui/e0119/conflict-with-std.stderr b/src/test/ui/e0119/conflict-with-std.stderr index 8c12b3d0bb9..3e0c71e9074 100644 --- a/src/test/ui/e0119/conflict-with-std.stderr +++ b/src/test/ui/e0119/conflict-with-std.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `std::convert::AsRef` for type `std::boxed::Box`: - --> $DIR/conflict-with-std.rs:6:1 + --> $DIR/conflict-with-std.rs:5:1 | LL | impl AsRef for Box { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | impl AsRef for Box { where T: ?Sized; error[E0119]: conflicting implementations of trait `std::convert::From` for type `S`: - --> $DIR/conflict-with-std.rs:13:1 + --> $DIR/conflict-with-std.rs:12:1 | LL | impl From for S { | ^^^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | impl From for S { - impl std::convert::From for T; error[E0119]: conflicting implementations of trait `std::convert::TryFrom` for type `X`: - --> $DIR/conflict-with-std.rs:20:1 + --> $DIR/conflict-with-std.rs:19:1 | LL | impl TryFrom for X { | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/mod-subitem-as-enum-variant.stderr b/src/test/ui/mod-subitem-as-enum-variant.stderr index 72eca588208..d6815c91e5e 100644 --- a/src/test/ui/mod-subitem-as-enum-variant.stderr +++ b/src/test/ui/mod-subitem-as-enum-variant.stderr @@ -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::::FakeVariant(0); | ^^^ type argument not allowed