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

Conditional compilation fails if enum variants use from() #47

Open
yawor opened this issue Jul 30, 2019 · 1 comment
Open

Conditional compilation fails if enum variants use from() #47

yawor opened this issue Jul 30, 2019 · 1 comment

Comments

@yawor
Copy link

yawor commented Jul 30, 2019

Hi,
I've stumbled upon an error when I've tried to add conditional compilation to my quick_error defined Error enum. Here's an example:

quick_error! {
    #[derive(Debug)]
    pub enum Error {
        Io(err: std::io::Error) {
            cause(err)
            from()
            display("I/O error: {}", err)
        }
        #[cfg(feature="ssh2")]
        Ssh(err: ssh2::Error) {
            cause(err)
            from()
            display("SSH error: {}", err)
        }
        Net(err: std::net::AddrParseError) {
            cause(err)
            from()
            display("Network error: {}", err)
        }
        Zmq(err: zmq::Error) {
            cause(err)
            from()
            display("ZMQ error: {}", err)
        }
        Other(desc: String) {
            description(desc)
            from(desc: &str) -> (String::from(desc))
            from(err: Box<dyn std::error::Error>) -> (String::from(err.description()))
        }
    }
}

If I remove the from() from Ssh variant, then it compiles correctly. When I'm expanding the macro, I can see the #[cfg(feature="ssh2")] everywhere except for the

impl From<ssh2::Error> for Error {
    fn from(err: ssh2::Error) -> Error {
        Error::Ssh(err)
    }
}
@jmjoy
Copy link

jmjoy commented Dec 26, 2019

I meet the same problem.

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