Add little is_test_crate function#109985
Conversation
|
r? @jackh726 (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
If you want to test for --cfg test, then you're gonna have to do something like tcx.sess.parse_sess.config.contains(sym::test), I think. --test implies --cfg test, but --cfg test does not imply --test.
I don't have enough background about what you needed this for to know whether that's what you wanted.
Also, side-note, this should be squashed into one commit.
|
It seems like it isn't necessary. |
|
Please also migrate all of the other usages of |
|
@rustbot author |
|
@rustbot ready |
|
@bors r+ |
|
⌛ Testing commit 2c97676 with merge f036f34036470ab3d5cdc9e762051e9588ef9321... |
|
💔 Test failed - checks-actions |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#108843 (Instantiate instead of erasing binder when probing param methods) - rust-lang#109985 (Add little `is_test_crate` function) - rust-lang#110028 (Migrate `rustc_hir_analysis` to session diagnostic [Part 3]) - rust-lang#110095 (Migrate remainder of rustc_ty_utils to `SessionDiagnostic`) - rust-lang#110108 (Add renaming of ignore-git to changelog) - rust-lang#110114 (compiletest: Give a better error message if `node` isn't installed) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
|
@bors retry crates.io network blip |
Ok, this is quite a story.
I'm mainly a Clippy contributor, so I was fixing this Clippy issue 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, and jyn answered something about
--cfg test. Aha! That's something that I might be looking for, so I started looking atrustc_driver_implflag parsing and configuration and all that.Then, I stumbled on this function right here, and noticed the argument
config: Config. That's a hint.So Config has the field
opts: Options, andOptionshas the fieldtest.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_cratein the documentation.