Skip to content

Warnings when compiling with packed_struct, crash with clippy #10

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

Closed
alexandre-janniaux opened this issue Feb 5, 2018 · 5 comments
Closed

Comments

@alexandre-janniaux
Copy link

Hello, I'm using your library for a student's project. Thank you for your work.

On any simple program implementing packed_struct, rustc is emitting the following warnings:

warning: unnecessary parentheses around assigned value
  --> src/main.rs:43:30
   |
43 | #[derive(Debug, Deserialize, PackedStruct)]
   |                              ^^^^^^^^^^^^ help: remove these parentheses
   |
   = note: #[warn(unused_parens)] on by default

warning: unnecessary parentheses around assigned value
  --> src/main.rs:43:30
   |
43 | #[derive(Debug, Deserialize, PackedStruct)]
   |                              ^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around assigned value
  --> src/main.rs:43:30
   |
43 | #[derive(Debug, Deserialize, PackedStruct)]
   |                              ^^^^^^^^^^^^ help: remove these parentheses

Moreover, clippy crashes when trying to lint the program. It shouldn't crash but it might unveil some flaws in the code of packed_struct.

For example, packed_struct prevents us from directly using error_chain! to handle errors, because of the following compile errors:

error[E0243]: wrong number of type arguments: expected 2, found 1
 --> src/units.rs:4:26
  |
4 | pub fn parse(s: &str) -> Result<u32> {
  |                          ^^^^^^^^^^^ expected 2 type arguments

error[E0244]: wrong number of type arguments: expected 1, found 2
  --> src/main.rs:43:30
   |
43 | #[derive(Debug, Deserialize, PackedStruct)]
   |                              ^^^^^^^^^^^^ expected 1 type argument

See also this issue on clippy: rust-lang/rust-clippy#2359

@rudib
Copy link
Member

rudib commented Feb 5, 2018

Compile warning: it'll be fixed with a generated attribute to ignore parenthesis warnings (#11).

Regarding clippy, this seems like a clippy bug and not at all related to any bugs in this crate.

For your last report, could you please post the structure from main.rs:43? I assume that the issue is that the structure has a generic field, which isn't supported at the moment. Still, it should at least emit an error about that.

@alexandre-janniaux
Copy link
Author

alexandre-janniaux commented Feb 7, 2018

Nice, thank you ! I didn't see this PR.

Sure, here is the struct:

#[derive(Debug, Deserialize, PackedStruct)] // this is line 43
#[packed_struct(bit_numbering = "msb0")]
pub struct LEDDriverConfig {
    #[packed_field(bits = "46..47")]
    lodvth: Integer<u8, ::packed_bits::Bits2>,
    #[packed_field(bits = "44..45")]
    sel_td0: Integer<u8, ::packed_bits::Bits2>,
    #[packed_field(bits = "43")]
    sel_gdly: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "42")]
    xrefresh: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "41")]
    sel_gck_edge: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "40")]
    sel_pchg: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "39")]
    espwm: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "38")]
    lgse3: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "37")]
    sel_sck_edge: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "34..36")]
    lgse1: Integer<u8, ::packed_bits::Bits3>,
    #[packed_field(bits = "25..33", endian = "msb")]
    ccb: Integer<u16, ::packed_bits::Bits9>,
    #[packed_field(bits = "16..24", endian = "msb")]
    ccg: Integer<u16, ::packed_bits::Bits9>,
    #[packed_field(bits = "7..15", endian = "msb")]
    ccr: Integer<u16, ::packed_bits::Bits9>,
    #[packed_field(bits = "4..6")]
    bc: Integer<u8, ::packed_bits::Bits3>,
    #[packed_field(bits = "3")]
    poker_trans_mode: Integer<u8, ::packed_bits::Bits1>,
    #[packed_field(bits = "0..2")]
    lgse2: Integer<u8, ::packed_bits::Bits3>,
}

To be able to use error_chain, I had to put the error_chain! code into a module:

mod errors {
    error_chain! {
        foreign_links {
            Toml(::toml::de::Error);
            Io(::io::Error);
            ParseInt(::std::num::ParseIntError);
            Image(::image::ImageError);
        }
    }
}

And the functions using this crate are like this one:

fn run() -> Result<()> {

I can provide some time if you need a minimal example code reproducing this issue or some help on this issue.

@rudib
Copy link
Member

rudib commented Feb 7, 2018

The problem was that importing error_chain's Result type overrides the typical std::result::Result type. I've fixed that by explicitly specifying the entire path. Check #16 for the test case and the fix.

I'll close this issue once 0.2.1 is released with this fix. In the meantime, you can point your project directly to the Git repository and check for any other issues.

@rudib
Copy link
Member

rudib commented Apr 19, 2018

Closing due to inactivity, and the reporting issue actually being an external project. 0.2.1 of this crate was released as well.

@rudib rudib closed this as completed Apr 19, 2018
@alexandre-janniaux
Copy link
Author

Sorry, didn't found the time to change our code and test, but I'll suggest minor changes as soon as I can also.

The issue with clippy seems to have been fixed too.

Thank you for your work.

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