News for hackers. Stuff that matters.
Re:I Want Off Mr. Golang's Wild Ride by typon on Friday February 28, 2020 @03:00PM (#22445815)
It will not compile. (As I said earlier, you can always fallback to a panic aka "I don't wanna deal with the error so let my program crash", but an error will not silently propagate through the stack)
Re:I Want Off Mr. Golang's Wild Ride by cjhopman on Friday February 28, 2020 @07:42PM (#22447769)
That's is completely false, stop spreading misinformation.

This code will compile (see https://play.rust-lang.org/?version=stable&mode=debug&editio...):

  pub fn foo() -> Result<(), i64> {
      Err(1)
  }
  
  pub fn bar() -> Result<(), ()> {
      foo();
      Ok(())
  }

It will provide a warning, but there's a ton of stuff in c++ that would throw a warning and you wouldn't say that it "will not compile".

A trivial change that still doesn't handle the error would get rid of the warning.

  pub fn foo() -> Result<(), i64> {
      Err(1)
  }
  
  pub fn bar() -> Result<(), ()> {
      println!("{:?}", foo());
      Ok(())
  }
Re:I Want Off Mr. Golang's Wild Ride by eddyb on Sunday March 01, 2020 @04:10AM (#22455954)
I wonder if people upthread meant the warning, or e.g. getting the `Foo` in `Result<Foo, BarError>`.

(EDIT: nevermind, just looked again and pcwalton was referring to the warning and specifically `Result<(), E>`; oh well)

Because the latter is impossible in Rust and probably more relevant to the usual cited issue with Go's pair approach (i.e. using the null/zeroed `Foo` without checking if there was an error).

I do agree though that the warning isn't to stop you from not handling the error at all, it's more of a hint that maybe you forgot something.

Printing a `Result` may be the legitimate way to handle it in that case, it's largely left to the user to decide what propagates and what doesn't.