-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Created utility uninhabited type #6348
Conversation
Related to #4724 |
Thanks! Can you give an example of how I think we probably also want to make In the future we might want to comb through the codebase to find places where We may also want some conversion traits, e.g. |
@brson I was using absurd because it was the name of the function that another person used when doing a similar thing in Haskell. However, I was thinking of using uninhabitable instead of absurd to highlight the similarities to the function unreachable because they have similar purposes, (or maybe name the type Uninhabited.) The use of absurd is similar to the use of uninhabitable. Consider a generic higher-order function "receive" that allows the user to optionable get a different type of value. In the following code absurd would simply be a less error prone alternative to unreachable.
Using the type *Void would make sense except it's not possible to stop someone from dereferencing such a pointer to get a Void value. Maybe there is some kind of lifetime weirdness that could prevent someone from doing such a thing? Or alternatively one might implement something along the lines of a trait Void where the trait is somehow impossible to implement. Then one could use *Void all one wants without danger of dereferencing it to a value. Personally I think that the best way of representing void pointers though is to think of them as using existential quantification. In other words, a void pointer is a pointer to a type T for some type T. This scheme can be implemented using traits (they quantify over the Self type.) I believe the following code works.
Then any pointer to a value should be easily castable to a pointer to an Object. Of course, one would have to use unsafe code to cast back. I don't remember how pointers to traits are represented. Is it possible to make a scheme like this be efficient, and compatible with C void pointers? Also, there is the issue of pointers to arrays of values. For example, the type &[Object] doesn't really make sense. |
@sstewartgallus Besides copying are there additional reasons that you would want to forbid dereferencing I like your idea about the |
In this commit I added a useful utility type, named Void, that encapsulates the doable but annoying job of creating an uninhabited type. As well, a function on that type, named absurd, was created which is useful for ignoring the result of matching on that type. No unit tests were created because it is not possible to create an instance of this type to test the usage of. This type is useful because it is like NonCopyable in that it can be used to create a type with special characteristics without special bloat. For instance, instead of typing pub struct PhantomType { priv contents : () } for each void type one may want to use one can simply type pub struct PhantomType (Void);. This type make such special cases much easier to write.
@brson Making the type I guess using Void for pointers would make sense then. I'm not sure that Object is really the same as an Any trait. As far as I understand an Any trait would have to have a few extra methods. Here's what I think an Any trait might be (with the implementations automatically generated by the compiler.)
And maybe there'd be a number identifying the type. As well, I'd suggest such a trait would make sense to be called something like Introspectable. |
In this commit I added a useful utility type, named Void, that encapsulates the doable but annoying job of creating an uninhabited type. As well, a function on that type, named absurd, was created which is useful for ignoring the result of matching on that type. No unit tests were created because it is not possible to create an instance of this type to test the usage of. This type is useful because it is like NonCopyable in that it can be used to create a type with special characteristics without special bloat. For instance, instead of typing pub struct PhantomType { priv contents : () } for each void type one may want to use one can simply type pub struct PhantomType (Void);. This type make such special cases much easier to write.
Resolves rust-lang#6348 Almost identical to print_stdout, this lint applies to the `eprintln!` and `eprint!` macros rather than `println!` and `print!`.
Add lint print_stderr Resolves rust-lang#6348 Almost identical to print_stdout, this lint applies to the `eprintln!` and `eprint!` macros rather than `println!` and `print!`. changelog: Add new lint [`print_stderr`]. [`println_empty_string`] and [`print_with_newline`] now apply to `eprint!()` and `eprintln!()` respectively.
In this commit I added a useful utility type, named Void, that encapsulates the
doable but annoying job of creating an uninhabited type. As well, a function on
that type, named absurd, was created which is useful for ignoring the result of
matching on that type. No unit tests were created because it is not possible to
create an instance of this type to test the usage of.
This type is useful because it is like NonCopyable in that it can be used to
create a type with special characteristics without special bloat. For instance,
instead of typing pub struct PhantomType { priv contents : () } for each void
type one may want to use one can simply type pub struct PhantomType (Void);.
This type make such special cases much easier to write.