Uh oh!
There was an error while loading. Please reload this page.
Created utility uninhabited type - #6348
Conversation
brson
commented
May 9, 2013
Related to #4724 |
brson
commented
May 9, 2013
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. |
mstewartgallus
commented
May 9, 2013
@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. |
brson
commented
May 9, 2013
@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.mstewartgallus
commented
May 9, 2013
@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.Resolvesrust-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 Resolvesrust-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.
6421: Check for allow(..) attributes in case check diagnostic r=popzxc a=popzxc Resolvesrust-lang#6348 This is not a full-fledged solution, as it doesn't looks up for parent elements (e.g. function -> module -> parent module -> crate root), but it does at least checks attributes of item being checked. I played a bit with code, and it seems that implementing a proper solution (which will also check for `deny` / `warn` attributes overriding values for `allow`s from above). So, this solution should fix all the macros which intentionally do "weird" naming and wrap it with `allow`, such as `lazy_static`. cc @ArifRoktim Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
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.