Forbid use of certain macros or functions in a project


I was wondering whether there's a way to prevent usage of some functions or macros in a project. For instance we currently have a shell script that more or less grep for todo!, unimplemented!, and a couple more things during the pre-commit hook, but it's a bit shaky. Is there a better way to do this in Rust?

For todo! and unimplemented! there exist opt-in clippy lints.

So you can add deny(clippy::todo) (and similar for clippy::unimplemented) to your source. Maybe even forbid if you want to rule out the lint level being overwritten. If it’s for the pre-commit only, and you don’t want it in clippy in general, you can also use command flags, e.g. cargo clippy -- -F clippy::todo -F clippy::unimplemented. If you don’t want to use clippy beyond these lints, it’s also possible to add -A clippy::all to disable all other lints.


Thanks, I was hoping for a more general solution but for these at least I can rely on clippy now :slight_smile:

cargo-deny can handle more interesting tasks.

I could've sworn I've seen it handle denying use of certain item paths before, but that functionality isn't in the book...

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.