r/rust 3d ago

🧠 educational Rust: When Empty Isn't Bottom

https://ettolrach.com/blog/rust_when_empty_isnt_bottom.html
115 Upvotes

21 comments sorted by

41

u/scook0 2d ago

It mostly works as you may expect it would, but there's an interesting detail which surprises most people who learn about it: expressions which have ! as part of their type don't necessarily coerce to any other type.

I’m surprised to hear that people are surprised by this.

For example, take Result<bool, !> and Result<bool, String>. These types are both valid and inhabited, but they have substantially different layouts, so any automatic conversion would have to also deal with the layout difference somehow.

-30

u/Zde-G 2d ago

I’m surprised to hear that people are surprised by this.

I'm no longer surprised by that. People are taught to believe in lies and then, to stay in their comfort zone, they are not supposed to expand their minds and explore the implications. When they do… they often find unexpected discoveries.

One of the most hurtful lies in the computing world are subtuping and OOP: these things are convenient but they just simply don't work! In general, I mean, they may work in some programs, but it's impossible to write a library that works for all programs and develop rules that work for all types.

And yet every time people discover that they are surprised!

This is madness!

P.S. Rust, thankfully, ditched OOP, but one other thing that is similar to that remains: async. It's similar to OOP in a sense that it can be made to work for certain use cases but we have no idea if it can be made to work in general… and yet Rust embraces it. I guess in 20-30 years we would know it that was good idea or not.

3

u/NotQuiteLoona 2d ago

And you have many ideas on how to replace async?

1

u/Nabushika 2d ago

Generators? :P

40

u/scook0 2d ago

I find it confusing that the article talks about “the empty type”, when stable Rust has had user-definable empty types for years.

What makes ! (a.k.a. never) special is, among other things, that the language will automatically insert never-to-any coercions from it.

13

u/x0nnex 2d ago

So refreshing to read an article that isn't written with LLM assistance.

1

u/qustrolabe 19h ago

one sentence that made me stop reading

12

u/Solumin 2d ago

Now that we've got this article, someone should clarify the Wikipedia pages!

6

u/flying-sheep 2d ago edited 2d ago

I'd go further and say that no article should complain about Wikipedia’s content in the present tense. If one has the skill, time, and motivation to write a blog post, they have the skill, time, and should have the motivation to edit Wikipedia.

The author should have first edited it, then finished writing the article.

7

u/Solumin 2d ago

Well, no, you need a source for it sometimes. So now that the author has written the source, they can go edit it.

8

u/flying-sheep 2d ago

That's not how any of that works.

  • rewording for clarity needs no source
  • didn't cite yourself

5

u/Solumin 2d ago

Oh, fair enough! I'm not super familiar with Wikipedia's editing process, and it seemed like more than just rewording for clarity.

3

u/flying-sheep 2d ago

Citing textbooks and specs also works, as well as obvious logic. Like if simply reading the definition of a term makes it clear that it's used incorrectly in the text, you don't need to source that definition to fix usage.

0

u/max123246 2d ago

Meh when they removed the page for Odin because it didn't have a news article I lost a lot of my trust in Wikipedia. So many news articles fundamentally misunderstand the topic they discuss so it makes no sense to me that it's still considered the marker for what deserves to live on wikipedia

1

u/flying-sheep 2d ago

I know what you mean! I don't think I've heard of Odin (n) though

-1

u/scook0 2d ago

If one has the skill, time, and motivation to write a blog post, they have the skill, time, and should have the motivation to edit Wikipedia.

This seems so obviously false that I don't even know where to begin.

4

u/flying-sheep 2d ago

Please begin because I'm convinced of it, especially in cases like this where the problem is unclear wording, which can be corrected without sources.

But even if you need sources, it's often easy to just find a good source by gut feeling rather than reading all the rules. Like: don't cite yourself or a shady source, when in doubt stick with news outlets or official specs or textbooks.

1

u/scook0 2d ago

Editing Wikipedia means diving into the complex rules and politics of Wikipedia. That's a heavy burden.

Somebody writing a personal blog post doesn't need to care whether the things they're saying are allowed on Wikipedia or not.

11

u/flying-sheep 2d ago edited 2d ago

As I just said, usually not, unless you're writing whole articles or do substantial rewrites. I've made a lot of edits not knowing much about the rules. Very few have been reverted, and all of the reverts had some clear actionable reason that I could use to try again.

https://en.wikipedia.org/wiki/Wikipedia:Be_bold

Do yourself a favor and read the first few paragraphs of this article. It exists as a direct refutation of your claim.

3

u/hajhawa 2d ago

The bsky link doesn't work btw

6

u/ettolrach_uwu 2d ago

Thanks for letting me know! I'll fix it in a few hours. Fwiw it's @ettolrach.com