Skip to main content

miniextendr_macros/
deprecation.rs

1//! Compile-time warnings for deprecated `#[miniextendr]` options (#2117).
2//!
3//! A proc macro can't emit a warning on stable Rust, but code that names a
4//! `#[deprecated]` item can. The option parsers record the span of an
5//! explicit `worker`, and the `#[miniextendr]` entry point appends one
6//! reference to `miniextendr_api::worker::WORKER_OPTION` per recorded span,
7//! so rustc warns at the option itself. `#![allow(deprecated)]` on the
8//! enclosing module silences it.
9
10use std::cell::RefCell;
11
12const WORKER_OPTIONS: ::std::thread::LocalKey<RefCell<Vec<proc_macro2::Span>>>
    =
    {
        const __RUST_STD_INTERNAL_INIT: RefCell<Vec<proc_macro2::Span>> =
            { RefCell::new(Vec::new()) };
        unsafe {
            ::std::thread::LocalKey::new(const {
                        if ::std::mem::needs_drop::<RefCell<Vec<proc_macro2::Span>>>()
                            {
                            |__rust_std_internal_init|
                                {
                                    #[thread_local]
                                    static __RUST_STD_INTERNAL_VAL:
                                        ::std::thread::local_impl::EagerStorage<RefCell<Vec<proc_macro2::Span>>>
                                        =
                                        ::std::thread::local_impl::EagerStorage::new(__RUST_STD_INTERNAL_INIT);
                                    __RUST_STD_INTERNAL_VAL.get()
                                }
                        } else {
                            |__rust_std_internal_init|
                                {
                                    #[thread_local]
                                    static __RUST_STD_INTERNAL_VAL:
                                        RefCell<Vec<proc_macro2::Span>> =
                                        __RUST_STD_INTERNAL_INIT;
                                    &__RUST_STD_INTERNAL_VAL
                                }
                        }
                    })
        }
    };thread_local! {
13    static WORKER_OPTIONS: RefCell<Vec<proc_macro2::Span>> = const { RefCell::new(Vec::new()) };
14}
15
16/// Record an explicit `worker` option written at `span`.
17pub(crate) fn worker_option(span: proc_macro2::Span) {
18    WORKER_OPTIONS.with(|spans| spans.borrow_mut().push(span));
19}
20
21/// The references that make rustc warn at each `worker` option recorded
22/// since the last call.
23pub(crate) fn take() -> proc_macro2::TokenStream {
24    WORKER_OPTIONS
25        .with(RefCell::take)
26        .into_iter()
27        .map(|span| {
28            {
    let mut _s = ::quote::__private::TokenStream::new();
    let _span: ::quote::__private::Span =
        ::quote::__private::get_span(span).__into_span();
    ::quote::__private::push_ident_spanned(&mut _s, _span, "const");
    ::quote::__private::push_underscore_spanned(&mut _s, _span);
    ::quote::__private::push_colon_spanned(&mut _s, _span);
    ::quote::__private::push_group_spanned(&mut _s, _span,
        ::quote::__private::Delimiter::Parenthesis,
        {
            let _: ::quote::__private::Span =
                ::quote::__private::get_span(_span).__into_span();
            ::quote::__private::TokenStream::new()
        });
    ::quote::__private::push_eq_spanned(&mut _s, _span);
    ::quote::__private::push_colon2_spanned(&mut _s, _span);
    ::quote::__private::push_ident_spanned(&mut _s, _span, "miniextendr_api");
    ::quote::__private::push_colon2_spanned(&mut _s, _span);
    ::quote::__private::push_ident_spanned(&mut _s, _span, "worker");
    ::quote::__private::push_colon2_spanned(&mut _s, _span);
    ::quote::__private::push_ident_spanned(&mut _s, _span, "WORKER_OPTION");
    ::quote::__private::push_semi_spanned(&mut _s, _span);
    _s
}quote::quote_spanned! {span=>
29                const _: () = ::miniextendr_api::worker::WORKER_OPTION;
30            }
31        })
32        .collect()
33}