`cfg_select!` in expression context interacts surprisingly with block expressions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I had code similar to the following:
return cfg_select! {
feature = "check_required" => Err(()),
_ => {
warn!("Did not check.");
Ok(())
}
};
I expected this to expand to a block expression, somewhat in line with the behavior one is used to from match or various select! macros for sockets and channels.
Instead, the second branch is expanded to the contents of the curly braces rather than a block expression, triggering semicolon_in_expressions_from_macros.
This feels especially unexpected since the usage without any curly braces is also permitted. One could therefore reasonably expect that the curly braces are parsed as a block expression rather than as part of the macro invocation.
Meta
rustc --version --verbose:
rustc 1.98.1 (48a229cea 2026-09-01)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.98.1
LLVM version: 22.1.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the cfg_select! example from the issue with the reported rustc version and inspect its macro expansion and diagnostic. Trace how the branch containing curly braces is interpreted, then establish the expected expansion and add or update coverage so the behavior is clearly validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100