Skip to content

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

Closed
@jyn514

Description

@jyn514

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions