Skip to content

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

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

Open
yawor opened this issue Jul 30, 2019 · 1 comment · May be fixed by #62
Open

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

yawor opened this issue Jul 30, 2019 · 1 comment · May be fixed by #62

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.

@kyrias kyrias linked a pull request Mar 11, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants