diesel-derive-enum
diesel-derive-enum copied to clipboard
Empty enum produces warning
The following code:
#[derive(Debug, diesel_derive_enum::DbEnum, diesel::SqlType)]
pub enum A {}
will lead to compiler warning:
warning: unreachable expression
--> src/lib.rs:1:17
|
1 | #[derive(Debug, diesel_derive_enum::DbEnum, diesel::SqlType)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| unreachable expression
| any code following this expression is unreachable
Particularly, if expand the macro issue is clearly seen at ToSql<AMapping, DB>
:
impl<DB: Backend> ToSql<AMapping, DB> for A {
fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> serialize::Result {
match *self {}
Ok(IsNull::No) // <- that one is unreachable
}
}
Hmm. What do you think should happen with an empty enum, hard failure? I agree that a warning isn't very helpful.
Well, I actually found it out by an accident, but probably it can be useful with "never" type, e.g. in postgres: CREATE TYPE NeverType AS ENUM ()
. Though, I'm not even sure if it works with diesel properly, but probably might be handy, if so.
Yes, I suppose the easiest thing to do it just remove the match block if there are no variants. No idea if that is really useful to anyone but it would remove the warning.