Comments (3)
Hi there!
Thanks for reaching out to us. While writing diag.rs
I certainly wished that there was a nice proc macro error reporting library. So I'm very tempted to replace it with a library.
However, I'm not quite sure about proc-macro-error
. Reading over the documentation, it seems a bit too much magic to me. Especially the #[proc_macro_error]
attribute and what exactly it does to the main function is not clear to me. But maybe it's indeed a good way to do error reporting in proc macros and I just don't understand yet. I would have to try it or see it in action to really be able to judge.
If you want, you can prepare a PR under the condition that I might still say "no" to it. Of course I'm not the only one deciding things for auto-impl
. And we should probably wait for your new release so that auto-impl
does not loose functionality (notes). But I can also totally understand if you don't want to create a PR that might get rejected.
from auto_impl.
There's no magic involved, actually. #[proc_macro_error]
just helps you to build up right entry_point
invocation while keeping indentation level flat. What exactly it does:
- It makes a closure of your whole top-level function, wrapping it with
AssertUnwindSafe
if needed or requested (for example, prior to Rust 1.37proc_macro::TokenStream
didn't implementUnwindSafe
so this wrapper is necessary). Then it just gives this closure over toentry_point
, the real work gets done there. - First,
entry_point
executes your code, catching all the panics viacatch_unwind
. Then it clears thethread_local
storage, resumes panic if it's not especialAbortNow
. Then, if storage is empty - it just returns your closure's result, if not - makes a sequence ofcompile_error!
invocations and returns it instead. Basically, that's all.
As you see, there's no magic in it. Moreover, if you decide to implement such global storage at yourself you'll simply end up reimplementing 80% of my crate and there's no guarantee you won't miss something. For example, global storage MUST be cleared (you already know what might happen if you don't do that 😄), even in case of panic, so you would have to use catch_unwind
too, which brings all the headache of AssertUnwingSafe
.
If you want, you can prepare a PR under the condition that I might still say "no" to it.
This is just sensible, I would be very surprised otherwise. In fact, I was just checking if it's still maintained :)
from auto_impl.
Closed in #60
from auto_impl.
Related Issues (20)
- Emit warning on empty proxy type list HOT 3
- Make `Fn*` types work with some generic methods HOT 1
- Relicense as MIT/Apache-2 HOT 4
- Newtype support HOT 9
- Add `!` (never) as proxy type HOT 3
- auto_impl for trait objects? HOT 3
- Compiler error running tests
- Make impls apply for trait objects HOT 9
- Add proper compile-fail tests HOT 2
- Investigate using `syn-mid` HOT 3
- Auto-impl trait objects? HOT 8
- Unable to use auto_impl with async-trait HOT 17
- Use `Span::mixed_site` HOT 3
- `no_std` support HOT 2
- Support mutable function arguments HOT 1
- const generics support HOT 1
- Errors when using an associated type defined in a supertrait HOT 6
- Doesn't work with generic associated types HOT 1
- request for crates.io minor release with syn 2 upgrade HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto_impl.