Configuring `cargo check` targets

Heya! I have now run several times into the situation where I run cargo check and have everything checks fine, only to have cargo test then fail to compile because I forgot to adjust the tests.

This is in theory easy to fix, cargo test --tests or cargo test --all-targets would make sure those are also checked. But this is longer to type, and easy to forget. I could of course make an alias in my shell, write my own shellscript or any other external solution. But I am interested in the possibility of selecting which targets to check via configuration of cargo check?

I did not find anything that points towards this being possible right now, so my question would be, is this something that had been discussed? I tried looking but didn't find anything (cargo, check and configuration are not very low entropy words).

I could see this work mostly with an environment variable: CARGO_CHECK_TARGETS which takes similar values as the CLI: CARGO_CHECK_TARGETS=tests,bench=foo*, etc...

I would then set this as part of my dev environment and could share it with my colleagues for example. (How I would do that is out of scope here of course)

You can define Cargo aliases in .cargo/config.toml (which you can have in your project root and commit to VCS). Doesn’t help if you forget to use it rather than vanilla check, or if a colleague doesn’t know about the alias, but at least something like cargo ck is really fast to type.

I think it's worthwhile to have cargo check do the most useful normal thing.

I'm not sure whether you're arguing that cargo check should by default do some globally unique useful normal thing, or whether it should be customizable to do a project- or coder-specific useful normal thing? If the former, I claim there is no such thing, and if the latter, I don't disagree; I just meant to note that cargo aliases provide a partial solution (or "workaround") that works right now.

Aliases would only be a partial solution, but thanks for the reminder they exist!

I know that I won't get out of the habit writing cargo check and wouldn't want to go away from that.