Skip to content

Document diverging functions, and ⊥, better #7538

Closed
@catamorphism

Description

@catamorphism
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.

Activity

catamorphism

catamorphism commented on Jul 1, 2013

@catamorphism
ContributorAuthor

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

catamorphism commented on Jul 1, 2013

@catamorphism
ContributorAuthor

@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

mstewartgallus commented on Jul 2, 2013

@mstewartgallus
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

catamorphism commented on Jul 2, 2013

@catamorphism
ContributorAuthor

@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

catamorphism commented on Sep 5, 2013

@catamorphism
ContributorAuthor

Accepted for production-ready

pnkfelix

pnkfelix commented on Mar 20, 2014

@pnkfelix
Member

P-low, not 1.0 blocker

steveklabnik

steveklabnik commented on Feb 16, 2015

@steveklabnik
Member

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

added a commit that references this issue on Sep 3, 2021

Auto merge of rust-lang#7566 - dswij:manual-flatten-use, r=xFrednet

983e5b8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@pnkfelix@catamorphism@mstewartgallus

        Issue actions

          Document diverging functions, and ⊥, better · Issue #7538 · rust-lang/rust