Skip to content

refactor: declare each const in the narrowest scope that holds its uses - #393

Merged
not-elm merged 2 commits into
mainfrom
refactor-consts
Oct 1, 2026
Merged

not-elm merged 2 commits into
mainfrom
refactor-consts

Conversation

@not-elm

@not-elm not-elm commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Problem

.claude/rules/rust.md requires each const to live in the narrowest scope that holds its uses, but many constants under src/ and crates/ were still module-level: some named by a single function, others stating a property of one type.

Solution

Apply the rule across src/ and crates/, with no change in behavior.

  • Function-local (51): a const that exactly one function names moves to the top of that function's body. Constants that had no doc get a one-line ///.
  • Associated (16): a const that states a property of one type moves onto it.
Before After
FACTORS / BASE FontZoom::FACTORS / FontZoom::BASE
WEBVIEW_TICK UpdatePolicy::WEBVIEW_TICK
INITIAL_POOL_CAP ImeGlyphPool::INITIAL_CAP
MAX_ASSET_LEN StaticAsset::MAX_LEN
DEFAULT_THICKNESS CursorConfig::DEFAULT_THICKNESS
DEFAULT_FOREGROUND / DEFAULT_BACKGROUND Palette::DEFAULT_FOREGROUND / Palette::DEFAULT_BACKGROUND
MAX_TITLE_DEPTH TitleState::MAX_STACK_DEPTH
MAX_APC_LEN WebviewApcRequest::MAX_LEN
MAX_INTERMEDIATES CsiParams::MAX_INTERMEDIATES
MAX_SUBPARAMS Group::MAX_SUBPARAMS
MAX_INLINE_HTML ValidatedRegistration::MAX_INLINE_HTML
placement::MAX_ROWS / MAX_COLS PlacementSize::MAX_ROWS / PlacementSize::MAX_COLS
grid::MIN_COLUMNS GridSize::MIN_COLS

The last two rows change orzma_vt::prelude: MAX_ROWS, MAX_COLS and MIN_COLUMNS are no longer exported, and MIN_COLUMNS is renamed to match GridSize::MAX_COLS.

Doc comments that named a constant which is now function-local describe the behavior instead.

Associated consts are declared above the methods of their impl, whatever their visibility. .claude/rules/rust.md now states this, and the consts that sat below a method (Binding::LEADER_TOKEN / REPEAT_TOKEN, PointerButton::ALL, QueueSampler::BACKLOG_FLOOR) move up as well.

Left at module level:

  • orzma_tty's MAX_CURSOR_KEYS: the type it bounds is pub(crate), and the public WheelConfig doc links to it.

  • Constants shared by more than one type (MAX_PLACEMENTS, MAX_COMBINING), and constants named by one function plus a test or another item's intra-doc link.

  • src/window_icon.rs is Windows-only and was not compiled locally; CI covers it.

🤖 Generated with Claude Code

Apply the const-scope rule in .claude/rules/rust.md across src/ and
crates/. A const that one function names moves into that function, and a
const that states a property of one type becomes an associated const.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@not-elm not-elm added the skip-changelog Exclude this PR from the release notes label Oct 1, 2026
Move every associated const that sat below a method to the top of its
impl block, whatever its visibility, and state the ordering in
.claude/rules/rust.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@not-elm
not-elm merged commit b508df0 into main Oct 1, 2026
10 checks passed
@not-elm
not-elm deleted the refactor-consts branch October 1, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Exclude this PR from the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant