diff options
author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-04-09 23:40:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-09 23:40:04 +0200 |
commit | 3dfda2c72fa8cb96b1be9968e99ab0b60175922b (patch) | |
tree | fe8604beae0573c9acad435732d2554f7f839047 /tests/rustdoc-js-std/parser-errors.js | |
parent | 4e165c1c9923e19fa91ddcdb09fbc9d07f7c29da (diff) | |
parent | 2c976765b8e426506285b334e0a1506c78b135e2 (diff) | |
download | rust-3dfda2c72fa8cb96b1be9968e99ab0b60175922b.tar.gz |
Rollup merge of #109985 - blyxyas:is_test_crate, r=compiler-errors
Add little `is_test_crate` function
Ok, this is quite a story.
I'm mainly a Clippy contributor, so I was fixing [this Clippy issue](https://github.com/rust-lang/rust-clippy/pull/10584) about a lint having to ignore test modules but that wasn't ignoring test files (integration test, `test/` dirs and such).
As test **files** don't tend to have an inner `#[cfg(test)]` module inside them, I tried everything, looking for filenames, looking for item's parents in the HIR Map, doing black magic...
I even asked [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/.E2.9C.94.20Checking.20if.20file.20is.20integration.20test), and jyn answered something about `--cfg test`. Aha! That's something that I might be looking for, so I started looking at `rustc_driver_impl` flag parsing and configuration and all that.
Then, I stumbled on [this function right here](https://github.com/rust-lang/rust/blob/2e486be8d29d198d48bc26bfce5712a4822814f5/compiler/rustc_driver_impl/src/lib.rs#L174-L181), and noticed the argument `config: Config`. That's a hint.
So [Config](https://doc.rust-lang.org/beta/nightly-rustc/rustc_interface/interface/struct.Config.html) has the field `opts: Options`, and [`Options`](https://doc.rust-lang.org/beta/nightly-rustc/rustc_session/options/struct.Options.html) has the field `test`.
This journey has been ~7 or 8 hours in 3 days, it's a very hard thing to find, so this PR adds a mini-function to check if the current crate is a testing one. So that no one has to travel through the same as me, and can just search for `is_test_crate` in the documentation.
Diffstat (limited to 'tests/rustdoc-js-std/parser-errors.js')
0 files changed, 0 insertions, 0 deletions