Skip to content
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

Empty enum produces warning #48

Open
l4l opened this issue May 10, 2020 · 3 comments
Open

Empty enum produces warning #48

l4l opened this issue May 10, 2020 · 3 comments

Comments

@l4l
Copy link

l4l commented May 10, 2020

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
    }
}
@adwhit
Copy link
Owner

adwhit commented May 10, 2020

Hmm. What do you think should happen with an empty enum, hard failure? I agree that a warning isn't very helpful.

@l4l
Copy link
Author

l4l commented May 10, 2020

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.

@adwhit
Copy link
Owner

adwhit commented May 25, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants