Skip to content

Commit 2acbe9c

Browse files
committedMay 5, 2024
Move some tests from rustc_expand to rustc_parse.
There are some test cases involving `parse` and `tokenstream` and `mut_visit` that are located in `rustc_expand`. Because it used to be the case that constructing a `ParseSess` required the involvement of `rustc_expand`. However, since rust-lang#64197 merged (a long time ago) `rust_expand` no longer needs to be involved. This commit moves the tests into `rustc_parse`. This is the optimal place for the `parse` tests. It's not ideal for the `tokenstream` and `mut_visit` tests -- they would be better in `rustc_ast` -- but they still rely on parsing, which is not available in `rustc_ast`. But `rustc_parse` is lower down in the crate graph and closer to `rustc_ast` than `rust_expand`, so it's still an improvement for them. The exact renaming is as follows: - rustc_expand/src/mut_visit/tests.rs -> rustc_parse/src/parser/mut_visit/tests.rs - rustc_expand/src/tokenstream/tests.rs -> rustc_parse/src/parser/tokenstream/tests.rs - rustc_expand/src/tests.rs + rustc_expand/src/parse/tests.rs -> compiler/rustc_parse/src/parser/tests.rs The latter two test files are combined because there's no need for them to be separate, and having a `rustc_parse::parser::parse` module would be weird. This also means some `pub(crate)`s can be removed.
1 parent 9c9b568 commit 2acbe9c

File tree

9 files changed

+405
-425
lines changed

9 files changed

+405
-425
lines changed
 

‎Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3976,7 +3976,6 @@ dependencies = [
39763976
"rustc_session",
39773977
"rustc_span",
39783978
"smallvec",
3979-
"termcolor",
39803979
"thin-vec",
39813980
"tracing",
39823981
]
@@ -4464,6 +4463,7 @@ dependencies = [
44644463
"rustc_macros",
44654464
"rustc_session",
44664465
"rustc_span",
4466+
"termcolor",
44674467
"thin-vec",
44684468
"tracing",
44694469
"unicode-normalization",

‎compiler/rustc_expand/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ rustc_serialize = { path = "../rustc_serialize" }
2525
rustc_session = { path = "../rustc_session" }
2626
rustc_span = { path = "../rustc_span" }
2727
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
28-
termcolor = "1.2"
2928
thin-vec = "0.2.12"
3029
tracing = "0.1"
3130
# tidy-alphabetical-end

‎compiler/rustc_expand/src/lib.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,4 @@ pub mod module;
3434
#[allow(rustc::untranslatable_diagnostic)]
3535
pub mod proc_macro;
3636

37-
// HACK(Centril, #64197): These shouldn't really be here.
38-
// Rather, they should be with their respective modules which are defined in other crates.
39-
// However, since for now constructing a `ParseSess` sorta requires `config` from this crate,
40-
// these tests will need to live here in the interim.
41-
42-
#[cfg(test)]
43-
mod tests;
44-
#[cfg(test)]
45-
mod parse {
46-
mod tests;
47-
}
48-
#[cfg(test)]
49-
mod tokenstream {
50-
mod tests;
51-
}
52-
#[cfg(test)]
53-
mod mut_visit {
54-
mod tests;
55-
}
56-
5737
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

‎compiler/rustc_expand/src/parse/tests.rs

Lines changed: 0 additions & 382 deletions
This file was deleted.

‎compiler/rustc_parse/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ tracing = "0.1"
2121
unicode-normalization = "0.1.11"
2222
unicode-width = "0.1.4"
2323
# tidy-alphabetical-end
24+
25+
[dev-dependencies]
26+
termcolor = "1.2"
27+

‎compiler/rustc_parse/src/parser/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ use crate::errors::{
4545
self, IncorrectVisibilityRestriction, MismatchedClosingDelimiter, NonStringAbiLiteral,
4646
};
4747

48+
#[cfg(test)]
49+
mod tests;
50+
51+
// Ideally, these tests would be in `rustc_ast`. But they depend on having a
52+
// parser, so they are here.
53+
#[cfg(test)]
54+
mod tokenstream {
55+
mod tests;
56+
}
57+
#[cfg(test)]
58+
mod mut_visit {
59+
mod tests;
60+
}
61+
4862
bitflags::bitflags! {
4963
#[derive(Clone, Copy)]
5064
struct Restrictions: u8 {

‎compiler/rustc_expand/src/mut_visit/tests.rs renamed to ‎compiler/rustc_parse/src/parser/mut_visit/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::tests::{matches_codepattern, string_to_crate};
2-
1+
use crate::parser::tests::{matches_codepattern, string_to_crate};
32
use rustc_ast as ast;
43
use rustc_ast::mut_visit::MutVisitor;
54
use rustc_ast_pretty::pprust;

‎compiler/rustc_expand/src/tests.rs renamed to ‎compiler/rustc_parse/src/parser/tests.rs

Lines changed: 384 additions & 17 deletions
Large diffs are not rendered by default.

‎compiler/rustc_expand/src/tokenstream/tests.rs renamed to ‎compiler/rustc_parse/src/parser/tokenstream/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::tests::string_to_stream;
2-
1+
use crate::parser::tests::string_to_stream;
32
use rustc_ast::token::{self, IdentIsRaw};
43
use rustc_ast::tokenstream::{TokenStream, TokenTree};
54
use rustc_span::create_default_session_globals_then;

0 commit comments

Comments
 (0)
Please sign in to comment.