Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/gc-arena-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use quote::{quote, quote_spanned, ToTokens};
use syn::spanned::Spanned;
use synstructure::{decl_derive, AddBounds};

Expand Down Expand Up @@ -160,12 +160,20 @@ fn collect_derive(mut s: synstructure::Structure) -> TokenStream {
for v in s.variants() {
for b in v.bindings() {
let ty = &b.ast().ty;
quote!(|| <#ty as gc_arena::Collect>::needs_trace())
.to_tokens(&mut needs_trace_body);
quote_spanned!(b.ast().span()=>
|| <#ty as gc_arena::Collect>::needs_trace()
).to_tokens(&mut needs_trace_body);
}
}
// Likewise, this will skip any fields that have `#[collect(require_static)]`
let trace_body = s.each(|bi| quote!(gc_arena::Collect::trace(#bi, cc)));
let trace_body = s.each(|bi| {
// Make sure to only use `quote_spanned` on the method call
// tokens - we want to use the call site span for the `cc` identifier
let trace_method = quote_spanned!(bi.ast().span()=>
gc_arena::Collect::trace
);
quote!(#trace_method (#bi, cc))
});

s.clone().add_bounds(AddBounds::Fields).gen_impl(quote! {
gen unsafe impl gc_arena::Collect for @Self #where_clause {
Expand Down
11 changes: 11 additions & 0 deletions src/gc-arena/tests/ui/bad_collect_bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use gc_arena::Collect;

struct NotCollect;

#[derive(Collect)]
#[collect(no_drop)]
struct MyStruct {
field: NotCollect
}

fn main() {}
18 changes: 18 additions & 0 deletions src/gc-arena/tests/ui/bad_collect_bound.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0277]: the trait bound `NotCollect: Collect` is not satisfied
--> $DIR/bad_collect_bound.rs:8:5
|
8 | field: NotCollect
| ^^^^^^^^^^^^^^^^^ the trait `Collect` is not implemented for `NotCollect`
|
::: $WORKSPACE/src/gc-arena/src/collect.rs
|
| Self: Sized,
| ----- required by this bound in `needs_trace`
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to rust-lang/rust#82038 - once that issue is fixed, this extra line should go away.


error[E0277]: the trait bound `NotCollect: Collect` is not satisfied
--> $DIR/bad_collect_bound.rs:8:5
|
8 | field: NotCollect
| ^^^^^^^^^^^^^^^^^ the trait `Collect` is not implemented for `NotCollect`
|
= note: required by `trace`