Replace deprecated proc-macro-error2 with proc-macro2-diagnostics#4613
Open
tautschnig wants to merge 2 commits into
Open
Replace deprecated proc-macro-error2 with proc-macro2-diagnostics#4613tautschnig wants to merge 2 commits into
tautschnig wants to merge 2 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
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-error2usage (abort!,abort_call_site!,#[proc_macro_error]) withproc_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.lockto removeproc-macro-error2and addproc-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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.