Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Interesting. Is there any plausible way that Rust can fall into the == vs = trap?


No, as assignment always results in (), and if always requires a boolean. This is by design.


Ah...so this works:

  fn main() {
      let mut x = false;
      println!("{}", x);
      if {x=true;x} {
          println!("{}", x);
      }
  }
But stands out as pretty obvious. Not something you might easily sneak into a codebase.


Sneaky! Yeah, no way this should get past code review, and not even easy to accidentally type.


I haven't yet reached the level of Rust mastery where I'm confident in this answer, but as far as I can tell it's very hard to make that kind of mistake. I'd be very interested to hear what others have to say on it though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: