top | item 36683301

(no title)

perth | 2 years ago

The thing that really ticks me off about RUST is it has compiler optimizations that can’t be turned off. In C++, you can typically turn off all optimizations, including optimizing away unused variables, in most compilers. In RUST it’s part of the language specification that you cannot have an unused variable, which, for me kills the language for me since I like having unused variables for debug while I’m stepping through the code.

discuss

order

vacuity|2 years ago

There isn't a Rust language specification, and you can use

  #![allow(dead_code)]
at the root of the crate

I'm not sure what you mean by "optimizing away unused variables", so I'm interpreting it as variables that are literally unused after declaration.

cesarb|2 years ago

> In RUST it’s part of the language specification that you cannot have an unused variable

I believe you're confusing Rust with Go. In Rust, an unused variable is just a warning, unless you explicitly asked the compiler to turn that warning (or all warnings) into an error.

coldtea|2 years ago

>which, for me kills the language for me since I like having unused variables for debug while I’m stepping through the code.

If they're unused, then they're not helping with debugging either...

It's quite a bizarre reason

Buttons840|2 years ago

Not true. Their debugger might display the value of the variables, which are unused outside the debugger. There are other options in Rust though, like logging. Create your "unused variable", and then use it in a debug log or dbg macro, etc.

groos|2 years ago

v = function_call(); // inspect v in debugger but it's 'unused' to the compiler.

At least this is how it works in C and C++.

dralley|2 years 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.

justinpombrio|2 years ago

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)]

IceSentry|2 years ago

Unused variables just generate warnings. It will still compile.