Skip to content

Commit ce3d610

Browse files
committed
Test #[derive(Trace)] on ignored lifetimes
This is broken because of lifetime bounds on `GcBrand`. I tried to remove them but it didn't work very well..... Probably need to read the nomicon (ugh) Also I realized my current implementation of `GcBrand` doesn't actually check that all its fields implement GcBrand. Ooops!
1 parent 8c1342a commit ce3d610

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

libs/derive/src/lib.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
extern crate proc_macro;
22

33
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};
115
use proc_macro2::{Ident, TokenStream, Span};
126
use syn::spanned::Spanned;
137
use syn::parse::{ParseStream, Parse};
@@ -696,30 +690,31 @@ fn impl_nop_trace(target: &DeriveInput, info: &GcTypeInfo) -> Result<TokenStream
696690
));
697691
},
698692
}
699-
let const_assertions = field_types.iter()
693+
let trace_assertions = field_types.iter()
700694
.map(|&t| {
701695
let ty_span = t.span();
702696
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+
);
708702
}
709703
}).collect::<Vec<_>>();
710704
Ok(quote! {
711-
#(#const_assertions)*
712705
unsafe impl #impl_generics ::zerogc::Trace for #name #ty_generics #where_clause {
713706
const NEEDS_TRACE: bool = false;
714707

715-
#[inline(always)] // NOP
708+
#[inline] // Should be const-folded away
716709
fn visit<V: ::zerogc::GcVisitor>(&mut self, #[allow(unused)] visitor: &mut V) -> Result<(), V::Err> {
710+
#(#trace_assertions)*
717711
Ok(())
718712
}
719713
}
720714
unsafe impl #impl_generics ::zerogc::TraceImmutable for #name #ty_generics #where_clause {
721-
#[inline(always)] // NOP
715+
#[inline] // Should be const-folded away
722716
fn visit_immutable<V: ::zerogc::GcVisitor>(&self, #[allow(unused)] visitor: &mut V) -> Result<(), V::Err> {
717+
#(#trace_assertions)*
723718
Ok(())
724719
}
725720
}

libs/derive/tests/basic.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ struct NopTrace {
6161
wow: Box<NopTrace>
6262
}
6363

64+
#[derive(Trace)]
65+
#[zerogc(nop_trace, ignore_lifetimes("'a"), ignore_params(T))]
66+
#[allow(unused)]
67+
struct LifetimeTrace<'a, T: GcSafe> {
68+
s: String,
69+
i: i32,
70+
wow: Box<NopTrace>,
71+
other: &'a LifetimeTrace<'a, T>,
72+
generic: Box<T>
73+
}
74+
6475

6576
#[test]
6677
fn basic() {

0 commit comments

Comments
 (0)