Repository navigation
Fix applicability level for cfg suggestion - #163239
Merged
rust-bors[bot] merged 1 commit intoSep 25, 2026
Merged
rust-bors[bot] merged 1 commit into
rust-bors[bot] merged 1 commit into
Conversation
Collaborator
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
Contributor
|
@bors r+ |
Contributor
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 25, 2026
Rollup of 7 pull requests Successful merges: - #160068 (Preserve explicit register names in inline asm diagnostics) - #163239 (Fix applicability level for cfg suggestion) - #163025 (make `Complex` ABI GCC-compatible on sparc) - #163076 (powerpc64: don't pass unions in FPRs on ELFv1) - #163268 ([rustdoc] Correctly check that an item is not `doc(hidden)` with `--generate-link-to-definition`) - #163288 (Tweak Layout::from_size_align_unchecked safety comment) - #163292 (moving div_ceil() to associated items macro)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 25, 2026
Rollup merge of #163239 - chenyukang:yukang-fix-cfg-tail-expression-suggestion, r=estebank Fix applicability level for cfg suggestion Mark the semicolon, block-wrapping, and if cfg! suggestions for attribute-bearing expressions as `MaybeIncorrect`. For example: ```rust fn native_file_attributes(metadata: &std::fs::Metadata) -> u32 { #[cfg(unix)] std::os::unix::fs::MetadataExt::mode(metadata) #[cfg(windows)] std::os::windows::fs::MetadataExt::file_attributes(metadata) } fn main() -> std::io::Result<()> { let metadata = std::fs::metadata(std::env::current_exe()?)?; println!( "native file attributes: {:#x}", native_file_attributes(&metadata) ); Ok(()) } ``` Adding ; discards the return value on Unix. Replacing #[cfg] with if cfg! also fails because disabled branches still undergo name resolution and type checking. Wrapping the expression in a block works here, but still can fail when multiple cfg branches are enabled and the first block returns a non-unit value. For example: ```rust fn value() -> u8 { #[cfg(all())] 1 #[cfg(all())] 2 } ``` r? @estebank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mark the semicolon, block-wrapping, and if cfg! suggestions for attribute-bearing expressions as
MaybeIncorrect.For example:
Adding ; discards the return value on Unix.
Replacing #[cfg] with if cfg! also fails because disabled branches still undergo name resolution and type checking.
Wrapping the expression in a block works here, but still can fail when multiple cfg branches are enabled and the first block returns a non-unit value.
For example:
r? @estebank