Skip to content

fix(macros): harden correctness pass authority boundaries#9

Merged
eboody merged 1 commit intomainfrom
audit/correctness-pass
Mar 22, 2026
Merged

fix(macros): harden correctness pass authority boundaries#9
eboody merged 1 commit intomainfrom
audit/correctness-pass

Conversation

@eboody
Copy link
Owner

@eboody eboody commented Mar 22, 2026

Summary

  • fail closed on state/machine resolution by trusting already-expanded metadata instead of raw-source lookup
  • scope loaded macro metadata to the current crate and live file fingerprints to avoid stale or cross-crate matches
  • add adversarial UI coverage for out-of-order declarations, cfg-pruned duplicate names, ambiguous include fallback, the module-path apostrophe regression, and README doctests

Verification

  • cargo test --workspace
  • cargo clippy --workspace --all-targets -- -D warnings
  • bash scripts/check_readme_links.sh

@eboody eboody merged commit 0e862d8 into main Mar 22, 2026
7 checks passed
Copy link

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

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: a78879e345

ℹ️ 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 on lines +97 to +100
let mut cursor = Some(path.as_path());
while let Some(dir) = cursor {
if dir.join("Cargo.toml").is_file() {
return Some(dir.to_string_lossy().into_owned());

Choose a reason for hiding this comment

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

P2 Badge Scope loaded metadata by crate, not nearest Cargo.toml

crate_root_for_file() uses the first ancestor Cargo.toml as the isolation key, which collapses every target in one package (src, examples, tests, benches, extra bins) into the same bucket. When Cargo reuses the proc-macro process across those distinct crates, loaded_machine_is_current() / loaded_state_is_current() will treat metadata from another target as local, so duplicate crate::Machine or crate::State names can become ambiguous or resolve to the wrong item. That means the new code is isolating by package root, not by the “current crate” it claims to protect.

Useful? React with 👍 / 👎.

Comment on lines +57 to +59
fn loaded_machine_is_current(machine: &MachineInfo, current_crate_root: Option<&str>) -> bool {
if current_crate_root.is_some() && machine.crate_root.as_deref() != current_crate_root {
return false;

Choose a reason for hiding this comment

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

P2 Badge Keep crate filtering when transitions come from OUT_DIR includes

loaded_machine_is_current() only rejects foreign metadata when current_crate_root() returns Some(_). For include! fragments generated under OUT_DIR—a common way to produce transition impls—crate_root_for_file() finds no ancestor Cargo.toml, so this guard is skipped and lookup_unique_loaded_machine_by_name() falls back to every machine loaded in the proc-macro process. In builds that compile another crate with the same machine name, a valid generated include can now fail with the new ambiguous-machine path even though the conflict is outside the current crate.

Useful? React with 👍 / 👎.

@eboody eboody deleted the audit/correctness-pass branch March 23, 2026 17:55
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.

1 participant