From 949658345c1352de926bf8c3af3e19cd18c6d0e6 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 15:28:48 +0100 Subject: [PATCH 1/4] Add a tidy test for line count --- src/tools/tidy/src/style.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 9ab88d6e9aeac..4de7e580b0000 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,9 @@ pub fn check(path: &Path, bad: &mut bool) { 1 => {} n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n), }; + if !skip_file_length && lines > LINES { + tidy_error!(bad, "{}: too many lines ({})", file.display(), lines); + } if let Directive::Ignore(false) = skip_cr { tidy_error!(bad, "{}: ignoring CR characters unnecessarily", file.display()); @@ -213,9 +222,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()); } From aa388f1d11da024898d823ce24654766a4cc3459 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 15:29:04 +0100 Subject: [PATCH 2/4] ignore-tidy-filelength on all files with greater than 3000 lines --- src/liballoc/collections/vec_deque.rs | 2 ++ src/libcore/num/mod.rs | 2 ++ src/libcore/ptr.rs | 2 ++ src/libcore/slice/mod.rs | 2 ++ src/libcore/str/mod.rs | 2 ++ src/librustc/hir/lowering.rs | 2 ++ src/librustc/mir/mod.rs | 2 ++ src/librustc/session/config.rs | 2 ++ src/librustc/traits/select.rs | 2 ++ src/librustc/ty/context.rs | 2 ++ src/librustc/ty/mod.rs | 2 ++ src/librustc_apfloat/tests/ieee.rs | 2 ++ src/librustc_resolve/lib.rs | 2 ++ src/librustc_typeck/check/mod.rs | 2 ++ src/librustc_typeck/error_codes.rs | 2 ++ src/librustdoc/clean/mod.rs | 2 ++ src/librustdoc/html/render.rs | 2 ++ src/libstd/collections/hash/map.rs | 2 ++ src/libstd/fs.rs | 2 ++ src/libstd/path.rs | 2 ++ src/libstd/sync/mpsc/mod.rs | 2 ++ src/libsyntax/parse/parser.rs | 2 ++ src/libsyntax/print/pprust.rs | 2 ++ src/test/run-pass/issues/issue-29466.rs | 4 ++++ src/tools/compiletest/src/runtest.rs | 2 ++ 25 files changed, 52 insertions(+) diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index d806bd0b1d76f..05225e5a25b29 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 f1325f383eedb..5c48c732b7843 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 f05700a1db285..5d77b4dfbf7ae 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 bf3dda48dc797..8731f48675356 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 379c263c04ca6..7a5511ee1dc8b 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 380dee5fcdcc2..d4dd983e21762 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 bf2a1eaafd664..9da961b4e9e84 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 cb307800fcdc2..60d5340613c2a 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 e7cc9618080c2..c079a526842f0 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 ed500d1ac3351..2d857f402ed60 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 67be228d232e1..f2c77b1bfab7d 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 108b2114439d4..7158efae8f1ad 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 7754bb26f9055..f6b62146c60eb 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 bd715df6e9d1e..9f0c377e19c12 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 22f24df450f46..dc23a92adbbcf 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 4ff16e4a26760..81e4905890d45 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 487c57172d9b1..2c4e1cde880a1 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 d1ba9c267b72e..f9fb392f9f52b 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 1772879d01362..04672da2b66a7 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 1bbda9b5bcb1a..126bc3754dabc 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 685c7909ff294..04353fde1b4d9 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 75d687be28003..8efe84cdf016f 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 7ce3951f13ecd..6c0fdfaa776f9 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 e28185bc3a2d7..f8785a6321792 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 d7a5395757fb8..9db16b69e5f29 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}; From b759c2d714d4087fb7465fe880675661d5428117 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 21:05:57 +0100 Subject: [PATCH 3/4] Advise the user on how to suppress the file length tidy error --- src/tools/tidy/src/style.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 4de7e580b0000..3bb2643f9c355 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -213,7 +213,13 @@ pub fn check(path: &Path, bad: &mut bool) { n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n), }; if !skip_file_length && lines > LINES { - tidy_error!(bad, "{}: too many lines ({})", file.display(), lines); + tidy_error!( + bad, + "{}: too many lines ({}) (add `// ignore-tidy-filelength` to the file to \ + suppress this error)", + file.display(), + lines + ); } if let Directive::Ignore(false) = skip_cr { From 8c3068784c91a2be86b5ea0e5512290cb0e12481 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 25 Apr 2019 21:54:09 +0100 Subject: [PATCH 4/4] Fix false position on style.rs itself --- src/tools/tidy/src/style.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 3bb2643f9c355..599b6c676fb27 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -212,14 +212,17 @@ pub fn check(path: &Path, bad: &mut bool) { 1 => {} n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n), }; - if !skip_file_length && lines > LINES { - tidy_error!( - bad, - "{}: too many lines ({}) (add `// ignore-tidy-filelength` to the file to \ - suppress this error)", - file.display(), - lines - ); + 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 {