12

Let's assume I wanted to write horrific and evil code that compiled with rustc. How many compiler-checks, type-checks, and warnings can I disable without recompiling Rust? And how would I go about doing it?

I'm looking for the Perl equivalent of no warnings; no strict;


Obviously I know this isn't good advice. I want to understand the configuration options of rustc the fun way.

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 1
    Allow, this kind of code would make any rust compiler not compliant, you ask the exact contrary that rust do. That doesn't make sense. – Stargateur Aug 24 '19 at 20:56
  • 1
    "Type checking" isn't really the kind of thing you can turn off; it's fundamental to how the compiler understands your code. Code that doesn't type check isn't merely *unsafe*, it's *nonsensical*. Some warnings can be turned off, mostly those considered "lints", but most of them are part of the type system -- there's simply no reason for them to have an off-switch. – trent Aug 24 '19 at 21:17
  • Great question. No good reason for any compiler to enforce style. Fight authoritarianism wherever it rears its ugly head. – devdanke Apr 10 '22 at 05:29

1 Answers1

15

You should be to silence warnings, and any unused arguments, etc. with #![allow(warnings, unused)]. However, I don't believe you can disable type checks or other compile errors: doing so would be pretty antithetical to a compiler's purpose. You would likely need to generate a syntax tree and then remove any errors by deleting lines from the source until the code compiles (or based on error suggestions), similar to how fuckitpy works.

For example, to silence all warnings, etc.:

#![allow(warnings, unused)]

unsafe fn iHaTeReAdAbLeCoDe(arg: u8, unused_arg: u32) -> u8 {
    let x: i32;
    arg
}

pub fn main() {
    print!("{:?}", unsafe {

                iHaTeReAdAbLeCoDe(5, 0)
    });
}

Please don't do this.

Alex Huszagh
  • 13,272
  • 3
  • 39
  • 67