Skip to content

1.99 beta crater regression: panic when formatting bitflags #162124

Closed

Description

@cyrgani

log: https://crater-reports.s3.amazonaws.com/beta-1.99-5/1.99.0-beta.1/reg/extended-notify-0.1.3/log.txt
partial reduction:

use enumflags2::bitflags;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[bitflags]
#[repr(u64)]
pub(crate) enum Interest {
    Established,
    Any,
    Access,
    AccessOpen,
    AccessClose,
    AccessRead,
    AccessOther,
    Create,
    CreateFile,
    CreateFolder,
    CreateOther,
    Modify,
    ModifyData,
    ModifyDataSize,
    ModifyDataContent,
    ModifyDataOther,
    ModifyMetadata,
    ModifyMetadataAccessTime,
    ModifyMetadataWriteTime,
    ModifyMetadataPermissions,
    ModifyMetadataOwnership,
    ModifyMetadataExtended,
    ModifyMetadataOther,
    ModifyRename,
    ModifyRenameTo,
    ModifyRenameFrom,
    ModifyRenameBoth,
    ModifyRenameOther,
    ModifyOther,
    Delete,
    DeleteFile,
    DeleteFolder,
    DeleteOther,
    Other,
}

fn main() {
    let flags = Interest::Established | Interest::Create;
    eprintln!("run step {flags:?}");
}

Activity

  1. added
    C-bugCategory: This is a bug.
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Sep 1, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 1, 2026
  3. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 1, 2026
  4. cyrgani commented on Sep 1, 2026

    @cyrgani
    ContributorAuthor

    slightly smaller:

    use enumflags2::bitflags;
    
    #[derive(Debug, Clone, Copy)]
    #[bitflags]
    #[repr(u64)]
    pub(crate) enum Interest {
        // we need at least 10 variants to trigger the faulty enum derive(Debug) optimization
        V0,
        V1,
        V2,
        V3,
        V4,
        V5,
        V6,
        V7,
        V8,
        V9,
    }
    
    fn main() {
        let flags = Interest::V0 | Interest::V4;
        eprintln!("run step {flags:?}");
    }

    The problem is that #155452 added a new optimization to derive(Debug) for fieldless enums. But applying #[bitflags] rewrites the enum and gives it discriminants, making the generated Debug code incorrect.
    Essentially this is yet another instance of #148423.

  5. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    S-has-bisectionStatus: A bisection has been found for this issue
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Sep 1, 2026
  6. 13 remaining items

  7. nia-e commented on Sep 1, 2026

    @nia-e
    Member

    We discussed this in the libs meeting - we'd like to revert this and backport the revert, yeah. If there's a way to do this opt without breaking bitflags, we could try to re-land a version of this on nightly. Thanks for bringing this up!

  8. added
    P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang
    on Sep 2, 2026
  9. added 3 commits that reference this issue on Sep 2, 2026
    f91c12f
    0b70ed2
    fd9a115
  10. traviscross commented on Sep 2, 2026

    @traviscross
    Contributor

    We discussed this in the lang call today. We're happy with the revert here.

  11. added
    I-lang-radarItems that are on lang's radar and will need eventual work or consideration.
    and removed
    I-lang-nominatedNominated for discussion during a lang team meeting.
    P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang
    on Sep 2, 2026
  12. added a commit that references this issue on Sep 3, 2026
    862d030
  13. added a commit that references this issue on Sep 3, 2026
    82b1966
  14. added a commit that references this issue on Sep 3, 2026
    a056d7d
  15. added a commit that references this issue on Sep 3, 2026
    e667477
  16. panstromek commented on Sep 4, 2026

    @panstromek
    Contributor

    If there's a way to do this opt without breaking bitflags, we could try to re-land a version of this on nightly. Thanks for bringing this up!

    I think we could do a version with a match that maps variant to a variant index, instead of reading discriminant_value. This wouldn't avoid the match statement overhead, but it would avoid the MIR and binary size overhead from string constant in each arm (which I think was more significant part of the overhead motivating this optimization).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-fmtArea: `core::fmt`A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.P-highHigh priorityS-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamT-libsRelevant to the library 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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions