Hacker News new | ask | show | jobs
by dralley 1074 days ago
This is just wrong? You can absolutely have unused variables in Rust. It's a compiler warning, not an error.

What you cannot have, is uninitialized variables which are used.

1 comments

If your development style demands uninitialized variables, you can set them to `= unimplemented!()` during development.

And as someone else said, if all you want is unused variables without warnings, you can say at the top of the root of the crate (`main.rs` or `lib.rs`):

    #![allow(dead_code)]
It might be worth noting that unimplemented!() is a thin wrapper around panic!(), so if execution makes it to that line, your program will crash.

Rust actually does allow uninitialized variables, even in safe code. But it'll be a compiler error if you try to use them in any way before initializing them, so this is mostly just a curiosity: https://play.rust-lang.org/?version=stable&mode=debug&editio...