Skip to content

fix(macro): make invalid #[Overwritten(...)] attributes a compile error - #967

Open
techmech-keeb wants to merge 3 commits into
rmk-rs:mainfrom
techmech-keeb:fix/overwritten-silent-fallback
Open

fix(macro): make invalid #[Overwritten(...)] attributes a compile error#967
techmech-keeb wants to merge 3 commits into
rmk-rs:mainfrom
techmech-keeb:fix/overwritten-silent-fallback

Conversation

@techmech-keeb

Copy link
Copy Markdown

Fixes #966

Description

An #[Overwritten(...)] attribute that failed to parse — an unknown or miscased variant like #[Overwritten(Entry)] instead of entry — was silently skipped: the if let Ok(...) matchers discarded darling's error and fell back to the generated default, and the function itself was dropped from the expansion, so neither the macro nor rustc reported anything. The matchers also required attrs.len() == 1, so any extra attribute (doc comments included) silently disabled a correctly spelled override.

  • Validate all Overwritten attributes up front in parse_keyboard_mod / parse_split_peripheral_mod; parse failures now surface darling's own diagnostic (Unknown field: `Entry`. Did you mean `entry`?) as a compile error via write_errors() — the idiom lib.rs already uses for other attribute parsing.
  • Replace the per-site attrs.len() == 1 + from_meta matching with a shared find_overwritten() helper that finds the attribute by path, so an extra attribute (doc comments included) no longer disables a correctly spelled override.
  • Functions without an Overwritten attribute, and valid single-attribute overrides, expand exactly as before. CHANGELOG entry added.

Testing

  • cargo test in rmk-macro: unit tests (incl. 6 new covering the typo, extra-attribute/doc-comment, valid, and no-attribute cases), trybuild compile_fail, and macrotest expand — all passing (with cargo expand installed).
  • cargo nextest run --no-default-features --features=split,vial,storage,async_matrix,_ble in rmk: 548/548 passed on current main (rmk consumes the path rmk-macro, so this compiles with the change).
  • scripts/format_all.sh clean (nightly rustfmt).
  • Macro-expansion-time change only; no hardware behavior change expected for valid configurations. Not tested on hardware.

@techmech-keeb
techmech-keeb force-pushed the fix/overwritten-silent-fallback branch from 7ec93fe to b139126 Compare July 17, 2026 05:19
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 397.5 KiB 397.5 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52840_ble 438.1 KiB 438.1 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52840_ble_split (central) 500.9 KiB 500.9 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52840_ble_split (peripheral) 320.6 KiB 320.6 KiB +0.00% 0 0 0
use_config/pi_pico_w_ble 671.1 KiB 671.1 KiB +0.00% ⬆️ +4 0 0
use_config/rp2040 145.8 KiB 145.8 KiB +0.00% 0 0 0
use_config/rp2040_split (central) 159.4 KiB 159.4 KiB +0.00% ⬆️ +8 0 0
use_config/rp2040_split (peripheral) 27.9 KiB 27.9 KiB +0.00% 0 0 0
use_config/stm32f1 62.6 KiB 62.5 KiB +0.00% ⬇️ -4 0 0
use_config/stm32h7 100.8 KiB 100.8 KiB +0.00% 0 0 0
use_rust/nrf52832_ble 385.5 KiB 385.5 KiB +0.00% 0 0 0
use_rust/nrf52840_ble 435.6 KiB 435.6 KiB +0.00% ⬇️ -4 0 0
use_rust/nrf52840_ble_split (central) 504.9 KiB 504.9 KiB +0.00% ⬆️ +4 0 0
use_rust/nrf52840_ble_split (peripheral) 318.4 KiB 318.4 KiB +0.00% ⬆️ +4 0 0
use_rust/pi_pico_w_ble 671.1 KiB 671.1 KiB +0.00% ⬆️ +4 0 0
use_rust/rp2040 144.9 KiB 144.9 KiB +0.00% 0 0 0
use_rust/rp2040_split (central) 157.9 KiB 158.0 KiB +0.00% ⬆️ +8 0 0
use_rust/rp2040_split (peripheral) 28.2 KiB 28.2 KiB +0.00% 0 0 0
use_rust/stm32f1 61.8 KiB 61.8 KiB +0.00% ⬇️ -4 0 0
use_rust/stm32h7 118.4 KiB 118.4 KiB +0.00% ⬆️ +4 0 0
use_config/nrf52832_ble — 397.5 KiB → 397.5 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 365036	   8620	  33344	 407000	  635d8	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 365040	   8620	  33344	 407004	  635dc	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +3.7%      +2  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -1.5%    -122  [ = ]       0    .debug_abbrev
  -0.1%    -229  [ = ]       0    .debug_line
  -0.1%    -457  [ = ]       0    .strtab
  -0.1% -1.01Ki  [ = ]       0    .debug_info
  -0.1% -3.96Ki  [ = ]       0    .debug_str
  -0.1% -5.76Ki  -0.0%      -4    TOTAL
use_config/nrf52840_ble — 438.1 KiB → 438.1 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 396596	   8628	  43368	 448592	  6d850	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 396600	   8628	  43368	 448596	  6d854	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +122  [ = ]       0    .debug_str
  +0.5%     +39  [ = ]       0    .debug_abbrev
  +0.0%     +33  [ = ]       0    .strtab
  +0.0%     +10  [ = ]       0    .debug_loc
  -0.0%      -4  -0.0%      -4    .text
 -41.8%     -28  [ = ]       0    [Unmapped]
  -0.0%     -79  [ = ]       0    .debug_info
  -0.0%    -157  [ = ]       0    .debug_line
  -0.0%     -64  -0.0%      -4    TOTAL
use_config/nrf52840_ble_split (central) — 500.9 KiB → 500.9 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 455612	   8684	  48576	 512872	  7d368	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 455616	   8684	  48576	 512876	  7d36c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +100  [ = ]       0    .debug_str
  +0.0%     +83  [ = ]       0    .debug_info
  +0.0%     +23  [ = ]       0    .debug_line
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -12  [ = ]       0    .strtab
 -44.1%     -30  [ = ]       0    [Unmapped]
  +0.0%    +160  -0.0%      -4    TOTAL
use_config/nrf52840_ble_split (peripheral) — 320.6 KiB → 320.6 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 292344	   8500	  27472	 328316	  5027c	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 292344	   8500	  27472	 328316	  5027c	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +32  [ = ]       0    .debug_str
  +0.0%     +16  [ = ]       0    .strtab
  +0.0%      +1  [ = ]       0    .debug_line
  +1.4%      +1  [ = ]       0    [Unmapped]
  -0.0%      -2  [ = ]       0    .debug_info
  +0.0%     +48  [ = ]       0    TOTAL
use_config/pi_pico_w_ble — 671.1 KiB → 671.1 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 634352	      0	  52904	 687256	  a7c98	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 634348	      0	  52904	 687252	  a7c94	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +4  +0.0%      +4    .text
 -11.6%      -8  [ = ]       0    [Unmapped]
  -0.0%     -24  [ = ]       0    .debug_info
  -0.4%     -39  [ = ]       0    .debug_abbrev
  -0.0%     -79  [ = ]       0    .debug_line
  -0.1%    -372  [ = ]       0    .strtab
  -0.1% -2.55Ki  [ = ]       0    .debug_str
  -0.0% -3.06Ki  +0.0%      +4    TOTAL
use_config/rp2040 — 145.8 KiB → 145.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135384	      0	  13892	 149276	  2471c	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135384	      0	  13892	 149276	  2471c	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +30  [ = ]       0    .debug_line
  -0.0%      -2  [ = ]       0    .debug_loc
  +0.0%     +28  [ = ]       0    TOTAL
use_config/rp2040_split (central) — 159.4 KiB → 159.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 148396	      0	  14844	 163240	  27da8	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 148388	      0	  14844	 163232	  27da0	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -6  [ = ]       0    .strtab
 -15.9%      -7  [ = ]       0    [Unmapped]
  -0.0%     -12  [ = ]       0    .debug_loc
  -0.0%     -37  [ = ]       0    .debug_info
  -0.0%    -106  [ = ]       0    .debug_str
  -0.1%    -124  [ = ]       0    .debug_line
  -0.0%    -284  +0.0%      +8    TOTAL
use_config/rp2040_split (peripheral) — 27.9 KiB → 27.9 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25696	     60	   2804	  28560	   6f90	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25696	     60	   2804	  28560	   6f90	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +1.9%      +1  [ = ]       0    [Unmapped]
  -0.2%     -39  [ = ]       0    .strtab
  -0.1%    -714  [ = ]       0    .debug_str
  -0.1%    -752  [ = ]       0    TOTAL
use_config/stm32f1 — 62.6 KiB → 62.5 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57684	     28	   6336	  64048	   fa30	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57688	     28	   6336	  64052	   fa34	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +62  [ = ]       0    .debug_str
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +6  [ = ]       0    .debug_line
  +5.0%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%     +76  -0.0%      -4    TOTAL
use_config/stm32h7 — 100.8 KiB → 100.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  94840	    264	   8112	 103216	  19330	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  94840	    264	   8112	 103216	  19330	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.12Ki  [ = ]       0    .debug_str
  +0.3%    +184  [ = ]       0    .strtab
  +8.7%      +4  [ = ]       0    [Unmapped]
  -0.0%     -36  [ = ]       0    .debug_info
  -0.1%    -126  [ = ]       0    .debug_line
  +0.0% +1.14Ki  [ = ]       0    TOTAL
use_rust/nrf52832_ble — 385.5 KiB → 385.5 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 352776	   8620	  33320	 394716	  605dc	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 352776	   8620	  33320	 394716	  605dc	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +10  [ = ]       0    .debug_loc
  +3.4%      +2  [ = ]       0    [Unmapped]
  +0.0%     +12  [ = ]       0    TOTAL
use_rust/nrf52840_ble — 435.6 KiB → 435.6 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 396796	   8628	  40616	 446040	  6ce58	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 396800	   8628	  40616	 446044	  6ce5c	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +1.6%      +1  [ = ]       0    [Unmapped]
  -0.0%      -2  [ = ]       0    .debug_loc
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -30  [ = ]       0    .strtab
  -0.0%     -63  [ = ]       0    .debug_info
  -0.0%    -110  [ = ]       0    .debug_str
  -0.0%    -140  [ = ]       0    .debug_line
  -0.0%    -348  -0.0%      -4    TOTAL
use_rust/nrf52840_ble_split (central) — 504.9 KiB → 504.9 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 457784	   8684	  50544	 517012	  7e394	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 457780	   8684	  50544	 517008	  7e390	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +3.29Ki  [ = ]       0    .debug_str
  +0.1%    +413  [ = ]       0    .strtab
  +0.0%      +4  +0.0%      +4    .text
  -6.1%      -3  [ = ]       0    [Unmapped]
  -0.0%     -48  [ = ]       0    .debug_info
  -0.0%    -131  [ = ]       0    .debug_line
  +0.0% +3.52Ki  +0.0%      +4    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 318.4 KiB → 318.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 290340	   8500	  27240	 326080	  4f9c0	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 290336	   8500	  27240	 326076	  4f9bc	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0% +1.34Ki  [ = ]       0    .debug_str
  +0.1%    +135  [ = ]       0    .strtab
  +0.0%      +4  +0.0%      +4    .text
 -12.5%      -8  [ = ]       0    [Unmapped]
  -0.0%     -97  [ = ]       0    .debug_line
  -0.0%    -234  [ = ]       0    .debug_info
  +0.0% +1.14Ki  +0.0%      +4    TOTAL
use_rust/pi_pico_w_ble — 671.1 KiB → 671.1 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 634228	      0	  53008	 687236	  a7c84	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 634224	      0	  53008	 687232	  a7c80	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +5  [ = ]       0    .debug_info
  +0.0%      +4  +0.0%      +4    .rodata
  -0.0%      -4  [ = ]       0    .debug_line
 -10.6%      -7  [ = ]       0    [Unmapped]
  -0.0%     -22  [ = ]       0    .strtab
  -0.0%     -44  [ = ]       0    .debug_str
  -0.0%     -68  +0.0%      +4    TOTAL
use_rust/rp2040 — 144.9 KiB → 144.9 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 134676	      0	  13732	 148408	  243b8	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 134676	      0	  13732	 148408	  243b8	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +101  [ = ]       0    .debug_str
  +0.1%     +94  [ = ]       0    .debug_line
  +0.0%     +37  [ = ]       0    .debug_info
  +0.0%      +1  [ = ]       0    .strtab
  +1.6%      +1  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  +0.0%    +224  [ = ]       0    TOTAL
use_rust/rp2040_split (central) — 157.9 KiB → 158.0 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 147160	      0	  14588	 161748	  277d4	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 147152	      0	  14588	 161740	  277cc	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.42Ki  [ = ]       0    .debug_str
  +0.2%    +248  [ = ]       0    .strtab
  +0.0%     +10  [ = ]       0    .debug_loc
  +0.0%      +8  +0.0%      +8    .text
  -9.7%      -6  [ = ]       0    [Unmapped]
  -0.0%     -49  [ = ]       0    .debug_info
  -0.1%    -142  [ = ]       0    .debug_line
  +0.1% +2.49Ki  +0.0%      +8    TOTAL
use_rust/rp2040_split (peripheral) — 28.2 KiB → 28.2 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25796	     60	   3068	  28924	   70fc	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25796	     60	   3068	  28924	   70fc	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
 -10.0%      -5  [ = ]       0    [Unmapped]
  -0.2%     -38  [ = ]       0    .strtab
  -0.1%    -737  [ = ]       0    .debug_str
  -0.1%    -780  [ = ]       0    TOTAL
use_rust/stm32f1 — 61.8 KiB → 61.8 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57012	     28	   6272	  63312	   f750	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57016	     28	   6272	  63316	   f754	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +62  [ = ]       0    .debug_str
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +6  [ = ]       0    .debug_line
  +5.0%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%     +76  -0.0%      -4    TOTAL
use_rust/stm32h7 — 118.4 KiB → 118.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 106908	    320	  14012	 121240	  1d998	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 106904	    320	  14012	 121236	  1d994	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +124  [ = ]       0    .debug_line
  +0.0%    +100  [ = ]       0    .debug_str
  +0.0%     +37  [ = ]       0    .debug_info
  +0.0%      +4  +0.0%      +4    .text
  -9.1%      -5  [ = ]       0    [Unmapped]
  +0.0%    +260  +0.0%      +4    TOTAL

@techmech-keeb

Copy link
Copy Markdown
Author

CI caught a real gap in my first push: I matched the attribute by the name Overwritten only, but the documented spelling (FAQ, stm32 examples) is #[Override(...)] — the old code never checked the attribute name at all, so both spellings were in use. That made the stm32 examples' #[Override(chip_config)] stop matching, surfacing as unused-import failures. Fixed: both spellings are matched, bind_interrupt passes validation (its own matching in bind_interrupt.rs is untouched), tests extended, and the three failing examples now build clean locally.

@HaoboGu

HaoboGu commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b139126459

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rmk-macro/src/codegen/override_helper.rs Outdated
An override attribute that failed to parse - an unknown or miscased
variant like `Entry` instead of `entry` - was silently skipped: the
`if let Ok(...)` matchers discarded darling's error and fell back to the
generated default, and the function itself was dropped from the
expansion, so neither the macro nor rustc reported anything. The
matchers also required `attrs.len() == 1`, so any extra attribute (doc
comments included) silently disabled a correctly spelled override.

Validate all override attributes up front in parse_keyboard_mod and
parse_split_peripheral_mod, emitting darling's diagnostics (which
already suggest the snake_case spelling) as compile errors via
write_errors(). Replace the per-site `attrs.len() == 1` + from_meta
matching with a shared find_overwritten() helper that locates the
attribute by path. Both spellings in real use are accepted: the
documented `#[Override(...)]` (docs/faq, stm32 examples) and
`#[Overwritten(...)]` (the enum's name) - the old matching ignored the
attribute path entirely, so both worked before. `bind_interrupt` is
accepted by validation as it appears in existing examples; its own
matching in bind_interrupt.rs is unchanged. Add unit tests for the
typo, extra-attribute, both-spellings, and valid cases.

Fixes rmk-rs#966

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3hnNYKmSK6ow1GZAT34F9
@techmech-keeb
techmech-keeb force-pushed the fix/overwritten-silent-fallback branch from b139126 to c7b52d4 Compare July 17, 2026 08:39
An attribute macro receives a module's items before cfg-stripping, so a
`#[cfg(...)] #[Override(...)]` function reaches the macro with its cfg
attribute intact (verified with a probe macro: an always-disabled fn is
still handed to the macro). Matching the override marker by path alone
would select or validate a cfg-disabled override, letting it replace the
generated default or emit a compile error for a disabled typo (PR rmk-rs#967
review by Codex).

Skip a function for override selection and validation when it carries
`#[cfg(...)]` or `#[cfg_attr(...)]`; inert attributes that don't gate
compilation (doc comments, `#[allow(...)]`, ...) may still accompany the
marker. Add tests for cfg/cfg_attr-gated markers, cfg-gated typos, and
inert-attribute markers.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3hnNYKmSK6ow1GZAT34F9
@HaoboGu

HaoboGu commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

@codex review again

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b1cafd36f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// Accepted so `#[Override(bind_interrupt)]` (used in existing examples)
/// passes validation; the bind_interrupt override itself is matched
/// separately in `bind_interrupt.rs`.
BindInterrupt,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wire bind_interrupt validation to the actual override matcher

When a user follows the documented #[Override(bind_interrupt)] form, this new enum variant makes validate_overwritten_attrs accept it as a valid marker, but expand_bind_interrupt still only recognizes a bare attribute whose path is bind_interrupt and therefore emits the generated default instead. In that configuration the custom interrupt binding function is dropped from the expansion with no diagnostic, so either this variant should be selected by the bind-interrupt path or the marker should remain rejected.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix this comment? @techmech-keeb

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow follow-up. Fixed in cabb8d8 — bind_interrupt overrides are now selected through the shared override matcher, so the documented #[Override(bind_interrupt)] form is actually applied after passing validation, with the same semantics as every other override (both spellings, inert attributes allowed, cfg-gated functions skipped). The legacy bare #[bind_interrupt] marker keeps working unchanged.

Wiring it up exposed that the stm32h7 example's custom binding had bit-rotted while it was being silently dropped: missing imports, and missing the EXTI lines async_matrix needs (the override replaces the whole generated block). Fixed the example body too — it now builds with its custom binding actually in effect, and added regression tests for the selection path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test it on the real hardware?

The documented `#[Override(bind_interrupt)]` form was accepted by
validation but never selected: expand_bind_interrupt only recognized a
bare attribute whose path is `bind_interrupt`, so the custom function
was silently dropped and the generated default emitted instead (rmk-rs#967
review).

Select bind_interrupt overrides through the shared override matcher, so
the documented form is applied and behaves like every other override
(both spellings, inert attributes allowed, cfg-gated functions skipped).
The legacy bare `#[bind_interrupt]` marker — the original syntax — keeps
working unchanged.

Wiring the override exposed that the stm32h7 example's custom binding
had bit-rotted while it was being dropped: it was missing imports and
the EXTI lines that `async_matrix` needs (the override replaces the
whole generated block). Fix the example body and note that requirement;
the example now builds with its custom binding actually in effect.

Add selection regression tests: the documented form, the Overwritten
spelling, the legacy bare marker, a doc-comment neighbor, cfg gating,
and a non-bind_interrupt marker.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[Overwritten(...)] silently falls back to the generated default on a typo or an extra attribute — happy to make it a compile error

2 participants