#[rustfmt::skip] issue

There are situations where it is important to me that the "Format Document" command in VSCode skips certain code areas. I can also do this with the command: #[rustfmt::skip]
But when I use it before the match command I always get this ugly warning.

Can this be deactivated?


That's not a warning, that's an error. You can turn off errors in your editor but the file still won't compile.

I don't have a solution for this.

Well… the following seems to work as a hack :sweat_smile:

enum Obst {

fn main() {
    use Obst::*;

    #[cfg_attr(any(), rustfmt::skip)]
    match Apfel {
        Apfel | Birne => println!("'n Apfel oder so"),
        Pflaume       => println!("was kleines Buntes"),

Is looks like rustfmt doesn’t evaluate cft_attr logic, but unconditionally skip the expression marked this way, whereas cfg_attr with any() (evaluating to false) evaluates to no attribute at all before the compiler has a change to error about the custom attribute on an expression. (Whereas attributes in general are allowed on statement expressions like blocks or this match, so the cfg_attr itself creates no issue.)

Subtle stuff… no idea by the way if this “hack” will keep working indefinitely.


Vielen Dank du coole Socke!! :slight_smile:

I wonder if there is some parsing ambiguity between ExpressionWithBlock and ExpressionStatement when attributes are attached. Adding an explicit semicolon to the end of the match statement makes the error go away: Rust Playground

The reference specifically says outer attributes can be applied to expression statements and the playground link above seems to agree with that: Expressions - The Rust Reference


That’s a neat workaround. I’d call that cleaner and more future-proof compared to the approach I could come up with.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.