Hacker News new | past | comments | ask | show | jobs | submit login

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)



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(())
  }


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.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: