Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate out from proc macro error #920

Merged
merged 1 commit into from
May 14, 2024
Merged

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented May 9, 2024

Implement Result<T, E> based proc macro error handling instead of out
of fashion proc_macro_error that still is in syn 1.0. This allows
us to remove the need for proc_macro_error crate and makes our
dependency tree leaner.

The error handling is implemented with custom ToTokensDiagnostics trait
that is used instead of the ToTokens when there is a possibility for
error. Error is passed up in the call stack via Diagnostics struct
that converts to compile error token stream at root of the macro call.

The result based approach is the recommended way of handling compile
errors in proc macros.

Resolves #854

@juhaku juhaku force-pushed the chore-migrate-off-proc-macro-error branch 4 times, most recently from e222c59 to ae687f4 Compare May 13, 2024 19:40
@juhaku juhaku changed the title Wip migrate out from proc macro error Migrate out from proc macro error May 13, 2024
@juhaku juhaku force-pushed the chore-migrate-off-proc-macro-error branch from ae687f4 to b4702a1 Compare May 14, 2024 14:07
@juhaku juhaku marked this pull request as ready for review May 14, 2024 14:08
@juhaku juhaku force-pushed the chore-migrate-off-proc-macro-error branch 2 times, most recently from 595e078 to df9ad98 Compare May 14, 2024 14:11
Implement `Result<T, E>` based proc macro error handling instead of out
of fashion `proc_macro_error` that still is in _syn_ `1.0`. This allows
us to remove the need for `proc_macro_error` crate and makes our
dependency tree leaner.

The error handling is implemented with custom `ToTokensDiagnostics` trait
that is used instead of the `ToTokens` when there is a possibility for
error. Error is passed up in the call stack via `Diagnostics` struct
that converts to compile error token stream at root of the macro call.

The result based approach is the recommended way of handling compile
errors in proc macros.

Resolves #854
@juhaku juhaku force-pushed the chore-migrate-off-proc-macro-error branch from df9ad98 to 733fb18 Compare May 14, 2024 15:06
@juhaku juhaku merged commit f03e7d5 into master May 14, 2024
14 checks passed
@juhaku juhaku deleted the chore-migrate-off-proc-macro-error branch May 14, 2024 15:19
juhaku added a commit that referenced this pull request May 16, 2024
Fix compile error propagation via comprehensive use of
`ToTokensDiagnostics` trait. `ToTokensDiagnostics` was introduced in
PR #920 to allow error propagation up in the call stack for error
reporting. However this initial implementation was too limited which
resulted invalid compile errors in case of error. This implementation
aims to fix the shortcomings of the initial implementation.
juhaku added a commit that referenced this pull request May 16, 2024
Fix compile error propagation via comprehensive use of
`ToTokensDiagnostics` trait. `ToTokensDiagnostics` was introduced in
PR #920 to allow error propagation up in the call stack for error
reporting. However this initial implementation was too limited which
resulted invalid compile errors in case of error. This implementation
aims to fix the shortcomings of the initial implementation.
juhaku added a commit that referenced this pull request May 16, 2024
Fix compile error propagation via comprehensive use of
`ToTokensDiagnostics` trait. `ToTokensDiagnostics` was introduced in
PR #920 to allow error propagation up in the call stack for error
reporting. However this initial implementation was too limited which
resulted invalid compile errors in case of error. This implementation
aims to fix the shortcomings of the initial implementation.
juhaku added a commit that referenced this pull request May 16, 2024
Fix compile error propagation via comprehensive use of
`ToTokensDiagnostics` trait. `ToTokensDiagnostics` was introduced in
PR #920 to allow error propagation up in the call stack for error
reporting. However this initial implementation was too limited which
resulted invalid compile errors in case of error. This implementation
aims to fix the shortcomings of the initial implementation.
juhaku added a commit that referenced this pull request May 16, 2024
Fix compile error propagation via comprehensive use of
`ToTokensDiagnostics` trait. `ToTokensDiagnostics` was introduced in
PR #920 to allow error propagation up in the call stack for error
reporting. However this initial implementation was too limited which
resulted invalid compile errors in case of error. This implementation
aims to fix the shortcomings of the initial implementation.

Fixes #927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

The proc-macro-error crate is end-of-life and unmaintained
1 participant