Open taiki-e opened 1 week ago
I would also expect the #[allow]
to work here.
However, I don't think you need the cfg_attr
anymore, it can be removed safely.
- #![cfg_attr(rustfmt, rustfmt::skip)]
+ #![rustfmt::skip]
it can be removed safely.
No. Custom inner attributes are unstable.
error[E0658]: custom inner attributes are unstable
--> src/lib.rs:1:4
|
1 | #![rustfmt::skip]
| ^^^^^^^^^^^^^
|
= note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable
= note: this compiler was built on 2024-05-04; consider upgrading it if it is out of date
Oh, good point, but they can (stably) be applied directly to the mod
, like this:
#[rustfmt::skip]
mod a;
Another thing that isn't right here is that the rustfmt
cfg is not a well known cfg.
I have never been able to find where that cfg might be set by rustfmt
so I (wrongly) assumed it was anymore, looks this I was wrong.
@rustbot label -needs-triage +F-check-cfg @rustbot claim
they can (stably) be applied directly to the
mod
, like this:#[rustfmt::skip] mod a;
Unfortunately, that is not an option available to me due to a rust-analyzer bug: https://github.com/rust-lang/rust-analyzer/issues/10826#issuecomment-1647890621
I have never been able to find where that cfg might be set by
rustfmt
so I (wrongly) assumed it was anymore, looks this I was wrong.
It looks like rustfmt will just always treat cfg_attr(anything, rustfmt::skip)
as rustfmt::skip
, regardless of the actual cfg condition, so this will also work: (playgound)
mod m {
#![cfg_attr(any(), rustfmt::skip)]
fn dont_format_me () { }
}
It looks like rustfmt will just always treat cfg_attr(anything, rustfmt::skip) as rustfmt::skip, regardless of the actual cfg condition
Oh, no! >.<
The rustfmt
cfg is now (as of nighlty-2024-05-07) recognized has a well known cfg.
Fixing one of the issue reported by this issue.
cc #82450
I tried this code:
I expected to see this happen: no warning
Instead, this happened:
#![allow(unexpected_cfgs)]
is ignored:Even if adding
#[allow(unexpected_cfgs)]
tomod a;
, the result is the same.cc @Urgau
Meta
rustc --version --verbose
: