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

can't compile bindings after rustfmt #2003

Closed
ctaggart opened this issue Sep 28, 2017 · 5 comments
Closed

can't compile bindings after rustfmt #2003

ctaggart opened this issue Sep 28, 2017 · 5 comments

Comments

@ctaggart
Copy link
Contributor

A file that compiles is no longer able to be compiled after running rustfmt on it.

For more details, see rust-lang/rust-bindgen#1045 & ctaggart/octh#27.

Here is the file that does compile:

/* automatically generated by rust-bindgen */

extern crate core;

# [ allow ( non_snake_case , non_camel_case_types , non_upper_case_globals ) ] pub mod root { # [ allow ( unused_imports ) ] use self :: super :: root ; # [ repr ( C ) ] # [ derive ( Debug , Copy , Clone ) ] pub struct c { pub _address : u8 , } # [ repr ( C ) ] # [ derive ( Copy ) ] pub struct e { pub __bindgen_anon_1 : root :: e__bindgen_ty_1 , } # [ repr ( C ) ] # [ derive ( Copy ) ] pub union e__bindgen_ty_1 { pub d : [ :: std :: os :: raw :: c_char ; 4usize ] , _bindgen_union_align : [ u8 ; 4usize ] , } # [ test ] fn bindgen_test_layout_e__bindgen_ty_1 ( ) { assert_eq ! ( :: core :: mem :: size_of :: < e__bindgen_ty_1 > ( ) , 4usize , concat ! ( "Size of: " , stringify ! ( e__bindgen_ty_1 ) ) ) ; assert_eq ! ( :: core :: mem :: align_of :: < e__bindgen_ty_1 > ( ) , 1usize , concat ! ( "Alignment of " , stringify ! ( e__bindgen_ty_1 ) ) ) ; assert_eq ! ( unsafe { & ( * ( 0 as * const e__bindgen_ty_1 ) ) . d as * const _ as usize } , 0usize , concat ! ( "Alignment of field: " , stringify ! ( e__bindgen_ty_1 ) , "::" , stringify ! ( d ) ) ) ; } impl Clone for e__bindgen_ty_1 { fn clone ( & self ) -> Self { * self } } # [ test ] fn bindgen_test_layout_e ( ) { assert_eq ! ( :: core :: mem :: size_of :: < e > ( ) , 4usize , concat ! ( "Size of: " , stringify ! ( e ) ) ) ; assert_eq ! ( :: core :: mem :: align_of :: < e > ( ) , 1usize , concat ! ( "Alignment of " , stringify ! ( e ) ) ) ; } impl Clone for e { fn clone ( & self ) -> Self { * self } } # [ repr ( C ) ] # [ derive ( Copy , Clone ) ] pub struct B { pub f : root :: e , } # [ repr ( C ) ] # [ derive ( Copy , Clone ) ] pub struct g { pub h : root :: B , } # [ repr ( C ) ] # [ derive ( Copy , Clone ) ] pub struct a { pub _base : root :: g , } # [ repr ( C ) ] # [ derive ( Debug , Copy , Clone ) ] pub struct i { pub _address : u8 , } # [ repr ( C ) ] # [ derive ( Copy ) ] pub struct octave_fields { pub __bindgen_anon_1 : root :: octave_fields__bindgen_ty_1 , } # [ repr ( C ) ] # [ derive ( Copy ) ] pub struct octave_fields__bindgen_ty_1 { pub _address : u8 , } # [ test ] fn bindgen_test_layout_octave_fields__bindgen_ty_1 ( ) { assert_eq ! ( :: core :: mem :: size_of :: < octave_fields__bindgen_ty_1 > ( ) , 1usize , concat ! ( "Size of: " , stringify ! ( octave_fields__bindgen_ty_1 ) ) ) ; assert_eq ! ( :: core :: mem :: align_of :: < octave_fields__bindgen_ty_1 > ( ) , 1usize , concat ! ( "Alignment of " , stringify ! ( octave_fields__bindgen_ty_1 ) ) ) ; } impl Clone for octave_fields__bindgen_ty_1 { fn clone ( & self ) -> Self { * self } } # [ test ] fn bindgen_test_layout_octave_fields ( ) { assert_eq ! ( :: core :: mem :: size_of :: < octave_fields > ( ) , 1usize , concat ! ( "Size of: " , stringify ! ( octave_fields ) ) ) ; assert_eq ! ( :: core :: mem :: align_of :: < octave_fields > ( ) , 1usize , concat ! ( "Alignment of " , stringify ! ( octave_fields ) ) ) ; } impl Clone for octave_fields { fn clone ( & self ) -> Self { * self } } # [ test ] fn __bindgen_test_layout_i_open0_c_open1_char_a_open2_char_close2_close1_close0_instantiation ( ) { assert_eq ! ( :: core :: mem :: size_of :: < root :: i > ( ) , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( root :: i ) ) ) ; assert_eq ! ( :: core :: mem :: align_of :: < root :: i > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: i ) ) ) ; } }

Run rustfmt on it returns an exit code of 3:

$ rustfmt __bindgen.rs
Rustfmt failed at /home/cameron/octh/__bindgen.rs:132: line exceeded maximum length (maximum: 100, found: 109) (sorry)

$ echo $?
3

And now it no longer compiles:

$ rustc --crate-type=lib __bindgen.rs
error: incorrect close delimiter: `]`
  --> __bindgen.rs:20:29
   |
20 |     #[derive(Copy)]; 4usize ] , }    #[test]
   |                             ^
   |
note: unclosed delimiter
  --> __bindgen.rs:6:14
   |
6  | pub mod root {
   |              ^

error: unexpected close delimiter: `}`
  --> __bindgen.rs:20:33
   |
20 |     #[derive(Copy)]; 4usize ] , }    #[test]
   | 
/* automatically generated by rust-bindgen */

extern crate core;

#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
    #[allow(unused_imports)]
    use self::super::root;
    #[repr(C)]
    #[derive(Debug, Copy, Clone)]
    pub struct c {
        pub _address: u8,
    }
    #[repr(C)]
    #[derive(Copy)]
    pub struct e {
        pub __bindgen_anon_1: root::e__bindgen_ty_1,
    }
    #[repr(C)]
    #[derive(Copy)]; 4usize ] , }    #[test]
    fn bindgen_test_layout_e__bindgen_ty_1() {
        assert_eq!(
            ::core::mem::size_of::<e__bindgen_ty_1>(),
            4usize,
            concat!("Size of: ", stringify!(e__bindgen_ty_1))
        );
        assert_eq!(
            ::core::mem::align_of::<e__bindgen_ty_1>(),
            1usize,
            concat!("Alignment of ", stringify!(e__bindgen_ty_1))
        );
        assert_eq!(
            unsafe { &(*(0 as *const e__bindgen_ty_1)).d as *const _ as usize },
            0usize,
            concat!(
                "Alignment of field: ",
                stringify!(e__bindgen_ty_1),
                "::",
                stringify!(d)
            )
        );
    }
    impl Clone for e__bindgen_ty_1 {
        fn clone(&self) -> Self {
            *self
        }
    }
    #[test]
    fn bindgen_test_layout_e() {
        assert_eq!(
            ::core::mem::size_of::<e>(),
            4usize,
            concat!("Size of: ", stringify!(e))
        );
        assert_eq!(
            ::core::mem::align_of::<e>(),
            1usize,
            concat!("Alignment of ", stringify!(e))
        );
    }
    impl Clone for e {
        fn clone(&self) -> Self {
            *self
        }
    }
    #[repr(C)]
    #[derive(Copy, Clone)]
    pub struct B {
        pub f: root::e,
    }
    #[repr(C)]
    #[derive(Copy, Clone)]
    pub struct g {
        pub h: root::B,
    }
    #[repr(C)]
    #[derive(Copy, Clone)]
    pub struct a {
        pub _base: root::g,
    }
    #[repr(C)]
    #[derive(Debug, Copy, Clone)]
    pub struct i {
        pub _address: u8,
    }
    #[repr(C)]
    #[derive(Copy)]
    pub struct octave_fields {
        pub __bindgen_anon_1: root::octave_fields__bindgen_ty_1,
    }
    #[repr(C)]
    #[derive(Copy)]
    pub struct octave_fields__bindgen_ty_1 {
        pub _address: u8,
    }
    #[test]
    fn bindgen_test_layout_octave_fields__bindgen_ty_1() {
        assert_eq!(
            ::core::mem::size_of::<octave_fields__bindgen_ty_1>(),
            1usize,
            concat!("Size of: ", stringify!(octave_fields__bindgen_ty_1))
        );
        assert_eq!(
            ::core::mem::align_of::<octave_fields__bindgen_ty_1>(),
            1usize,
            concat!("Alignment of ", stringify!(octave_fields__bindgen_ty_1))
        );
    }
    impl Clone for octave_fields__bindgen_ty_1 {
        fn clone(&self) -> Self {
            *self
        }
    }
    #[test]
    fn bindgen_test_layout_octave_fields() {
        assert_eq!(
            ::core::mem::size_of::<octave_fields>(),
            1usize,
            concat!("Size of: ", stringify!(octave_fields))
        );
        assert_eq!(
            ::core::mem::align_of::<octave_fields>(),
            1usize,
            concat!("Alignment of ", stringify!(octave_fields))
        );
    }
    impl Clone for octave_fields {
        fn clone(&self) -> Self {
            *self
        }
    }
    #[test]fn __bindgen_test_layout_i_open0_c_open1_char_a_open2_char_close2_close1_close0_instantiation ( ){
        assert_eq!(
            ::core::mem::size_of::<root::i>(),
            1usize,
            concat!("Size of template specialization: ", stringify!(root::i))
        );
        assert_eq!(
            ::core::mem::align_of::<root::i>(),
            1usize,
            concat!(
                "Alignment of template specialization: ",
                stringify!(root::i)
            )
        );
    }
}
@topecongiro
Copy link
Contributor

Could you please try with the latest rustfmt-nightly? I hope that it works...

@ctaggart
Copy link
Contributor Author

ctaggart commented Sep 28, 2017

@topecongiro, can I do that from cargo?

I just installed doing this, but it still errors. Did it work for you?

$ cargo install rustfmt --force
$ cargo install --list
rustfmt v0.9.0:
	cargo-fmt
	rustfmt

@ctaggart
Copy link
Contributor Author

ctaggart commented Sep 28, 2017

Sorry, I'll test with rustfmt-nightly. Didn't realize what you were asking until I read through the readme just now.

@ctaggart
Copy link
Contributor Author

rustfmt-nightly works. It creates a file that compiles. How can I increase the maximum width allowed?

$ export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
$ rustfmt __bindgen.rs
error: line exceeded maximum width (maximum: 100, found: 101)
   --> /home/cameron/octh/__bindgen.rs:138
    |
138 |     fn __bindgen_test_layout_i_open0_c_open1_char_a_open2_char_close2_close1_close0_instantiation() {
    |                                                                                                     ^

warning: rustfmt may have failed to format. See previous 1 errors.

$ echo $?
3
$ rustc --crate-type=lib __bindgen.rs
$ echo $?
0
$ cargo install --list
rustfmt-nightly v0.2.7 (file:///home/cameron/rustfmt):
    cargo-fmt
    rustfmt
    rustfmt-format-diff

@topecongiro
Copy link
Contributor

Thank you!

You could add max_width = 110 (or any value larger than 100) to your rustfmt.toml to increase the max width.
FWIW the issue should be fixed via #2005.

@nrc nrc closed this as completed Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants