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
    regression-from-stable-to-beta
    C-bug
    E-needs-bisection
    E-needs-mcve
    on Sep 1, 2026
  2. added
    needs-triage
    on Sep 1, 2026
  3. added
    A-fmt
    on Sep 1, 2026
  4. added
    I-prioritize
    on Sep 1, 2026
  5. 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.

  6. added
    S-has-mcve
    S-has-bisection
    A-macros
    A-proc-macros
    T-compiler
    and removed
    E-needs-bisection
    E-needs-mcve
    on Sep 1, 2026
  7. 13 remaining items

  8. 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!

  9. added
    P-lang-drag-1
    on Sep 2, 2026
  10. added 3 commits that reference this issue on Sep 2, 2026
    f91c12f
    0b70ed2
    fd9a115
  11. traviscross commented on Sep 2, 2026

    @traviscross
    Contributor

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

  12. added
    I-lang-radar
    and removed
    I-lang-nominated
    P-lang-drag-1
    on Sep 2, 2026
  13. added a commit that references this issue on Sep 3, 2026
    862d030
  14. added a commit that references this issue on Sep 3, 2026
    82b1966
  15. added a commit that references this issue on Sep 3, 2026
    a056d7d
  16. added a commit that references this issue on Sep 3, 2026
    e667477
  17. 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-fmtA-macrosA-proc-macrosC-bugI-lang-radarP-highS-has-bisectionS-has-mcveT-compilerT-langT-libsregression-from-stable-to-beta

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions