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

error: cannot find derive macro BitfieldStruct in this scope #183

Closed
ctaggart opened this issue Oct 24, 2019 · 12 comments
Closed

error: cannot find derive macro BitfieldStruct in this scope #183

ctaggart opened this issue Oct 24, 2019 · 12 comments
Labels
bug Something isn't working

Comments

@ctaggart
Copy link

I tried to manually fix it for about a half hour and wasn't able to, so I don't think it is trivial. (from ctaggart/openconnect-rust#5)

Camerons-MacBook-Pro:openconnect-rust cameron$ cargo build
   Compiling openconnect-rust v0.0.0 (/Users/cameron/github/openconnect-rust)
error: cannot find derive macro `BitfieldStruct` in this scope
    --> src/tun.rs:1198:29
     |
1198 |     #[derive ( Copy, Clone, BitfieldStruct )]
     |                             ^^^^^^^^^^^^^^

error: cannot find derive macro `BitfieldStruct` in this scope
    --> src/gpst.rs:1086:29
     |
1086 |     #[derive ( Copy, Clone, BitfieldStruct )]
     |                             ^^^^^^^^^^^^^^

It is complaining about:

https://github.com/ctaggart/openconnect-rust/blob/28ff0a3ca51386d841638c7fff9fe6a862e7465d/src/tun.rs#L1198-L1215

    #[derive ( Copy, Clone, BitfieldStruct )]
    #[repr(C)]
    #[src_loc = "81:1"]
    pub struct ip {
        #[bitfield(name = "ip_hl", ty = "u_int", bits = "0..=3")]
        #[bitfield(name = "ip_v", ty = "u_int", bits = "4..=7")]
        pub ip_hl_ip_v: [u8; 1],
        pub ip_tos: u_char,
        pub ip_len: u_short,
        pub ip_id: u_short,
        pub ip_off: u_short,
        pub ip_ttl: u_char,
        pub ip_p: u_char,
        pub ip_sum: u_short,
        pub ip_src: in_addr,
        pub ip_dst: in_addr,
        /* source and dest address */
    }
@TheDan64
Copy link
Contributor

I think your use c2rust_bitfields::BitfieldStruct; import needs to be moved into the mod block containing the struct. Rust modules don't inherit imports from parents.

@ctaggart
Copy link
Author

ctaggart commented Oct 25, 2019

Yes, I tried that yesterday. I tried that again and noticed it is actually a different error:

error: cannot determine resolution for the derive macro `BitfieldStruct`
    --> src/tun.rs:1199:29
     |
1199 |     #[derive ( Copy, Clone, BitfieldStruct )]
     |                             ^^^^^^^^^^^^^^
     |
     = note: import resolution is stuck, try simplifying macro imports

error: cannot find derive macro `BitfieldStruct` in this scope
    --> src/gpst.rs:1086:29
     |
1086 |     #[derive ( Copy, Clone, BitfieldStruct )]
     |                  

@TheDan64
Copy link
Contributor

TheDan64 commented Oct 25, 2019

I did manage to figure out a way to get it to work, using the old macro import approach:

In your lib.rs, after your feature attrs but before your mod decls, add:

#[macro_use]
extern crate c2rust_bitfields;

This will make the derive macro a globally visible type, so you can use it in the rest of the crate without any use imports.

That said, this shouldn't be necessary - so I'm inclined to think that this is a rust macro resolution bug in the 2018e macro imports.

@rinon
Copy link
Contributor

rinon commented Oct 25, 2019

This was my mistake, I removed the extern crate for all things we use. We'll need to put that back in for proc-macro crates, unfortunately.

@rinon
Copy link
Contributor

rinon commented Oct 25, 2019

The import should work, but you'll need to import it again in the ip_h module in the file you linked to. This should be automatic, we need to fix the translator to do that.

@rinon rinon added the bug Something isn't working label Oct 25, 2019
@TheDan64
Copy link
Contributor

@ctaggart Any luck with my workaround?

@TheDan64
Copy link
Contributor

I've opened up a rustc issue here: rust-lang/rust#65935

@ctaggart
Copy link
Author

Thanks for opening the rustc issue. I haven't tried it. I was working on work and waiting for #184 as well. There are two solutions proposed in this issue. I can try them both this week.

@TheDan64 TheDan64 added the blocked Cannot be supported without external support first label Oct 29, 2019
@rinon
Copy link
Contributor

rinon commented Oct 29, 2019

Since rustc is deprecating custom attributes and WONTFIX the issue above, we should revert back to using extern crate.

@TheDan64
Copy link
Contributor

Do we need to revert back though? If custom attrs are going away, then this bug shouldn't appear? By that, I mean that the issue is due to the attr, which is going away/to be replaced by another approach

@TheDan64
Copy link
Contributor

I guess we should do that if we want a more immediate fix, though

@rinon
Copy link
Contributor

rinon commented Oct 29, 2019

It's going to take a lot longer to work around the attributes thing. For now we'll keep using the custom attribute and just need to fix the imports.

@rinon rinon removed the blocked Cannot be supported without external support first label Oct 29, 2019
@rinon rinon closed this as completed in 6f69c51 Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants