Skip to content

Commit 5bf139e

Browse files
committed
Auto merge of #109440 - WaffleLapkin:make_tidy_slower, r=jyn514
Don't skip all directories when tidy-checking This fixes a regression from #108772 which basically made it that tidy style checks only `README.md` and `COMPILER_TESTS.md`.
2 parents 2036fdd + 904dd2c commit 5bf139e

File tree

23 files changed

+87
-67
lines changed

23 files changed

+87
-67
lines changed

Diff for: compiler/rustc_attr/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl UnstableReason {
227227
}
228228

229229
/// Collects stability info from `stable`/`unstable`/`rustc_allowed_through_unstable_modules`
230-
/// attributes in `attrs`. Returns `None` if no stability attributes are found.
230+
/// attributes in `attrs`. Returns `None` if no stability attributes are found.
231231
pub fn find_stability(
232232
sess: &Session,
233233
attrs: &[Attribute],
@@ -281,7 +281,7 @@ pub fn find_stability(
281281
}
282282

283283
/// Collects stability info from `rustc_const_stable`/`rustc_const_unstable`/`rustc_promotable`
284-
/// attributes in `attrs`. Returns `None` if no stability attributes are found.
284+
/// attributes in `attrs`. Returns `None` if no stability attributes are found.
285285
pub fn find_const_stability(
286286
sess: &Session,
287287
attrs: &[Attribute],

Diff for: compiler/rustc_codegen_ssa/src/back/linker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ impl<'a> Linker for AixLinker<'a> {
16211621
let path = tmpdir.join("list.exp");
16221622
let res: io::Result<()> = try {
16231623
let mut f = BufWriter::new(File::create(&path)?);
1624-
// TODO: use llvm-nm to generate export list.
1624+
// FIXME: use llvm-nm to generate export list.
16251625
for symbol in symbols {
16261626
debug!(" _{}", symbol);
16271627
writeln!(f, " {}", symbol)?;

Diff for: compiler/rustc_error_codes/src/error_codes/E0080.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ or causing an integer overflow are two ways to induce this error.
1616
Ensure that the expressions given can be evaluated as the desired integer type.
1717

1818
See the [Discriminants] section of the Reference for more information about
19-
setting custom integer types on enums using the [`repr` attribute][repr-attribute].
19+
setting custom integer types on enums using the
20+
[`repr` attribute][repr-attribute].
2021

2122
[discriminants]: https://doc.rust-lang.org/reference/items/enumerations.html#discriminants
2223
[repr-attribute]: https://doc.rust-lang.org/reference/type-layout.html#representations

Diff for: compiler/rustc_error_codes/src/error_codes/E0794.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ In the definition of `bar`, the lifetime parameter `'a` is late-bound, while
5959
where `'a` is universally quantified and `'b` is substituted by a specific
6060
lifetime. It is not allowed to explicitly specify early-bound lifetime
6161
arguments when late-bound lifetime parameters are present (as for `bar_fn2`,
62-
see [issue #42868](https://github.com/rust-lang/rust/issues/42868)), although the
63-
types that are constrained by early-bound parameters can be specified (as for
64-
`bar_fn3`).
62+
see [issue #42868](https://github.com/rust-lang/rust/issues/42868)), although
63+
the types that are constrained by early-bound parameters can be specified (as
64+
for `bar_fn3`).

Diff for: compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
568568
BinOp::Shl | BinOp::Shr if self.check_overflow && ty.is_integral() => {
569569
// For an unsigned RHS, the shift is in-range for `rhs < bits`.
570570
// For a signed RHS, `IntToInt` cast to the equivalent unsigned
571-
// type and do that same comparison. Because the type is the
571+
// type and do that same comparison. Because the type is the
572572
// same size, there's no negative shift amount that ends up
573573
// overlapping with valid ones, thus it catches negatives too.
574574
let (lhs_size, _) = ty.int_size_and_signed(self.tcx);

Diff for: src/doc/unstable-book/src/compiler-flags/sanitizer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
213213
214214
## Example
215215
216-
```rust,ignore
216+
```rust,ignore (making doc tests pass cross-platform is hard)
217217
#![feature(naked_functions)]
218218
219219
use std::arch::asm;

Diff for: src/tools/replace-version-placeholder/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
let version_str = version_str.trim();
1111
walk::walk(
1212
&root_path,
13-
|path| {
13+
|path, _is_dir| {
1414
walk::filter_dirs(path)
1515
// We exempt these as they require the placeholder
1616
// for their operation

Diff for: src/tools/tidy/src/alphabetical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn check_section<'a>(
9595
}
9696

9797
pub fn check(path: &Path, bad: &mut bool) {
98-
walk(path, filter_dirs, &mut |entry, contents| {
98+
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
9999
let file = &entry.path().display();
100100

101101
let mut lines = contents.lines().enumerate().peekable();

Diff for: src/tools/tidy/src/bins.rs

+31-27
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,40 @@ mod os_impl {
103103

104104
// FIXME: we don't need to look at all binaries, only files that have been modified in this branch
105105
// (e.g. using `git ls-files`).
106-
walk_no_read(&[path], |path| filter_dirs(path) || path.ends_with("src/etc"), &mut |entry| {
107-
let file = entry.path();
108-
let extension = file.extension();
109-
let scripts = ["py", "sh", "ps1"];
110-
if scripts.into_iter().any(|e| extension == Some(OsStr::new(e))) {
111-
return;
112-
}
113-
114-
if t!(is_executable(&file), file) {
115-
let rel_path = file.strip_prefix(path).unwrap();
116-
let git_friendly_path = rel_path.to_str().unwrap().replace("\\", "/");
117-
118-
if ALLOWED.contains(&git_friendly_path.as_str()) {
106+
walk_no_read(
107+
&[path],
108+
|path, _is_dir| filter_dirs(path) || path.ends_with("src/etc"),
109+
&mut |entry| {
110+
let file = entry.path();
111+
let extension = file.extension();
112+
let scripts = ["py", "sh", "ps1"];
113+
if scripts.into_iter().any(|e| extension == Some(OsStr::new(e))) {
119114
return;
120115
}
121116

122-
let output = Command::new("git")
123-
.arg("ls-files")
124-
.arg(&git_friendly_path)
125-
.current_dir(path)
126-
.stderr(Stdio::null())
127-
.output()
128-
.unwrap_or_else(|e| {
129-
panic!("could not run git ls-files: {e}");
130-
});
131-
let path_bytes = rel_path.as_os_str().as_bytes();
132-
if output.status.success() && output.stdout.starts_with(path_bytes) {
133-
tidy_error!(bad, "binary checked into source: {}", file.display());
117+
if t!(is_executable(&file), file) {
118+
let rel_path = file.strip_prefix(path).unwrap();
119+
let git_friendly_path = rel_path.to_str().unwrap().replace("\\", "/");
120+
121+
if ALLOWED.contains(&git_friendly_path.as_str()) {
122+
return;
123+
}
124+
125+
let output = Command::new("git")
126+
.arg("ls-files")
127+
.arg(&git_friendly_path)
128+
.current_dir(path)
129+
.stderr(Stdio::null())
130+
.output()
131+
.unwrap_or_else(|e| {
132+
panic!("could not run git ls-files: {e}");
133+
});
134+
let path_bytes = rel_path.as_os_str().as_bytes();
135+
if output.status.success() && output.stdout.starts_with(path_bytes) {
136+
tidy_error!(bad, "binary checked into source: {}", file.display());
137+
}
134138
}
135-
}
136-
})
139+
},
140+
)
137141
}
138142
}

Diff for: src/tools/tidy/src/debug_artifacts.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ use std::path::Path;
66
const GRAPHVIZ_POSTFLOW_MSG: &str = "`borrowck_graphviz_postflow` attribute in test";
77

88
pub fn check(test_dir: &Path, bad: &mut bool) {
9-
walk(test_dir, |path| filter_dirs(path) || filter_not_rust(path), &mut |entry, contents| {
10-
for (i, line) in contents.lines().enumerate() {
11-
if line.contains("borrowck_graphviz_postflow") {
12-
tidy_error!(bad, "{}:{}: {}", entry.path().display(), i + 1, GRAPHVIZ_POSTFLOW_MSG);
9+
walk(
10+
test_dir,
11+
|path, _is_dir| filter_dirs(path) || filter_not_rust(path),
12+
&mut |entry, contents| {
13+
for (i, line) in contents.lines().enumerate() {
14+
if line.contains("borrowck_graphviz_postflow") {
15+
tidy_error!(
16+
bad,
17+
"{}:{}: {}",
18+
entry.path().display(),
19+
i + 1,
20+
GRAPHVIZ_POSTFLOW_MSG
21+
);
22+
}
1323
}
14-
}
15-
});
24+
},
25+
);
1626
}

Diff for: src/tools/tidy/src/edition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn is_edition_2021(mut line: &str) -> bool {
99
}
1010

1111
pub fn check(path: &Path, bad: &mut bool) {
12-
walk(path, |path| filter_dirs(path), &mut |entry, contents| {
12+
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
1313
let file = entry.path();
1414
let filename = file.file_name().unwrap();
1515
if filename != "Cargo.toml" {

Diff for: src/tools/tidy/src/error_codes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn check_error_codes_docs(
129129

130130
let mut no_longer_emitted_codes = Vec::new();
131131

132-
walk(&docs_path, |_| false, &mut |entry, contents| {
132+
walk(&docs_path, |_, _| false, &mut |entry, contents| {
133133
let path = entry.path();
134134

135135
// Error if the file isn't markdown.
@@ -321,7 +321,7 @@ fn check_error_codes_used(
321321

322322
let mut found_codes = Vec::new();
323323

324-
walk_many(search_paths, filter_dirs, &mut |entry, contents| {
324+
walk_many(search_paths, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
325325
let path = entry.path();
326326

327327
// Return early if we aren't looking at a source file.

Diff for: src/tools/tidy/src/features.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn check(
102102
&tests_path.join("rustdoc-ui"),
103103
&tests_path.join("rustdoc"),
104104
],
105-
|path| {
105+
|path, _is_dir| {
106106
filter_dirs(path)
107107
|| filter_not_rust(path)
108108
|| path.file_name() == Some(OsStr::new("features.rs"))
@@ -478,7 +478,7 @@ fn map_lib_features(
478478
) {
479479
walk(
480480
base_src_path,
481-
|path| filter_dirs(path) || path.ends_with("tests"),
481+
|path, _is_dir| filter_dirs(path) || path.ends_with("tests"),
482482
&mut |entry, contents| {
483483
let file = entry.path();
484484
let filename = file.file_name().unwrap().to_string_lossy();

Diff for: src/tools/tidy/src/mir_opt_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
1111

1212
walk_no_read(
1313
&[&path.join("mir-opt")],
14-
|path| path.file_name() == Some("README.md".as_ref()),
14+
|path, _is_dir| path.file_name() == Some("README.md".as_ref()),
1515
&mut |file| {
1616
let filepath = file.path();
1717
if filepath.extension() == Some("rs".as_ref()) {

Diff for: src/tools/tidy/src/pal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn check(path: &Path, bad: &mut bool) {
6767
// Sanity check that the complex parsing here works.
6868
let mut saw_target_arch = false;
6969
let mut saw_cfg_bang = false;
70-
walk(path, filter_dirs, &mut |entry, contents| {
70+
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
7171
let file = entry.path();
7272
let filestr = file.to_string_lossy().replace("\\", "/");
7373
if !filestr.ends_with(".rs") {

Diff for: src/tools/tidy/src/rustdoc_gui_tests.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ use std::path::Path;
55
pub fn check(path: &Path, bad: &mut bool) {
66
crate::walk::walk(
77
&path.join("rustdoc-gui"),
8-
|p| {
9-
// If there is no extension, it's very likely a folder and we want to go into it.
10-
p.extension().map(|e| e != "goml").unwrap_or(false)
11-
},
8+
|p, is_dir| !is_dir && p.extension().map_or(true, |e| e != "goml"),
129
&mut |entry, content| {
1310
for line in content.lines() {
1411
if !line.starts_with("// ") {

Diff for: src/tools/tidy/src/style.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn is_unexplained_ignore(extension: &str, line: &str) -> bool {
227227
}
228228

229229
pub fn check(path: &Path, bad: &mut bool) {
230-
fn skip(path: &Path) -> bool {
230+
fn skip(path: &Path, is_dir: bool) -> bool {
231231
if path.file_name().map_or(false, |name| name.to_string_lossy().starts_with(".#")) {
232232
// vim or emacs temporary file
233233
return true;
@@ -237,8 +237,15 @@ pub fn check(path: &Path, bad: &mut bool) {
237237
return true;
238238
}
239239

240+
// Don't check extensions for directories
241+
if is_dir {
242+
return false;
243+
}
244+
240245
let extensions = ["rs", "py", "js", "sh", "c", "cpp", "h", "md", "css", "ftl", "goml"];
241-
if extensions.iter().all(|e| path.extension() != Some(OsStr::new(e))) {
246+
247+
// NB: don't skip paths without extensions (or else we'll skip all directories and will only check top level files)
248+
if path.extension().map_or(true, |ext| !extensions.iter().any(|e| ext == OsStr::new(e))) {
242249
return true;
243250
}
244251

Diff for: src/tools/tidy/src/target_specific_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct RevisionInfo<'a> {
3737
}
3838

3939
pub fn check(path: &Path, bad: &mut bool) {
40-
crate::walk::walk(path, filter_not_rust, &mut |entry, content| {
40+
crate::walk::walk(path, |path, _is_dir| filter_not_rust(path), &mut |entry, content| {
4141
let file = entry.path().display();
4242
let mut header_map = BTreeMap::new();
4343
iter_header(content, &mut |cfg, directive| {

Diff for: src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn check(path: &Path, bad: &mut bool) {
5151
check_entries(&path, bad);
5252
let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps"));
5353
let paths = [ui.as_path(), ui_fulldeps.as_path()];
54-
crate::walk::walk_no_read(&paths, |_| false, &mut |entry| {
54+
crate::walk::walk_no_read(&paths, |_, _| false, &mut |entry| {
5555
let file_path = entry.path();
5656
if let Some(ext) = file_path.extension() {
5757
if ext == "stderr" || ext == "stdout" {

Diff for: src/tools/tidy/src/unit_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ pub fn check(root_path: &Path, bad: &mut bool) {
2020
&& !(path.starts_with(&core_tests) || path.starts_with(&core_benches))
2121
};
2222

23-
let skip = move |path: &Path| {
23+
let skip = move |path: &Path, is_dir| {
2424
let file_name = path.file_name().unwrap_or_default();
25-
if path.is_dir() {
25+
if is_dir {
2626
filter_dirs(path)
2727
|| path.ends_with("src/doc")
2828
|| (file_name == "tests" || file_name == "benches") && !is_core(path)

Diff for: src/tools/tidy/src/walk.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ pub fn filter_not_rust(path: &Path) -> bool {
4141

4242
pub fn walk(
4343
path: &Path,
44-
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
44+
skip: impl Send + Sync + 'static + Fn(&Path, bool) -> bool,
4545
f: &mut dyn FnMut(&DirEntry, &str),
4646
) {
4747
walk_many(&[path], skip, f);
4848
}
4949

5050
pub fn walk_many(
5151
paths: &[&Path],
52-
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
52+
skip: impl Send + Sync + 'static + Fn(&Path, bool) -> bool,
5353
f: &mut dyn FnMut(&DirEntry, &str),
5454
) {
5555
let mut contents = Vec::new();
@@ -67,14 +67,16 @@ pub fn walk_many(
6767

6868
pub(crate) fn walk_no_read(
6969
paths: &[&Path],
70-
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
70+
skip: impl Send + Sync + 'static + Fn(&Path, bool) -> bool,
7171
f: &mut dyn FnMut(&DirEntry),
7272
) {
7373
let mut walker = ignore::WalkBuilder::new(paths[0]);
7474
for path in &paths[1..] {
7575
walker.add(path);
7676
}
77-
let walker = walker.filter_entry(move |e| !skip(e.path()));
77+
let walker = walker.filter_entry(move |e| {
78+
!skip(e.path(), e.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
79+
});
7880
for entry in walker.build() {
7981
if let Ok(entry) = entry {
8082
if entry.file_type().map_or(true, |kind| kind.is_dir() || kind.is_symlink()) {

Diff for: tests/rustdoc/issue-108925.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ pub enum MyThing {
88
#[doc(hidden)]
99
NotShown,
1010
}
11-

Diff for: tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const fn to_usize<T: 'static>() -> usize {
1717
match TypeId::of::<T>() {
1818
WHAT_A_TYPE => 0,
1919
_ => 1000,
20-
}
20+
}
2121
}
2222
impl<T: 'static> AssocCt for T {
2323
const ASSOC: usize = to_usize::<T>();

0 commit comments

Comments
 (0)