Skip to content

cfg_select! + doc comment gives cryptic compiler error #155701

@rukai

Description

@rukai

I tried this code:

fn main() {
    cfg_select! {
        /// this doc comment causes a compiler error
        debug_assertions => println!("debug"),
        // this regular comment does not cause a compiler error
        _ => println!("not debug"),
    };
}

I expected to see this happen:

Successful compilation with a warning for unused doc comment.

Instead, this happened:

error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression
 --> src/main.rs:4:9
  |
4 |         debug_assertions => println!("debug"),
  |         ^^^^^^^^^^^^^^^^ expressions are not allowed here
  |
help: surround the identifier with quotation marks to make it into a string literal
  |
4 |         "debug_assertions" => println!("debug"),

Note that using doc comments on regular match arms works fine, but emits a warning.

fn main() {
    match 1 {
        /// doc comment
        1 => println!("fine"),
        // regular comment
        _ => println!("also fine"),
    }
}

Gives:

warning: unused doc comment
 --> src/main.rs:3:9
  |
3 |         /// doc comment
  |         ^^^^^^^^^^^^^^^
  |
  = help: use `//` for a plain comment
  = note: `#[warn(unused_doc_comments)]` (part of `#[warn(unused)]`) on by default

Meta

rustc --version --verbose:

rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: x86_64-unknown-linux-gnu
release: 1.95.0
LLVM version: 22.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.F-cfg_select`#![feature(cfg_select)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions