Skip to content

may_name_constant misses constants declared by item macros, so a macro-made constant pattern can read exposed #7863

Closed

Description

@EffortlessSteven

Repro

macro_rules! def_const { ($n:ident) => { const $n: i64 = 0; }; }
def_const!(p);

pub fn tier(points: i64) -> Tier {
    match points {
        p if 100 < p => Tier::Gold,   // edited from `p if 100 <= p`
        p if p >= 50 => Tier::Silver,
        _ => Tier::Bronze,
    }
}
// tests: tier(99), tier(100), tier(101), tier(400) with exact asserts

Observed: the guard's predicate finding reads exposed. That is false: p is the constant 0, the arm only matches points == 0, and no test separates the two guards.

Cause

may_name_constant (crates/ripr/src/analysis/classify/arm_selection.rs) recognizes const/static written before the name, and use imports. Item names from macro_rules! are not hygienic, so def_const!(p) declares a constant p that this check cannot see. The same applies to a crate macro defined in another file. Both consumers are affected: arm-selection binding demotion (demote_constant_bindings) and, since #7811, the guard-binding alias in activation.rs.

Goal it hurts

Trustworthy verdicts: a false exposed is the worst outcome.

Suggested fix

Fail closed when the owner file has any item-level macro call, matching how declared_enum_variants treats item macros. Then add this repro as a control for both consumers.

Found by adversarial review of #7811 (non-blocking there: the code is unusual).


Generated by Claude Code

Activity

  1. added 2 commits that reference this issue on Oct 14, 2026
  2. EffortlessSteven commented on Oct 17, 2026

    @EffortlessSteven
    MemberAuthor

    Claiming: fixing in a draft PR (branch claude/issue-7863).


    Generated by Claude Code

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions