Skip to content

Invalid formating for conditional compilation rule #1668

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
r8d8 opened this issue Jun 13, 2017 · 4 comments
Closed

Invalid formating for conditional compilation rule #1668

r8d8 opened this issue Jun 13, 2017 · 4 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@r8d8
Copy link

r8d8 commented Jun 13, 2017

Formatter v0.8.6 prodices invalid outup for multiargument conditional compilation rule
Resulting code doesn't compile

Expected:

/// Default path (*nix) #[cfg(all(unix, not(target_os = "macos") , not(target_os = "ios"), not(target_os = "android")))]

Received:

/// Default path (*nix) #[cfg(all(unix, not(target_os = "macos") ), not(target_os = "ios") ), not(target_os = "android")))]

@Lakier15
Copy link

I have got similar problems. Rustfmt is doing something weird with #[cfg()] and #[cfg_attr()].

Example with #[cfg()]:

#[cfg(target_os = "freertos")] 
match port_id { 
    'a' | 'A' => GpioPort { port_address: GPIO_A }, 
    'b' | 'B' => GpioPort { port_address: GPIO_B }, 
    _ => panic!(),
}

becomes

#[cfg(target_os = "freertos")]    #[cfg(target_os = "freertos")] 
    #[cfg(target_os = "freertos")] match port_id { 
         'a' | 'A' => GpioPort { port_address: GPIO_A }, 
         'b' | 'B' => GpioPort { port_address: GPIO_B }, 
         _ => panic!(),
    }

Example with #[cfg_attr()]:

#[cfg_attr(not(target_os = "freertos"), allow(unused_variables))]

becomes

#[cfg_attr(not(target_os = "freertos") /* ) /* ) */, allow(unused_variables))]

@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Jun 13, 2017
@topecongiro
Copy link
Contributor

topecongiro commented Jun 13, 2017

Thanks for raising this issue. Looks like the span from ast::MetaItem and ast::NestedMetaItem does not contain the closing paren and rustfmt inserts it for recovery.

@mjfeller
Copy link

Similar problems from me as well.

#[cfg(all(not(test), target_os = "macos"))]

becomes

#[cfg(all(not(test) ), target_os = "macos"))]

@topecongiro
Copy link
Contributor

@mjfeller Thanks, this is fixed via #1669.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

4 participants