When I start a new project or file, I often have a lot of functions beeing empty, with
unimplemented!() in them, to lay out the basic structure, implement some traits and so on. However, all the lint warnings of having unused code, unused variables and so on really annoy me. But I hesitate to put an
allow on top of the file because when I implement those functions, I want to have them back and am fearing to forget deleting that again. In my opinion, a good way to go would be to disable those warnings of there is an
unimplemented!() in the function, but I think that wouldn't go well with a generalized macro syntax..
Do you have any suggestions/ how do you deal with this case?
One suggestion is not to forget deleting
allow attributes... Another is to use commit hook or push hook so that you can't commit/push
Yeah, as I read my finished post I also thought it really isn't that hard to delete them later, but those commit hooks sound interesting, I've never used them before and will look into that, thanks
I often write code from the inside out. so I start working on the called function first instead of the callee. With traits, what I do is add the return type after implementing it
You can add a single leading underscore before you function and variable name:
fn _todo() and
let _todo to mark them as unused.
What's more, I strongly recommend you to use cargo clippy. It has a lint call used_underscore_binding which can make sure that you don't forget to remove the leading underscore after they are finally implemented and used.
What I don't like about this approach is that when you start implementing things, u have to manually delete all those underscores. I think I'll try the earlier mentioned commit hook method, that sounded really promising. But thanks anyways
You don't have to do the deletion by hand. Make good use of your IDE and some text processing tools such as sed.
Iirc when you run clippy it will fix the code automatically
Am i missing some arguments? Clippy doesn't fix my code.
Not sure. Haven't used clippy for a while now.
For me, clippy only spits out warnings that I fix manually. Not sure if it can be done differently, but that seems to be pretty much the default.
Another solution is to disable the warnings from the command line. For example :
RUSTFLAGS="-A dead_code" cargo build
You could make an alias for that.
You may forget to check without that before commiting. To prevent that, you can use a pre-commit hook (with Git) where you compile with the "-D dead_code" to make sure you can't inadvertently commit with unused code.