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

The standing joke for the last few years is that "the never type is named after its date of stabilization."

I certainly don't disagree that Rust has flaws, for sure. I think this particular one is pretty far down the list, though. I'm not sure what else I'd want to use ! for, and by virtue of it not being used so often means that it's much less of a pain than @T would have been, though I would also argue that 2012 Rust used ~T and @T far more than contemporary Rust does (I still remember pcwalton's mailing list post about how you didn't have to use ~ for comparing strings!) and so was even more painful at the time than would be now.



Swift and TypeScript use ! sort of like .unwrap(). Probably a better use of it than "never" tbh.


I'm not completely opposed but I'm also not sure syntax sugar for unwrap is a great idea.


If ! was just used as never it could still be used as an operator, because those are different contexts AFAICT. However, its use in macro invocations seems likely to be more difficult to differentiate from operators.


We actually use this version of never a lot in our code at $WORK

```

export function never(message?: string): never {

  throw new Error(message ?? 'Reached an impossible state');
}

const [foo = never()] = dbQueryThatReturnsOne();

```

I guess it's en par with .unwrap()




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

Search: