Skip to content

Commit 93b0aa1

Browse files
committed
Auto merge of #60168 - varkor:tidy-leading-newline, r=alexcrichton
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).
2 parents c21fbfe + 5347ab4 commit 93b0aa1

File tree

10 files changed

+10
-12
lines changed

10 files changed

+10
-12
lines changed

src/rustc/rustc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
fn main() {
32
// Pull in jemalloc when enabled.
43
//

src/test/incremental/change_name_of_static_in_fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// revisions:rpass1 rpass2 rpass3
32

43
// See issue #57692.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
pub fn foo() {
32
println!("bar");
43
}

src/test/run-make-fulldeps/lto-dylib-dep/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
extern crate a_dylib;
32

43
fn main() {

src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
pub trait Backend{}
1+
pub trait Backend {}
32
pub trait SupportsDefaultKeyword {}
43

54
impl SupportsDefaultKeyword for Postgres {}

src/test/ui/coherence/auxiliary/re_rebalance_coherence_lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
pub trait Backend{}
1+
pub trait Backend {}
32
pub trait SupportsDefaultKeyword {}
43

54
impl SupportsDefaultKeyword for Postgres {}

src/test/ui/e0119/conflict-with-std.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use std::marker::PhantomData;
32
use std::convert::{TryFrom, AsRef};
43

src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
pub trait Backend{}
1+
pub trait Backend {}
32
pub trait SupportsDefaultKeyword {}
43

54
impl SupportsDefaultKeyword for Postgres {}

src/test/ui/mod-subitem-as-enum-variant.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
mod Mod {
32
pub struct FakeVariant<T>(pub T);
43
}

src/tools/tidy/src/style.rs

+7
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn check(path: &Path, bad: &mut bool) {
112112
let skip_length = contents.contains("ignore-tidy-linelength");
113113
let skip_end_whitespace = contents.contains("ignore-tidy-end-whitespace");
114114
let skip_copyright = contents.contains("ignore-tidy-copyright");
115+
let mut leading_new_lines = false;
115116
let mut trailing_new_lines = 0;
116117
for (i, line) in contents.split('\n').enumerate() {
117118
let mut err = |msg: &str| {
@@ -152,11 +153,17 @@ pub fn check(path: &Path, bad: &mut bool) {
152153
err(LLVM_UNREACHABLE_INFO);
153154
}
154155
if line.is_empty() {
156+
if i == 0 {
157+
leading_new_lines = true;
158+
}
155159
trailing_new_lines += 1;
156160
} else {
157161
trailing_new_lines = 0;
158162
}
159163
}
164+
if leading_new_lines {
165+
tidy_error!(bad, "{}: leading newline", file.display());
166+
}
160167
match trailing_new_lines {
161168
0 => tidy_error!(bad, "{}: missing trailing newline", file.display()),
162169
1 | 2 => {}

0 commit comments

Comments
 (0)