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

unreachable expression on derive macro #4

Open
Boog900 opened this issue Jul 14, 2023 · 0 comments
Open

unreachable expression on derive macro #4

Boog900 opened this issue Jul 14, 2023 · 0 comments

Comments

@Boog900
Copy link
Owner

Boog900 commented Jul 14, 2023

When using epee_flatten on a struct with only 1 field it gives an unreachable expression error.

for example:

/// A Support Flags Response
#[derive(Debug, Clone, EpeeObject, PartialEq, Eq)]
pub struct SupportFlagsResponse {
    /// Support Flags
    #[epee_flatten]
    pub support_flags: PeerSupportFlags,
}

This is because the add field function expands to:

fn add_field<R: epee_encoding::io::Read>(
    &mut self,
    name: &str,
    r: &mut R,
) -> epee_encoding::error::Result<bool> {
    match name {
        _ => {
            if self.support_flags.add_field(name, r)? {
                return Ok(true);
            }
            return Ok(false);
        }
    };
    Ok(true)
}

and the Ok(true) is unreachable

Edit: This will happen no matter how many fields you have as long as they are all flattened:

fn add_field<R: epee_encoding::io::Read>(
    &mut self,
    name: &str,
    r: &mut R,
) -> epee_encoding::error::Result<bool> {
    match name {
        _ => {
            if self.support_flags.add_field(name, r)? {
                return Ok(true);
            }
            if self.some_other_field.add_field(name, r)? {
               return Ok(true);
            }
            return Ok(false);
        }
    };
    Ok(true)
}
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

1 participant