Skip to content

Replace deprecated proc-macro-error2 with proc-macro2-diagnostics#4613

Open
tautschnig wants to merge 2 commits into
model-checking:mainfrom
tautschnig:no-proc-macro-error2
Open

Replace deprecated proc-macro-error2 with proc-macro2-diagnostics#4613
tautschnig wants to merge 2 commits into
model-checking:mainfrom
tautschnig:no-proc-macro-error2

Conversation

@tautschnig

Copy link
Copy Markdown
Member

proc-macro-error2 is unmaintained (RUSTSEC-2026-0173). Migrate the kani_macros crate to proc-macro2-diagnostics, one of the alternatives recommended by the advisory.

The abort!/abort_call_site! macros (which panicked and were caught by the #[proc_macro_error] wrapper) are replaced by threading Result<TokenStream, Diagnostic> through the macro helpers and emitting the diagnostic at each entry point via Diagnostic::emit_as_item_tokens(). The structured note/help sub-diagnostics and spans are preserved, and proc-macro2-diagnostics auto-enables native nightly emission, so the compiler output is unchanged.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

proc-macro-error2 is unmaintained (RUSTSEC-2026-0173). Migrate the
kani_macros crate to proc-macro2-diagnostics, one of the alternatives
recommended by the advisory.

The abort!/abort_call_site! macros (which panicked and were caught by
the #[proc_macro_error] wrapper) are replaced by threading
Result<TokenStream, Diagnostic> through the macro helpers and emitting
the diagnostic at each entry point via Diagnostic::emit_as_item_tokens().
The structured note/help sub-diagnostics and spans are preserved, and
proc-macro2-diagnostics auto-enables native nightly emission, so the
compiler output is unchanged.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 24, 2026 10:24
@tautschnig tautschnig requested a review from a team as a code owner June 24, 2026 10:24
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Jun 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the kani_macros proc-macro crate off the unmaintained proc-macro-error2 (flagged by RUSTSEC-2026-0173) to proc-macro2-diagnostics, reworking macro error handling to emit structured diagnostics without relying on panic-catching wrappers.

Changes:

  • Replaced proc-macro-error2 usage (abort!, abort_call_site!, #[proc_macro_error]) with proc_macro2_diagnostics::Diagnostic-based error construction/emission.
  • Refactored derive/proof macro helpers to return Result<_, Diagnostic> and emit diagnostics at macro entry points.
  • Updated dependencies in Cargo.toml/Cargo.lock to remove proc-macro-error2 and add proc-macro2-diagnostics.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
library/kani_macros/src/sysroot/loop_contracts/mod.rs Replaces abort_call_site! with Diagnostic emission for unsupported loop forms.
library/kani_macros/src/lib.rs Removes #[proc_macro_error] and migrates sysroot proof argument parsing to Diagnostic-based reporting.
library/kani_macros/src/derive.rs Threads Result<_, Diagnostic> through derive helpers and emits diagnostics at entry points.
library/kani_macros/src/derive_bounded.rs Converts union-derive failure to Diagnostic and emits at entry point.
library/kani_macros/Cargo.toml Swaps proc-macro-error2 dependency for proc-macro2-diagnostics.
Cargo.lock Updates lockfile entries to reflect dependency replacement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread library/kani_macros/src/lib.rs Outdated
Comment thread library/kani_macros/src/lib.rs Outdated
Address review feedback on the proc-macro2-diagnostics migration:

- Drop the brittle `Diagnostic` -> `syn::Error` -> `Diagnostic` round-trip
  in the `#[kani::proof(...)]` option parser. Splitting the syntactic parse
  (`RawProofOptions`) from validation (`parse_proof_options`) lets the
  unknown-option error be built as a `Diagnostic` at the entry point, so its
  `help`/`note` render as proper sub-diagnostics again instead of being
  flattened into a `syn::Error` message.
- Make the `syn::Error` -> `Diagnostic` conversion for genuine parse errors
  explicit via `map_err(Diagnostic::from)` rather than relying on the
  implicit `?` conversion.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants