Skip to content

Comment on The Wake Programming Languageparent

Comments

The rule only applies at the ends of blocks/functions. The semicolon can only be omitted on trailing expressions. And, when it's omitted, the block/function takes on the value of that trailing expression. E.g. this is not valid Rust:

  fn foo(x: bool) -> i32 {
      if x { 
          1 // no semicolon on the 1
      }

      let a = 2 + 3;
      return a * 4;
  }
It's not implicitly returning the 1 from `foo`. An early return would need to be written `if x { return 1 }`. On the other hand, the `return a * 4;` could just be written `a * 4` since it's at the end of the function.

This rule means the scanning required is just looking at the end of the function.

In any case, having a static type system means I have never personally encountered a bug caused by this sort of implicit return in Rust.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.