Giter Club home page Giter Club logo

Comments (3)

LukasKalbertodt avatar LukasKalbertodt commented on July 1, 2024

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.

CreepySkeleton avatar CreepySkeleton commented on July 1, 2024

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.37 proc_macro::TokenStream didn't implement UnwindSafe so this wrapper is necessary). Then it just gives this closure over to entry_point, the real work gets done there.
  • First, entry_point executes your code, catching all the panics via catch_unwind. Then it clears the thread_local storage, resumes panic if it's not especial AbortNow. Then, if storage is empty - it just returns your closure's result, if not - makes a sequence of compile_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.

LukasKalbertodt avatar LukasKalbertodt commented on July 1, 2024

Closed in #60

from auto_impl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.