Lines Matching +full:proc +full:- +full:macro +full:- +full:api
3 …vis ci](https://travis-ci.org/CreepySkeleton/proc-macro-error.svg?branch=master)](https://travis-c…
4 [](https://docs.rs/proc-macro-error)
5 …idden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-…
7 This crate aims to make error reporting in proc-macros simple and easy to use.
8 Migrate from `panic!`-based errors for as little effort as possible!
18 available on stable ahead of time and your error-reporting code future-proof.
22 proc-macro-error = "1.0"
36 pub fn make_fn(input: TokenStream) -> TokenStream {
54 <img src="https://user-images.githubusercontent.com/50968528/78830016-d3b46a80-79d6-11ea-9de2-972e8…
60 <img src="https://user-images.githubusercontent.com/50968528/78830547-a9af7800-79d7-11ea-822e-59e29…
65 ### Panic-like usage
83 pub fn make_answer(input: TokenStream) -> TokenStream {
88 // This immediately aborts the proc-macro and shows the error
102 // so just highlight the proc-macro invocation itself
112 ### `proc_macro::Diagnostic`-like usage
120 fn process_attrs(attrs: &[Attribute]) -> Vec<Attribute> {
133 fn process_fields(_attrs: &Fields) -> Vec<TokenStream> {
140 pub fn make_answer(input: TokenStream) -> TokenStream {
160 * [`structopt-derive`](https://github.com/TeXitoi/structopt/tree/master/structopt-derive)
161 (abort-like usage)
162 * [`auto-impl`](https://github.com/auto-impl-rs/auto_impl/) (emit-like usage)
166 - Warnings are emitted only on nightly, they are ignored on stable.
167 - "help" suggestions can't have their own span info on stable,
169 - If your macro happens to trigger a panic, no errors will be displayed. This is not a
174 `proc_macro_error` will always be compatible with proc-macro Holy Trinity:
176 to you - `proc_macro_error` is available too.
182 > due to some bug in pre-1.34 rustc, putting proc-macro attributes inside macro
187 Error handling in proc-macros sucks. There's not much of a choice today:
188 you either "bubble up" the error up to the top-level of the macro and convert it to
191 - Former sucks because it's quite redundant to unroll a proper error handling
192 just for critical errors that will crash the macro anyway; so people mostly
195 Also, if you do decide to implement this `Result`-based architecture in your macro
199 - Later sucks because there's no way to carry out the span info via `panic!`.
202 Furthermore, panics aren't for error-reporting at all; panics are for bug-detecting
203 (like unwrapping on `None` or out-of-range indexing) or for early development stages
207 - There is [`proc_macro::Diagnostic`][] which is awesome but it has been experimental
210 This crate's API is intentionally designed to be compatible with `proc_macro::Diagnostic`
216 - It must be better than `panic!`. The main point: it must offer a way to carry the span information
218 - It must take as little effort as possible to migrate from `panic!`. Ideally, a new
219 macro with similar semantics plus ability to carry out span info.
220 - It must maintain compatibility with [`proc_macro::Diagnostic`][] .
221 - **It must be usable on stable**.
223 This crate aims to provide such a mechanism. All you have to do is annotate your top-level
237 Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
238 2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
245 for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
250 [compl_err]: https://doc.rust-lang.org/std/macro.compile_error.html
251 [`proc_macro::Diagnostic`]: https://doc.rust-lang.org/proc_macro/struct.Diagnostic.html
253 [crate::dummy]: https://docs.rs/proc-macro-error/1/proc_macro_error/dummy/index.html
254 [crate::multi]: https://docs.rs/proc-macro-error/1/proc_macro_error/multi/index.html
256 [`abort_call_site!`]: https://docs.rs/proc-macro-error/1/proc_macro_error/macro.abort_call_site.html
257 [`abort!`]: https://docs.rs/proc-macro-error/1/proc_macro_error/macro.abort.html
258 [guide]: https://docs.rs/proc-macro-error