← Back to Pull requests

Keep attribute spans in extern_protocol! #888

Open
unknown opened this pull request with 220 lines diff across 2 files
View on GitHub
unknown unknown commented on Oct 30, 2026 12:46 UTC
Author

Fixes #887.

extern_protocol! matched each attribute as #[$($attrs:tt)] and wrote it back as #[...], so the # and the brackets came from the macro. Clippy ignores docs from an external macro, so missing_safety_doc fired on every protocol trait, even with a # Safety section.

Each attribute is now moved as its two tokens, # and [...], so it keeps the caller's span:

  • extern_protocol! hands its input to __extern_protocol_attributes!, which moves one attribute per step until it reaches the trait.

  • The last arm of __extract_attributes_inner! matches $pound:tt $group:tt instead of #[$($parsed:tt)]. define_class! and extern_class! share that arm and behave as before.

  • The old matcher stays as __extern_protocol_check_syntax!, so invalid input is still reported against it.
  • Testing

  • New integration test crates/objc2/tests/extern_protocol.rs, under #![deny(clippy::missing_safety_doc)]: a protocol with a # Safety section must pass, and one without it carries #[expect(clippy::missing_safety_doc)], so the lint must still fire. It is an integration test because a protocol declared inside objc2 is not from an external macro, and does not show the bug.

  • With the old macros, cargo clippy -p objc2 --all-targets -- -D warnings fails on the documented protocol. With this change it passes.

  • cargo test -p objc2 passes.

  • The #[allow(clippy::missing_safety_doc)] in the extern_protocol! unit test is replaced by a # Safety section.
  • Recursion limit

    The helper adds one expansion step per attribute, so a protocol with a long doc comment uses more of the recursion limit. The longest run of attributes before a protocol in objc2-foundation 0.3.2 is 81, well under its recursion_limit = "512".

    🍄

    Diff: 220 lines (+165 / -55) across 2 files Reviewer: madsmtm Review duration: 33520m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.37) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 220 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.323
    Real PR Conversation Timeline
    1 comments
    "Review active on #888"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.8% (MEDIUM) · Higher = larger blast radius
    36.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.6% · Safe to merge
    19.6%
    Repository