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

Rustfmt discards newlines between #[doc] attributes and other attributes #4604

Closed
jyn514 opened this issue Dec 19, 2020 · 1 comment
Closed

Comments

@jyn514
Copy link
Member

jyn514 commented Dec 19, 2020

Input

//! Some docs here
#![cfg_attr(bootstrap, doc = "xxx")]

#![cfg_attr(debug_assertions, stable(feature = "rust1", since = "1.0.0"))]

Output

//! Some docs here
#![cfg_attr(bootstrap, doc = "xxx")]
#![cfg_attr(debug_assertions, stable(feature = "rust1", since = "1.0.0"))]

Expected output

//! Some docs here
#![cfg_attr(bootstrap, doc = "xxx")]

#![cfg_attr(debug_assertions, stable(feature = "rust1", since = "1.0.0"))]

I see here why rustfmt did this - it thinks that all cfg_attr attributes should be grouped together. But this doesn't make sense in the semantic context of the program: cfg_attr(doc) is a doc-comment and should be grouped with other doc-comments. See rust-lang/rust#80181 (comment) for a more realistic example.

Is there a way to disable this behavior?

Meta

  • rustfmt version: rustfmt 1.4.24-stable (eb894d5 2020-11-05)
  • From where did you install rustfmt?: rustup
@calebcartwright
Copy link
Member

Going to close as a duplicate of #4082. The context here around doc comments is helpful as additional reference cases/motivation, but fundamentally relates to the same lack of support (default or opt-in) for newlines between attrs

Is there a way to disable this behavior?

Not categorically, but #[rustfmt::skip] and/or #[rustfmt::skip::attributes(cfg_attr)] could potentially be of use

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