Debian Codegraph @

third_party/rust/syn/tests/repo/mod.rs

raw
1 #![allow(clippy::manual_assert)]
2
3 mod progress;
4
5 use self::progress::Progress;
6 use anyhow::Result;
7 use flate2::read::GzDecoder;
8 use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
9 use rayon::ThreadPoolBuilder;
10 use std::collections::BTreeSet;
11 use std::env;
12 use std::ffi::OsStr;
13 use std::fs;
14 use std::path::{Path, PathBuf};
15 use tar::Archive;
16 use walkdir::{DirEntry, WalkDir};
17
18 const REVISION: &str = "86d69c705a552236a622eee3fdea94bf13c5f102";
19
20 #[rustfmt::skip]
21 static EXCLUDE_FILES: &[&str] = &[
22 // TODO: non-lifetime binders: `where for<'a, T> &'a Struct<T>: Trait`
23 // https://github.com/dtolnay/syn/issues/1435
24 "src/tools/rustfmt/tests/source/issue_5721.rs",
25 "src/tools/rustfmt/tests/source/non-lifetime-binders.rs",
26 "src/tools/rustfmt/tests/target/issue_5721.rs",
27 "src/tools/rustfmt/tests/target/non-lifetime-binders.rs",
28 "tests/rustdoc-json/non_lifetime_binders.rs",
29 "tests/rustdoc/inline_cross/auxiliary/non_lifetime_binders.rs",
30 "tests/rustdoc/non_lifetime_binders.rs",
31
32 // TODO: return type notation: `where T: Trait<method(): Send>` and `where T::method(..): Send`
33 // https://github.com/dtolnay/syn/issues/1434
34 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/return_type_syntax_assoc_type_bound.rs",
35 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/return_type_syntax_in_path.rs",
36 "src/tools/rustfmt/tests/target/return-type-notation.rs",
37 "tests/ui/associated-type-bounds/return-type-notation/basic.rs",
38 "tests/ui/associated-type-bounds/return-type-notation/higher-ranked-bound-works.rs",
39 "tests/ui/associated-type-bounds/return-type-notation/namespace-conflict.rs",
40 "tests/ui/associated-type-bounds/return-type-notation/path-constrained-in-method.rs",
41 "tests/ui/associated-type-bounds/return-type-notation/path-self-qself.rs",
42 "tests/ui/associated-type-bounds/return-type-notation/path-works.rs",
43 "tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs",
44 "tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs",
45 "tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs",
46 "tests/ui/async-await/return-type-notation/supertrait-bound.rs",
47 "tests/ui/borrowck/alias-liveness/rtn-static.rs",
48 "tests/ui/feature-gates/feature-gate-return_type_notation.rs",
49
50 // TODO: lazy type alias syntax with where-clause in trailing position
51 // https://github.com/dtolnay/syn/issues/1525
52 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/type_item_where_clause.rs",
53 "src/tools/rustfmt/tests/source/type-alias-where-clauses-with-comments.rs",
54 "src/tools/rustfmt/tests/source/type-alias-where-clauses.rs",
55 "src/tools/rustfmt/tests/target/type-alias-where-clauses-with-comments.rs",
56 "src/tools/rustfmt/tests/target/type-alias-where-clauses.rs",
57 "tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs",
58
59 // TODO: gen blocks and functions
60 // https://github.com/dtolnay/syn/issues/1526
61 "compiler/rustc_codegen_cranelift/example/gen_block_iterate.rs",
62 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/gen_blocks.rs",
63 "tests/ui/coroutine/async-gen-deduce-yield.rs",
64 "tests/ui/coroutine/async-gen-yield-ty-is-unit.rs",
65 "tests/ui/coroutine/async_gen_fn_iter.rs",
66 "tests/ui/coroutine/gen_block_is_fused_iter.rs",
67 "tests/ui/coroutine/gen_block_is_iter.rs",
68 "tests/ui/coroutine/gen_block_iterate.rs",
69 "tests/ui/coroutine/gen_fn_iter.rs",
70 "tests/ui/coroutine/gen_fn_lifetime_capture.rs",
71 "tests/ui/coroutine/other-attribute-on-gen.rs",
72 "tests/ui/coroutine/return-types-diverge.rs",
73 "tests/ui/higher-ranked/builtin-closure-like-bounds.rs",
74 "tests/ui/sanitizer/cfi/coroutine.rs",
75
76 // TODO: `!` as a pattern
77 // https://github.com/dtolnay/syn/issues/1546
78 "tests/mir-opt/building/match/never_patterns.rs",
79 "tests/ui/rfcs/rfc-0000-never_patterns/diverges.rs",
80 "tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.rs",
81
82 // TODO: async trait bounds: `impl async Fn()`
83 // https://github.com/dtolnay/syn/issues/1628
84 "src/tools/miri/tests/pass/async-closure-captures.rs",
85 "src/tools/miri/tests/pass/async-closure-drop.rs",
86 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/async_trait_bound.rs",
87 "src/tools/rustfmt/tests/target/asyncness.rs",
88 "tests/codegen/async-closure-debug.rs",
89 "tests/coverage/async_closure.rs",
90 "tests/ui/async-await/async-closures/async-fn-mut-for-async-fn.rs",
91 "tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs",
92 "tests/ui/async-await/async-closures/auxiliary/foreign.rs",
93 "tests/ui/async-await/async-closures/body-check-on-non-fnmut.rs",
94 "tests/ui/async-await/async-closures/box-deref-in-debuginfo.rs",
95 "tests/ui/async-await/async-closures/brand.rs",
96 "tests/ui/async-await/async-closures/captures.rs",
97 "tests/ui/async-await/async-closures/clone-closure.rs",
98 "tests/ui/async-await/async-closures/constrained-but-no-upvars-yet.rs",
99 "tests/ui/async-await/async-closures/debuginfo-by-move-body.rs",
100 "tests/ui/async-await/async-closures/drop.rs",
101 "tests/ui/async-await/async-closures/force-move-due-to-inferred-kind.rs",
102 "tests/ui/async-await/async-closures/foreign.rs",
103 "tests/ui/async-await/async-closures/inline-body.rs",
104 "tests/ui/async-await/async-closures/mangle.rs",
105 "tests/ui/async-await/async-closures/moro-example.rs",
106 "tests/ui/async-await/async-closures/move-is-async-fn.rs",
107 "tests/ui/async-await/async-closures/mut-ref-reborrow.rs",
108 "tests/ui/async-await/async-closures/no-borrow-from-env.rs",
109 "tests/ui/async-await/async-closures/non-copy-arg-does-not-force-inner-move.rs",
110 "tests/ui/async-await/async-closures/overlapping-projs.rs",
111 "tests/ui/async-await/async-closures/precise-captures.rs",
112 "tests/ui/async-await/async-closures/refd.rs",
113 "tests/ui/async-await/async-closures/signature-deduction.rs",
114 "tests/ui/async-await/async-fn/edition-2015-not-async-bound.rs",
115 "tests/ui/async-await/async-fn/higher-ranked-async-fn.rs",
116 "tests/ui/async-await/async-fn/impl-trait.rs",
117 "tests/ui/async-await/async-fn/project.rs",
118 "tests/ui/async-await/async-fn/sugar.rs",
119
120 // TODO: mutable by-reference bindings (mut ref)
121 // https://github.com/dtolnay/syn/issues/1629
122 "src/tools/rustfmt/tests/source/mut_ref.rs",
123 "src/tools/rustfmt/tests/target/mut_ref.rs",
124 "tests/ui/mut/mut-ref.rs",
125
126 // TODO: postfix match
127 // https://github.com/dtolnay/syn/issues/1630
128 "src/tools/rustfmt/tests/source/postfix-match/pf-match.rs",
129 "src/tools/rustfmt/tests/target/postfix-match/pf-match.rs",
130 "tests/pretty/postfix-match/simple-matches.rs",
131 "tests/ui/match/postfix-match/no-unused-parens.rs",
132 "tests/ui/match/postfix-match/pf-match-chain.rs",
133 "tests/ui/match/postfix-match/postfix-match.rs",
134
135 // TODO: delegation
136 // https://github.com/dtolnay/syn/issues/1580
137 "tests/pretty/delegation.rs",
138 "tests/ui/delegation/body-identity-glob.rs",
139 "tests/ui/delegation/body-identity-list.rs",
140 "tests/ui/delegation/explicit-paths-in-traits-pass.rs",
141 "tests/ui/delegation/explicit-paths-pass.rs",
142 "tests/ui/delegation/explicit-paths-signature-pass.rs",
143 "tests/ui/delegation/fn-header.rs",
144 "tests/ui/delegation/generics/free-fn-to-free-fn-pass.rs",
145 "tests/ui/delegation/generics/free-fn-to-trait-method-pass.rs",
146 "tests/ui/delegation/generics/impl-to-free-fn-pass.rs",
147 "tests/ui/delegation/generics/impl-trait-to-trait-method-pass.rs",
148 "tests/ui/delegation/generics/inherent-impl-to-trait-method-pass.rs",
149 "tests/ui/delegation/generics/trait-method-to-other-pass.rs",
150 "tests/ui/delegation/glob-glob.rs",
151 "tests/ui/delegation/glob-override.rs",
152 "tests/ui/delegation/glob.rs",
153 "tests/ui/delegation/impl-trait.rs",
154 "tests/ui/delegation/list.rs",
155 "tests/ui/delegation/macro-inside-glob.rs",
156 "tests/ui/delegation/macro-inside-list.rs",
157 "tests/ui/delegation/method-call-priority.rs",
158 "tests/ui/delegation/parse.rs",
159 "tests/ui/delegation/rename.rs",
160 "tests/ui/delegation/self-coercion.rs",
161
162 // TODO: for await
163 // https://github.com/dtolnay/syn/issues/1631
164 "tests/ui/async-await/for-await-2015.rs",
165 "tests/ui/async-await/for-await-passthrough.rs",
166 "tests/ui/async-await/for-await.rs",
167
168 // TODO: const trait bound: `T: const Trait` and `impl const Trait` and `~const Trait`
169 // https://github.com/dtolnay/syn/issues/1632
170 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/const_trait_bound.rs",
171 "tests/ui/generic-const-items/const-trait-impl.rs",
172 "tests/ui/traits/const-traits/tilde-const-syntax.rs",
173
174 // TODO: unparenthesized half-open range pattern inside slice pattern: `[1..]`
175 // https://github.com/dtolnay/syn/issues/1769
176 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/range_pat.rs",
177 "tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs",
178
179 // TODO: pinned type sugar: `&pin const Self`
180 // https://github.com/dtolnay/syn/issues/1770
181 "src/tools/rustfmt/tests/source/pin_sugar.rs",
182 "src/tools/rustfmt/tests/target/pin_sugar.rs",
183 "tests/ui/async-await/pin-sugar.rs",
184
185 // TODO: `|| .. .method()`
186 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/closure_range_method_call.rs",
187 "src/tools/rustfmt/tests/source/issue-4808.rs",
188
189 // Several of the above
190 "tests/ui/unpretty/expanded-exhaustive.rs",
191
192 // Rustc bug: https://github.com/rust-lang/rust/issues/132080
193 "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0073_safe_declarations_in_extern_blocks.rs",
194
195 // Compile-fail expr parameter in const generic position: f::<1 + 2>()
196 "tests/ui/const-generics/early/closing-args-token.rs",
197 "tests/ui/const-generics/early/const-expression-parameter.rs",
198
199 // Compile-fail variadics in not the last position of a function parameter list
200 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/fn_def_param.rs",
201 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/param_list_vararg.rs",
202 "tests/ui/parser/variadic-ffi-syntactic-pass.rs",
203
204 // Need at least one trait in impl Trait, no such type as impl 'static
205 "tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs",
206
207 // Negative polarity trait bound: `where T: !Copy`
208 "src/tools/rustfmt/tests/target/negative-bounds.rs",
209 "tests/ui/traits/negative-bounds/supertrait.rs",
210
211 // Const impl that is not a trait impl: `impl ~const T {}`
212 "tests/ui/traits/const-traits/syntax.rs",
213
214 // Lifetimes and types out of order in angle bracketed path arguments
215 "tests/ui/parser/constraints-before-generic-args-syntactic-pass.rs",
216
217 // Deprecated anonymous parameter syntax in traits
218 "src/tools/rustfmt/tests/source/trait.rs",
219 "src/tools/rustfmt/tests/target/trait.rs",
220 "tests/ui/issues/issue-13105.rs",
221 "tests/ui/issues/issue-13775.rs",
222 "tests/ui/issues/issue-34074.rs",
223 "tests/ui/proc-macro/trait-fn-args-2015.rs",
224
225 // Deprecated where-clause location
226 "src/tools/rustfmt/tests/source/issue_4257.rs",
227 "src/tools/rustfmt/tests/source/issue_4911.rs",
228 "src/tools/rustfmt/tests/target/issue_4257.rs",
229 "src/tools/rustfmt/tests/target/issue_4911.rs",
230 "tests/pretty/gat-bounds.rs",
231 "tests/rustdoc/generic-associated-types/gats.rs",
232
233 // Deprecated trait object syntax with parenthesized generic arguments and no dyn keyword
234 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/bare_dyn_types_with_paren_as_generic_args.rs",
235 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/path_fn_trait_args.rs",
236 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/typepathfn_with_coloncolon.rs",
237 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/value_parameters_no_patterns.rs",
238 "src/tools/rustfmt/tests/source/attrib.rs",
239 "src/tools/rustfmt/tests/source/closure.rs",
240 "src/tools/rustfmt/tests/source/existential_type.rs",
241 "src/tools/rustfmt/tests/source/fn-simple.rs",
242 "src/tools/rustfmt/tests/source/fn_args_layout-vertical.rs",
243 "src/tools/rustfmt/tests/source/issue-4689/one.rs",
244 "src/tools/rustfmt/tests/source/issue-4689/two.rs",
245 "src/tools/rustfmt/tests/source/paths.rs",
246 "src/tools/rustfmt/tests/source/structs.rs",
247 "src/tools/rustfmt/tests/target/attrib.rs",
248 "src/tools/rustfmt/tests/target/closure.rs",
249 "src/tools/rustfmt/tests/target/existential_type.rs",
250 "src/tools/rustfmt/tests/target/fn-simple.rs",
251 "src/tools/rustfmt/tests/target/fn.rs",
252 "src/tools/rustfmt/tests/target/fn_args_layout-vertical.rs",
253 "src/tools/rustfmt/tests/target/issue-4689/one.rs",
254 "src/tools/rustfmt/tests/target/issue-4689/two.rs",
255 "src/tools/rustfmt/tests/target/paths.rs",
256 "src/tools/rustfmt/tests/target/structs.rs",
257 "tests/codegen-units/item-collection/non-generic-closures.rs",
258 "tests/debuginfo/recursive-enum.rs",
259 "tests/pretty/closure-reform-pretty.rs",
260 "tests/run-make/reproducible-build-2/reproducible-build.rs",
261 "tests/run-make/reproducible-build/reproducible-build.rs",
262 "tests/ui/auxiliary/typeid-intrinsic-aux1.rs",
263 "tests/ui/auxiliary/typeid-intrinsic-aux2.rs",
264 "tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs",
265 "tests/ui/lifetimes/auxiliary/lifetime_bound_will_change_warning_lib.rs",
266 "tests/ui/lifetimes/bare-trait-object-borrowck.rs",
267 "tests/ui/lifetimes/bare-trait-object.rs",
268 "tests/ui/parser/bounds-obj-parens.rs",
269
270 // Various extensions to Rust syntax made up by rust-analyzer
271 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/const_param_default_path.rs",
272 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/use_tree_abs_star.rs",
273 "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0015_use_tree.rs",
274 "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0029_range_forms.rs",
275 "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0051_parameter_attrs.rs",
276 "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0055_dot_dot_dot.rs",
277 "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0068_item_modifiers.rs",
278 "src/tools/rust-analyzer/crates/syntax/test_data/parser/validation/0031_block_inner_attrs.rs",
279 "src/tools/rust-analyzer/crates/syntax/test_data/parser/validation/0038_endless_inclusive_range.rs",
280 "src/tools/rust-analyzer/crates/syntax/test_data/parser/validation/0045_ambiguous_trait_object.rs",
281 "src/tools/rust-analyzer/crates/syntax/test_data/parser/validation/0046_mutable_const_item.rs",
282
283 // Placeholder syntax for "throw expressions"
284 "compiler/rustc_errors/src/translation.rs",
285 "compiler/rustc_expand/src/module.rs",
286 "compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs",
287 "src/tools/clippy/tests/ui/needless_return.rs",
288 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/yeet_expr.rs",
289 "tests/pretty/yeet-expr.rs",
290 "tests/ui/try-trait/yeet-for-option.rs",
291 "tests/ui/try-trait/yeet-for-result.rs",
292
293 // Edition 2015 code using identifiers that are now keywords
294 // TODO: some of these we should probably parse
295 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/dyn_trait_type_weak.rs",
296 "src/tools/rustfmt/tests/source/configs/indent_style/block_call.rs",
297 "src/tools/rustfmt/tests/source/configs/use_try_shorthand/false.rs",
298 "src/tools/rustfmt/tests/source/configs/use_try_shorthand/true.rs",
299 "src/tools/rustfmt/tests/source/issue_1306.rs",
300 "src/tools/rustfmt/tests/source/try-conversion.rs",
301 "src/tools/rustfmt/tests/target/configs/indent_style/block_call.rs",
302 "src/tools/rustfmt/tests/target/configs/use_try_shorthand/false.rs",
303 "src/tools/rustfmt/tests/target/issue-1681.rs",
304 "src/tools/rustfmt/tests/target/issue_1306.rs",
305 "tests/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs",
306 "tests/ui/editions/edition-keywords-2015-2015.rs",
307 "tests/ui/editions/edition-keywords-2015-2018.rs",
308 "tests/ui/lint/lint_pre_expansion_extern_module_aux.rs",
309 "tests/ui/macros/macro-comma-support-rpass.rs",
310 "tests/ui/macros/try-macro.rs",
311 "tests/ui/parser/extern-crate-async.rs",
312 "tests/ui/try-block/try-is-identifier-edition2015.rs",
313
314 // Excessive nesting
315 "tests/ui/issues/issue-74564-if-expr-stack-overflow.rs",
316
317 // Testing tools on invalid syntax
318 "src/tools/rustfmt/tests/coverage/target/comments.rs",
319 "src/tools/rustfmt/tests/parser/issue-4126/invalid.rs",
320 "src/tools/rustfmt/tests/parser/issue_4418.rs",
321 "src/tools/rustfmt/tests/parser/stashed-diag.rs",
322 "src/tools/rustfmt/tests/parser/stashed-diag2.rs",
323 "src/tools/rustfmt/tests/parser/unclosed-delims/issue_4466.rs",
324 "src/tools/rustfmt/tests/source/configs/disable_all_formatting/true.rs",
325 "src/tools/rustfmt/tests/source/configs/spaces_around_ranges/false.rs",
326 "src/tools/rustfmt/tests/source/configs/spaces_around_ranges/true.rs",
327 "src/tools/rustfmt/tests/source/type.rs",
328 "src/tools/rustfmt/tests/target/configs/spaces_around_ranges/false.rs",
329 "src/tools/rustfmt/tests/target/configs/spaces_around_ranges/true.rs",
330 "src/tools/rustfmt/tests/target/type.rs",
331 "src/tools/rustfmt/tests/target/unsafe_extern_blocks.rs",
332 "tests/run-make/translation/test.rs",
333 "tests/ui/generics/issue-94432-garbage-ice.rs",
334
335 // Generated file containing a top-level expression, used with `include!`
336 "compiler/rustc_codegen_gcc/src/intrinsic/archs.rs",
337
338 // Not actually test cases
339 "tests/ui/lint/expansion-time-include.rs",
340 "tests/ui/macros/auxiliary/macro-comma-support.rs",
341 "tests/ui/macros/auxiliary/macro-include-items-expr.rs",
342 "tests/ui/macros/include-single-expr-helper.rs",
343 "tests/ui/macros/include-single-expr-helper-1.rs",
344 "tests/ui/parser/issues/auxiliary/issue-21146-inc.rs",
345 ];
346
347 #[rustfmt::skip]
348 static EXCLUDE_DIRS: &[&str] = &[
349 // Inputs that intentionally do not parse
350 "src/tools/rust-analyzer/crates/parser/test_data/parser/err",
351 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/err",
352
353 // Inputs that lex but do not necessarily parse
354 "src/tools/rust-analyzer/crates/parser/test_data/lexer",
355
356 // Inputs that used to crash rust-analyzer, but aren't necessarily supposed to parse
357 "src/tools/rust-analyzer/crates/syntax/test_data/parser/fuzz-failures",
358 "src/tools/rust-analyzer/crates/syntax/test_data/reparse/fuzz-failures",
359
360 // Inputs that crash rustc, making no claim about whether they are valid Rust
361 "tests/crashes",
362 ];
363
364 // Directories in which a .stderr implies the corresponding .rs is not expected
365 // to work.
366 static UI_TEST_DIRS: &[&str] = &["tests/ui", "tests/rustdoc-ui"];
367
368 pub fn for_each_rust_file(for_each: impl Fn(&Path) + Sync + Send) {
369 let mut rs_files = BTreeSet::new();
370
371 let repo_dir = Path::new("tests/rust");
372 for entry in WalkDir::new(repo_dir)
373 .into_iter()
374 .filter_entry(base_dir_filter)
375 {
376 let entry = entry.unwrap();
377 if !entry.file_type().is_dir() {
378 rs_files.insert(entry.into_path());
379 }
380 }
381
382 for ui_test_dir in UI_TEST_DIRS {
383 for entry in WalkDir::new(repo_dir.join(ui_test_dir)) {
384 let mut path = entry.unwrap().into_path();
385 if path.extension() == Some(OsStr::new("stderr")) {
386 loop {
387 rs_files.remove(&path.with_extension("rs"));
388 path = path.with_extension("");
389 if path.extension().is_none() {
390 break;
391 }
392 }
393 }
394 }
395 }
396
397 rs_files.par_iter().map(PathBuf::as_path).for_each(for_each);
398 }
399
400 pub fn base_dir_filter(entry: &DirEntry) -> bool {
401 let path = entry.path();
402
403 let mut path_string = path.to_string_lossy();
404 if cfg!(windows) {
405 path_string = path_string.replace('\\', "/").into();
406 }
407 let path_string = if path_string == "tests/rust" {
408 return true;
409 } else if let Some(path) = path_string.strip_prefix("tests/rust/") {
410 path
411 } else {
412 panic!("unexpected path in Rust dist: {}", path_string);
413 };
414
415 if path.is_dir() {
416 return !EXCLUDE_DIRS.contains(&path_string);
417 }
418
419 if path.extension() != Some(OsStr::new("rs")) {
420 return false;
421 }
422
423 !EXCLUDE_FILES.contains(&path_string)
424 }
425
426 #[allow(dead_code)]
427 pub fn edition(path: &Path) -> &'static str {
428 if path.ends_with("dyn-2015-no-warnings-without-lints.rs") {
429 "2015"
430 } else {
431 "2021"
432 }
433 }
434
435 #[allow(dead_code)]
436 pub fn abort_after() -> usize {
437 match env::var("ABORT_AFTER_FAILURE") {
438 Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"),
439 Err(_) => usize::MAX,
440 }
441 }
442
443 pub fn rayon_init() {
444 let stack_size = match env::var("RUST_MIN_STACK") {
445 Ok(s) => s.parse().expect("failed to parse RUST_MIN_STACK"),
446 Err(_) => 1024 * 1024 * if cfg!(debug_assertions) { 40 } else { 20 },
447 };
448 ThreadPoolBuilder::new()
449 .stack_size(stack_size)
450 .build_global()
451 .unwrap();
452 }
453
454 pub fn clone_rust() {
455 let needs_clone = match fs::read_to_string("tests/rust/COMMIT") {
456 Err(_) => true,
457 Ok(contents) => contents.trim() != REVISION,
458 };
459 if needs_clone {
460 download_and_unpack().unwrap();
461 }
462
463 let mut missing = String::new();
464 let test_src = Path::new("tests/rust");
465
466 let mut exclude_files_set = BTreeSet::new();
467 for exclude in EXCLUDE_FILES {
468 if !exclude_files_set.insert(exclude) {
469 panic!("duplicate path in EXCLUDE_FILES: {}", exclude);
470 }
471 for dir in EXCLUDE_DIRS {
472 if Path::new(exclude).starts_with(dir) {
473 panic!("excluded file {} is inside an excluded dir", exclude);
474 }
475 }
476 if !test_src.join(exclude).is_file() {
477 missing += "\ntests/rust/";
478 missing += exclude;
479 }
480 }
481
482 let mut exclude_dirs_set = BTreeSet::new();
483 for exclude in EXCLUDE_DIRS {
484 if !exclude_dirs_set.insert(exclude) {
485 panic!("duplicate path in EXCLUDE_DIRS: {}", exclude);
486 }
487 if !test_src.join(exclude).is_dir() {
488 missing += "\ntests/rust/";
489 missing += exclude;
490 missing += "/";
491 }
492 }
493
494 if !missing.is_empty() {
495 panic!("excluded test file does not exist:{}\n", missing);
496 }
497 }
498
499 fn download_and_unpack() -> Result<()> {
500 let url = format!(
501 "https://github.com/rust-lang/rust/archive/{}.tar.gz",
502 REVISION
503 );
504 let response = reqwest::blocking::get(url)?.error_for_status()?;
505 let progress = Progress::new(response);
506 let decoder = GzDecoder::new(progress);
507 let mut archive = Archive::new(decoder);
508 let prefix = format!("rust-{}", REVISION);
509
510 let tests_rust = Path::new("tests/rust");
511 if tests_rust.exists() {
512 fs::remove_dir_all(tests_rust)?;
513 }
514
515 for entry in archive.entries()? {
516 let mut entry = entry?;
517 let path = entry.path()?;
518 if path == Path::new("pax_global_header") {
519 continue;
520 }
521 let relative = path.strip_prefix(&prefix)?;
522 let out = tests_rust.join(relative);
523 entry.unpack(&out)?;
524 }
525
526 fs::write("tests/rust/COMMIT", REVISION)?;
527 Ok(())
528 }