Skip to content

try bikeshed $ty { … } is not pre-expansion gated (affects beta+nightly) #152501

Closed

Description

@fmease

The following code compiles even though it shouldn't:

fn main() {
    #[cfg(false)]
    try bikeshed () {}
}  

Contrary to try { … } it does not even issue a pre-expansion gate warning. For context, try blocks and some other ancient features are notoriously post-expansion gated which we can't change without breaking a large amount of crates in the ecosystem (which use the #[cfg(feature = "nightly")] pattern). For new syntactic forms however we require a pre-expansion feature gate nowadays for forward compatibility reasons. try bikeshed $ty { … } is a new syntactic form and thus should be pre-expansion gated by try_blocks try_block_heterogeneous.

Activity

  1. added
    A-parserArea: The lexing & parsing of Rust source code to an AST
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Feb 11, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 11, 2026
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 11, 2026
  4. scottmcm commented on Feb 11, 2026

    @scottmcm
    Member

    Oops, absolutely agreed. My bad for copying try.

    Can you point me at instructions for the right way to do this? (Or if someone who knows what they're doing wants to just fix it that would be good too.)

  5. fmease commented on Feb 12, 2026

    @fmease
    Author
  6. fmease commented on Feb 12, 2026

    @fmease
    MemberAuthor

    Feel free to r? me

  7. fmease commented on Feb 12, 2026

    @fmease
    MemberAuthor
    Resolved

    Ah, now I see that it's to be gated separately anyway, namely behind try_blocks_heterogeneous. That makes it even simpler.

    Oops, absolutely agreed. My bad for copying try.

    No worries!

    Can you point me at instructions for the right way to do this? (Or if someone who knows what they're doing wants to just fix it that would be good too.)

    In compiler/rustc_ast_passes/src/feature_gate.rs you add a gate_all!(try_block_heterogeneous, "… … …"); where all the other gate_all!(…)s are. Then, you remove the branch you've added to the PostExpansionVisitor in PR #149489.

  8. added this to the 1.94.0 milestone on Feb 12, 2026
  9. self-assigned this
    on Feb 12, 2026
  10. added 2 commits that reference this issue on Feb 13, 2026
    a0c9e99
    4269210
  11. added a commit that references this issue on Feb 13, 2026
    86f7eb8
  12. zhanglin2603 commented on Feb 17, 2026

    @zhanglin2603
  13. fmease commented on Feb 17, 2026

    @fmease
    MemberAuthor

    #152501 (comment)

    @rust-lang/mods

  14. added a commit that references this issue on Mar 9, 2026
  15. added 2 commits that reference this issue on Mar 9, 2026
  16. added a commit that references this issue on Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions