Description
1. Description
No matter the value set in the option inline_attribute_width
(100, same as max_width
for me), rustfmt never inlines this:
#[macro_use]
extern crate static_assertions;
into this:
#[macro_use] extern crate static_assertions;
However, when I change the first code snippet into this:
#[cfg(abc)] extern crate static_assertions;
it suddenly works. According to the Rust docs, macro_use
is one of many built-in attributes, just like cfg
is an attribute. Therefore I came to conclusion, that rustfmt should inline the first case as well.
2. Attempt to a solution
I think this issue has something to do with the pull request #2412, which was created because rustfmt was in some cases incorrectly reordering items having the macro_use
attribute (see #2399 for example). The pull request fixed the reordering problem, but the price for it was that since then, rustfmt ignores the macro_use
attribute to the point that it does not inline it when it should.
I see the source code of rustfmt for the first time today and I am not yet much familiar with it, but I have figured out that if in the file src/reorder.rs:178
the contains_macro_use_attr
function gets changed to always return false
fn contains_macro_use_attr(item: &ast::Item) -> bool {
//attr::contains_name(&filter_inline_attrs(&item.attrs, item.span()), "macro_use")
false
}
and rustfmt gets recompiled, it suddenly starts to properly inline the macro_use
attribute.