|
1 | 1 | extern crate proc_macro;
|
2 | 2 |
|
3 | 3 | use quote::{quote, quote_spanned};
|
4 |
| -use syn::{ |
5 |
| - parse_macro_input, parenthesized, parse_quote, DeriveInput, |
6 |
| - Data, Error, Generics, GenericParam, TypeParamBound, Fields, |
7 |
| - Member, Index, Type, GenericArgument, Attribute, PathArguments, |
8 |
| - Meta, TypeParam, WherePredicate, PredicateType, Token, Lifetime, |
9 |
| - NestedMeta, Lit |
10 |
| -}; |
| 4 | +use syn::{parse_macro_input, parenthesized, parse_quote, DeriveInput, Data, Error, Generics, GenericParam, TypeParamBound, Fields, Member, Index, Type, GenericArgument, Attribute, PathArguments, Meta, TypeParam, WherePredicate, PredicateType, Token, Lifetime, NestedMeta, Lit, PredicateLifetime}; |
11 | 5 | use proc_macro2::{Ident, TokenStream, Span};
|
12 | 6 | use syn::spanned::Spanned;
|
13 | 7 | use syn::parse::{ParseStream, Parse};
|
@@ -696,30 +690,31 @@ fn impl_nop_trace(target: &DeriveInput, info: &GcTypeInfo) -> Result<TokenStream
|
696 | 690 | ));
|
697 | 691 | },
|
698 | 692 | }
|
699 |
| - let const_assertions = field_types.iter() |
| 693 | + let trace_assertions = field_types.iter() |
700 | 694 | .map(|&t| {
|
701 | 695 | let ty_span = t.span();
|
702 | 696 | quote_spanned! { ty_span =>
|
703 |
| - #[allow(clippy::eq_op)] |
704 |
| - const _: [(); 0 - !{ |
705 |
| - const ASSERT: bool = !<#t as Trace>::NEEDS_TRACE; |
706 |
| - ASSERT |
707 |
| - } as usize] = []; |
| 697 | + assert!( |
| 698 | + !<#t as Trace>::NEEDS_TRACE, |
| 699 | + "Can't #[derive(NullTrace) with {}", |
| 700 | + stringify!(#t) |
| 701 | + ); |
708 | 702 | }
|
709 | 703 | }).collect::<Vec<_>>();
|
710 | 704 | Ok(quote! {
|
711 |
| - #(#const_assertions)* |
712 | 705 | unsafe impl #impl_generics ::zerogc::Trace for #name #ty_generics #where_clause {
|
713 | 706 | const NEEDS_TRACE: bool = false;
|
714 | 707 |
|
715 |
| - #[inline(always)] // NOP |
| 708 | + #[inline] // Should be const-folded away |
716 | 709 | fn visit<V: ::zerogc::GcVisitor>(&mut self, #[allow(unused)] visitor: &mut V) -> Result<(), V::Err> {
|
| 710 | + #(#trace_assertions)* |
717 | 711 | Ok(())
|
718 | 712 | }
|
719 | 713 | }
|
720 | 714 | unsafe impl #impl_generics ::zerogc::TraceImmutable for #name #ty_generics #where_clause {
|
721 |
| - #[inline(always)] // NOP |
| 715 | + #[inline] // Should be const-folded away |
722 | 716 | fn visit_immutable<V: ::zerogc::GcVisitor>(&self, #[allow(unused)] visitor: &mut V) -> Result<(), V::Err> {
|
| 717 | + #(#trace_assertions)* |
723 | 718 | Ok(())
|
724 | 719 | }
|
725 | 720 | }
|
|
0 commit comments