diff options
| author | bors <bors@rust-lang.org> | 2019-04-26 04:42:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-26 04:42:10 +0000 |
| commit | e8310a77143879ef0aa5ee4a0dffb4216390432b (patch) | |
| tree | 689f6e1bd0f3cdf5bb0fc1e681e4f9a4fe0d3f3b | |
| parent | 180edc21eeca50d0d597de091c8eb712667b5dd2 (diff) | |
| parent | 8c3068784c91a2be86b5ea0e5512290cb0e12481 (diff) | |
| download | rust-e8310a77143879ef0aa5ee4a0dffb4216390432b.tar.gz rust-e8310a77143879ef0aa5ee4a0dffb4216390432b.zip | |
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. https://github.com/rust-lang/rust/issues/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 https://github.com/rust-lang/rust/issues/60015#issuecomment-483868594. (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 https://github.com/rust-lang/rust/issues/60015).
26 files changed, 76 insertions, 3 deletions
diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index d806bd0b1d7..05225e5a25b 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! A double-ended queue implemented with a growable ring buffer. //! //! This queue has `O(1)` amortized inserts and removals from both ends of the diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 718222ee0f4..c1887a93490 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Numeric traits and functions for the built-in numeric types. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index f05700a1db2..5d77b4dfbf7 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Manually manage memory through raw pointers. //! //! *[See also the pointer primitive types](../../std/primitive.pointer.html).* diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index bf3dda48dc7..8731f486753 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Slice management and manipulation. //! //! For more details see [`std::slice`]. diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 379c263c04c..7a5511ee1dc 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! String manipulation. //! //! For more details, see the `std::str` module. diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 37373da72fb..bcf1b30814f 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Lowers the AST to the HIR. //! //! Since the AST and HIR are fairly similar, this is mostly a simple procedure, diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 3d094e72d26..0dc23f5ce47 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! MIR datatypes and passes. See the [rustc guide] for more info. //! //! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/index.html diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index cb307800fcd..60d5340613c 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Contains infrastructure for configuring the compiler, including parsing //! command line options. diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index cf69885c3e0..495b099601d 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Candidate selection. See the [rustc guide] for more information on how this works. //! //! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/resolution.html#selection diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index ed500d1ac33..2d857f402ed 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Type context book-keeping. use crate::arena::Arena; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 67be228d232..f2c77b1bfab 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + #![allow(usage_of_ty_tykind)] pub use self::Variance::*; diff --git a/src/librustc_apfloat/tests/ieee.rs b/src/librustc_apfloat/tests/ieee.rs index 108b2114439..7158efae8f1 100644 --- a/src/librustc_apfloat/tests/ieee.rs +++ b/src/librustc_apfloat/tests/ieee.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + use rustc_apfloat::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO}; use rustc_apfloat::{Float, FloatConvert, ParseError, Round, Status}; use rustc_apfloat::ieee::{Half, Single, Double, Quad, X87DoubleExtended}; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 80b82bc4dbd..be68f303537 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(crate_visibility_modifier)] diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ff3245a467a..d2d05982c61 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + /*! # typeck: check phase diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index 0b435be7bfc..ba67593ce96 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -1,4 +1,6 @@ // ignore-tidy-linelength +// ignore-tidy-filelength + #![allow(non_snake_case)] register_long_diagnostics! { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4ff16e4a267..81e4905890d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! This module contains the "cleaned" pieces of the AST, and the functions //! that clean them. diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 3e6aeddeae0..0a0a9ff64b9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Rustdoc's HTML rendering module. //! //! This modules contains the bulk of the logic necessary for rendering a diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index d1ba9c267b7..f9fb392f9f5 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + use self::Entry::*; use hashbrown::hash_map as base; diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 1772879d013..04672da2b66 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Filesystem manipulation operations. //! //! This module contains basic methods to manipulate the contents of the local diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 1bbda9b5bcb..126bc3754da 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Cross-platform path manipulation. //! //! This module provides two types, [`PathBuf`] and [`Path`][`Path`] (akin to [`String`] diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 685c7909ff2..04353fde1b4 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! Multi-producer, single-consumer FIFO queue communication primitives. //! //! This module provides message-based communication over channels, concretely diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 75d687be280..8efe84cdf01 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + use crate::ast::{AngleBracketedArgs, AsyncArgument, ParenthesizedArgs, AttrStyle, BareFnTy}; use crate::ast::{GenericBound, TraitBoundModifier}; use crate::ast::Unsafety; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7ce3951f13e..6c0fdfaa776 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; use crate::ast::{SelfKind, GenericBound, TraitBoundModifier}; use crate::ast::{Attribute, MacDelimiter, GenericArg}; diff --git a/src/test/run-pass/issues/issue-29466.rs b/src/test/run-pass/issues/issue-29466.rs index e28185bc3a2..f8785a63217 100644 --- a/src/test/run-pass/issues/issue-29466.rs +++ b/src/test/run-pass/issues/issue-29466.rs @@ -1,5 +1,9 @@ +// ignore-tidy-filelength +// // run-pass + #![allow(unused_variables)] + macro_rules! m( ($e1:expr => $e2:expr) => ({ $e1 }) ); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index d7a5395757f..9db16b69e5f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + use crate::common::CompareMode; use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT}; use crate::common::{output_base_dir, output_base_name, output_testname_unique}; diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 9ab88d6e9ae..599b6c676fb 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -3,6 +3,7 @@ //! Example checks are: //! //! * No lines over 100 characters. +//! * No files with over 3000 lines. //! * No tabs. //! * No trailing whitespace. //! * No CR characters. @@ -18,6 +19,8 @@ use std::path::Path; const COLS: usize = 100; +const LINES: usize = 3000; + const UNEXPLAINED_IGNORE_DOCTEST_INFO: &str = r#"unexplained "```ignore" doctest; try one: * make the test actually pass, by adding necessary imports and declarations, or @@ -139,11 +142,13 @@ pub fn check(path: &Path, bad: &mut bool) { let mut skip_cr = contains_ignore_directive(&contents, "cr"); let mut skip_tab = contains_ignore_directive(&contents, "tab"); - let mut skip_length = contains_ignore_directive(&contents, "linelength"); + let mut skip_line_length = contains_ignore_directive(&contents, "linelength"); + let mut skip_file_length = contains_ignore_directive(&contents, "filelength"); let mut skip_end_whitespace = contains_ignore_directive(&contents, "end-whitespace"); let mut skip_copyright = contains_ignore_directive(&contents, "copyright"); let mut leading_new_lines = false; let mut trailing_new_lines = 0; + let mut lines = 0; for (i, line) in contents.split('\n').enumerate() { let mut err = |msg: &str| { tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg); @@ -151,7 +156,7 @@ pub fn check(path: &Path, bad: &mut bool) { if line.chars().count() > COLS && !long_line_is_ok(line) { suppressible_tidy_err!( err, - skip_length, + skip_line_length, &format!("line longer than {} chars", COLS) ); } @@ -197,6 +202,7 @@ pub fn check(path: &Path, bad: &mut bool) { } else { trailing_new_lines = 0; } + lines = i; } if leading_new_lines { tidy_error!(bad, "{}: leading newline", file.display()); @@ -206,6 +212,18 @@ pub fn check(path: &Path, bad: &mut bool) { 1 => {} n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n), }; + if lines > LINES { + let mut err = |_| { + tidy_error!( + bad, + "{}: too many lines ({}) (add `// \ + ignore-tidy-filelength` to the file to suppress this error)", + file.display(), + lines + ); + }; + suppressible_tidy_err!(err, skip_file_length, ""); + } if let Directive::Ignore(false) = skip_cr { tidy_error!(bad, "{}: ignoring CR characters unnecessarily", file.display()); @@ -213,9 +231,12 @@ pub fn check(path: &Path, bad: &mut bool) { if let Directive::Ignore(false) = skip_tab { tidy_error!(bad, "{}: ignoring tab characters unnecessarily", file.display()); } - if let Directive::Ignore(false) = skip_length { + if let Directive::Ignore(false) = skip_line_length { tidy_error!(bad, "{}: ignoring line length unnecessarily", file.display()); } + if let Directive::Ignore(false) = skip_file_length { + tidy_error!(bad, "{}: ignoring file length unnecessarily", file.display()); + } if let Directive::Ignore(false) = skip_end_whitespace { tidy_error!(bad, "{}: ignoring trailing whitespace unnecessarily", file.display()); } |
