Skip to content

Document diverging functions, and ⊥, better #7538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
catamorphism opened this issue Jul 1, 2013 · 7 comments
Closed

Document diverging functions, and ⊥, better #7538

catamorphism opened this issue Jul 1, 2013 · 7 comments
Labels
A-type-system Area: Type system P-low Low priority

Comments

@catamorphism
Copy link
Contributor

As per discussion on IRC, it's surprising at first that return(); is an expression. What's the result type of this expression? Bottom / | , but since you can't write this type explicitly in Rust, it's confusing.

Likewise, it's tempting to invoke fn f() -> ! when trying to explain ⊥, but that's different -- it means "f definitely diverges".

So, document these clearly and precisely in the manual / tutorial.

@catamorphism
Copy link
Contributor Author

Nominating for milestone 1, well-defined. It's not that we don't know what the semantics are here, just that it would be good to explain them better.

@catamorphism
Copy link
Contributor Author

@thestinger asked whether we couldn't just get rid of ! and use an uninhabited enum type instead. Off the top of my head I can't think of why not. (For example, std::util::void.) This would eliminate confusion about the meaning of ! in the pipes compiler vs. diverging functions.

@mstewartgallus
Copy link
Contributor

@catamorphism It was explained to me on IRC a while ago when I asked why one couldn't use a polymorphic return type (instead of a void type I suggested forall a, a but that's basically the same idea) that ! is needed because the compiler needs extra information for borrowing purposes. I believe it was @brson who explained this to me but I don't quite remember.

@catamorphism
Copy link
Contributor Author

@sstewartgallus For borrowing, an uninhabited type would carry the exact same amount of information that ! does, AFAIK. Since it's impossible to construct a result of that type, declaring "I return Void" is the same as what ! says. Within the compiler, it's easy to look up a type and see if it corresponds to an enum with no variants. SO I think this is do-able.

@catamorphism
Copy link
Contributor Author

Accepted for production-ready

@pnkfelix
Copy link
Member

P-low, not 1.0 blocker

@steveklabnik
Copy link
Member

#22275 documents these in the book, and we have info in the reference.

flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 3, 2021
Check expr usage for  `manual_flatten`

Fixes rust-lang#6784
Fixes rust-lang#7538

`manual_flatten` should not trigger when `if let` match expression will be used.

changelog: [`manual_flatten`] checks for expr usage after `if let`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system P-low Low priority
Projects
None yet
Development

No branches or pull requests

4 participants