Skip to content

Commit e8310a7

Browse files
committed
Auto merge of #60167 - varkor:tidy-filelength, r=matthewjasper
Add a tidy check for files with over 3,000 lines Files with a large number of lines can cause issues in GitHub (e.g. #60015) and also tend to be indicative of opportunities to refactor into less monolithic structures. This adds a new check to tidy to warn against files that have more than 3,000 lines, as suggested in #60015 (comment). (This number was chosen fairly arbitrarily as a reasonable indicator of size.) This check can be ignored with `// ignore-tidy-filelength`. Existing files with greater than 3,000 lines currently ignore the check, but this helps us spot when files are getting too large. (We might try to split up all files larger than this in the future, as in #60015).
2 parents 180edc2 + 8c30687 commit e8310a7

File tree

26 files changed

+76
-3
lines changed

26 files changed

+76
-3
lines changed

src/liballoc/collections/vec_deque.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! A double-ended queue implemented with a growable ring buffer.
24
//!
35
//! This queue has `O(1)` amortized inserts and removals from both ends of the

src/libcore/num/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Numeric traits and functions for the built-in numeric types.
24
35
#![stable(feature = "rust1", since = "1.0.0")]

src/libcore/ptr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Manually manage memory through raw pointers.
24
//!
35
//! *[See also the pointer primitive types](../../std/primitive.pointer.html).*

src/libcore/slice/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Slice management and manipulation.
24
//!
35
//! For more details see [`std::slice`].

src/libcore/str/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! String manipulation.
24
//!
35
//! For more details, see the `std::str` module.

src/librustc/hir/lowering.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Lowers the AST to the HIR.
24
//!
35
//! Since the AST and HIR are fairly similar, this is mostly a simple procedure,

src/librustc/mir/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! MIR datatypes and passes. See the [rustc guide] for more info.
24
//!
35
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/index.html

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Contains infrastructure for configuring the compiler, including parsing
24
//! command line options.
35

src/librustc/traits/select.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Candidate selection. See the [rustc guide] for more information on how this works.
24
//!
35
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/resolution.html#selection

src/librustc/ty/context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Type context book-keeping.
24
35
use crate::arena::Arena;

src/librustc/ty/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
#![allow(usage_of_ty_tykind)]
24

35
pub use self::Variance::*;

src/librustc_apfloat/tests/ieee.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
use rustc_apfloat::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
24
use rustc_apfloat::{Float, FloatConvert, ParseError, Round, Status};
35
use rustc_apfloat::ieee::{Half, Single, Double, Quad, X87DoubleExtended};

src/librustc_resolve/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
24

35
#![feature(crate_visibility_modifier)]

src/librustc_typeck/check/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
/*!
24
35
# typeck: check phase

src/librustc_typeck/error_codes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// ignore-tidy-linelength
2+
// ignore-tidy-filelength
3+
24
#![allow(non_snake_case)]
35

46
register_long_diagnostics! {

src/librustdoc/clean/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! This module contains the "cleaned" pieces of the AST, and the functions
24
//! that clean them.
35

src/librustdoc/html/render.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Rustdoc's HTML rendering module.
24
//!
35
//! This modules contains the bulk of the logic necessary for rendering a

src/libstd/collections/hash/map.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
use self::Entry::*;
24

35
use hashbrown::hash_map as base;

src/libstd/fs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Filesystem manipulation operations.
24
//!
35
//! This module contains basic methods to manipulate the contents of the local

src/libstd/path.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Cross-platform path manipulation.
24
//!
35
//! This module provides two types, [`PathBuf`] and [`Path`][`Path`] (akin to [`String`]

src/libstd/sync/mpsc/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! Multi-producer, single-consumer FIFO queue communication primitives.
24
//!
35
//! This module provides message-based communication over channels, concretely

src/libsyntax/parse/parser.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
use crate::ast::{AngleBracketedArgs, AsyncArgument, ParenthesizedArgs, AttrStyle, BareFnTy};
24
use crate::ast::{GenericBound, TraitBoundModifier};
35
use crate::ast::Unsafety;

src/libsyntax/print/pprust.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
24
use crate::ast::{SelfKind, GenericBound, TraitBoundModifier};
35
use crate::ast::{Attribute, MacDelimiter, GenericArg};

src/test/run-pass/issues/issue-29466.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
// ignore-tidy-filelength
2+
//
13
// run-pass
4+
25
#![allow(unused_variables)]
6+
37
macro_rules! m(
48
($e1:expr => $e2:expr) => ({ $e1 })
59
);

src/tools/compiletest/src/runtest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
use crate::common::CompareMode;
24
use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
35
use crate::common::{output_base_dir, output_base_name, output_testname_unique};

src/tools/tidy/src/style.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Example checks are:
44
//!
55
//! * No lines over 100 characters.
6+
//! * No files with over 3000 lines.
67
//! * No tabs.
78
//! * No trailing whitespace.
89
//! * No CR characters.
@@ -18,6 +19,8 @@ use std::path::Path;
1819

1920
const COLS: usize = 100;
2021

22+
const LINES: usize = 3000;
23+
2124
const UNEXPLAINED_IGNORE_DOCTEST_INFO: &str = r#"unexplained "```ignore" doctest; try one:
2225

2326
* make the test actually pass, by adding necessary imports and declarations, or
@@ -139,19 +142,21 @@ pub fn check(path: &Path, bad: &mut bool) {
139142

140143
let mut skip_cr = contains_ignore_directive(&contents, "cr");
141144
let mut skip_tab = contains_ignore_directive(&contents, "tab");
142-
let mut skip_length = contains_ignore_directive(&contents, "linelength");
145+
let mut skip_line_length = contains_ignore_directive(&contents, "linelength");
146+
let mut skip_file_length = contains_ignore_directive(&contents, "filelength");
143147
let mut skip_end_whitespace = contains_ignore_directive(&contents, "end-whitespace");
144148
let mut skip_copyright = contains_ignore_directive(&contents, "copyright");
145149
let mut leading_new_lines = false;
146150
let mut trailing_new_lines = 0;
151+
let mut lines = 0;
147152
for (i, line) in contents.split('\n').enumerate() {
148153
let mut err = |msg: &str| {
149154
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
150155
};
151156
if line.chars().count() > COLS && !long_line_is_ok(line) {
152157
suppressible_tidy_err!(
153158
err,
154-
skip_length,
159+
skip_line_length,
155160
&format!("line longer than {} chars", COLS)
156161
);
157162
}
@@ -197,6 +202,7 @@ pub fn check(path: &Path, bad: &mut bool) {
197202
} else {
198203
trailing_new_lines = 0;
199204
}
205+
lines = i;
200206
}
201207
if leading_new_lines {
202208
tidy_error!(bad, "{}: leading newline", file.display());
@@ -206,16 +212,31 @@ pub fn check(path: &Path, bad: &mut bool) {
206212
1 => {}
207213
n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n),
208214
};
215+
if lines > LINES {
216+
let mut err = |_| {
217+
tidy_error!(
218+
bad,
219+
"{}: too many lines ({}) (add `// \
220+
ignore-tidy-filelength` to the file to suppress this error)",
221+
file.display(),
222+
lines
223+
);
224+
};
225+
suppressible_tidy_err!(err, skip_file_length, "");
226+
}
209227

210228
if let Directive::Ignore(false) = skip_cr {
211229
tidy_error!(bad, "{}: ignoring CR characters unnecessarily", file.display());
212230
}
213231
if let Directive::Ignore(false) = skip_tab {
214232
tidy_error!(bad, "{}: ignoring tab characters unnecessarily", file.display());
215233
}
216-
if let Directive::Ignore(false) = skip_length {
234+
if let Directive::Ignore(false) = skip_line_length {
217235
tidy_error!(bad, "{}: ignoring line length unnecessarily", file.display());
218236
}
237+
if let Directive::Ignore(false) = skip_file_length {
238+
tidy_error!(bad, "{}: ignoring file length unnecessarily", file.display());
239+
}
219240
if let Directive::Ignore(false) = skip_end_whitespace {
220241
tidy_error!(bad, "{}: ignoring trailing whitespace unnecessarily", file.display());
221242
}

0 commit comments

Comments
 (0)