Skip to content

Missed optimization for match #146718

@bwmf2

Description

@bwmf2

I tried this code:

Code

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum GeneralCategory { Lu, Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Pc, Pd, Ps, Pe, Pi, Pf, Po, Sm, Sc, Sk, So, Zs, Zl, Zp, Cc, Cf, Cs, Co, Cn, } #[unsafe(no_mangle)] pub const fn is_ascii_alphabetic1(c: char) -> bool { use GeneralCategory::*; c >= '\u{0000}' && c <= '\u{007f}' && match match c { '\u{0000}'..='\u{001F}' => Cc, '\u{0020}' => Zs, '\u{0021}'..='\u{0023}' => Po, '\u{0024}' => Sc, '\u{0025}'..='\u{0027}' => Po, '\u{0028}' => Ps, '\u{0029}' => Pe, '\u{002A}' => Po, '\u{002B}' => Sm, '\u{002C}' => Po, '\u{002D}' => Pd, '\u{002E}'..='\u{002F}' => Po, '\u{0030}'..='\u{0039}' => Nd, '\u{003A}'..='\u{003B}' => Po, '\u{003C}'..='\u{003E}' => Sm, '\u{003F}'..='\u{0040}' => Po, '\u{0041}'..='\u{005A}' => Lu, '\u{005B}' => Ps, '\u{005C}' => Po, '\u{005D}' => Pe, '\u{005E}' => Sk, '\u{005F}' => Pc, '\u{0060}' => Sk, '\u{0061}'..='\u{007A}' => Ll, '\u{007B}' => Ps, '\u{007C}' => Sm, '\u{007D}' => Pe, '\u{007E}' => Sm, '\u{007F}' => Cc, _ => return false, } { Lu | Ll | Lt | Lm | Lo => true, _ => false, } } #[unsafe(no_mangle)] pub const fn is_ascii_alphabetic2(c: char) -> bool { use GeneralCategory::*; c >= '\u{0000}' && c <= '\u{007f}' && match match c { '\u{0041}'..='\u{005A}' => Lu, '\u{0061}'..='\u{007A}' => Ll, _ => return false, } { Lu | Ll | Lt | Lm | Lo => true, _ => false, } }

I expected to see this happen: The code for is_ascii_alphabetic1 to be identical to the code of is_ascii_alphabetic2

Instead, this happened: The function is_ascii_alphabetic1 has a lot of code compared to the function is_ascii_alphabetic2.

Meta

rustc --version --verbose:

rustc 1.91.0-nightly (7d82b83ed 2025-08-06) binary: rustc commit-hash: 7d82b83ed57d188ab3f2441a765a6419685a88a3 commit-date: 2025-08-06 host: x86_64-unknown-linux-gnu release: 1.91.0-nightly LLVM version: 21.1.0 

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions