Skip to content

Use quote_spanned when generating calls to gc_arena methods#12

Merged
kyren merged 1 commit intokyren:masterfrom
Aaron1011:quote-spanned
Feb 13, 2021
Merged

Use quote_spanned when generating calls to gc_arena methods#12
kyren merged 1 commit intokyren:masterfrom
Aaron1011:quote-spanned

Conversation

@Aaron1011
Copy link
Collaborator

We now span calls to Collect::needs_trace and Collect::trace
with the span of the field that we're generating the call for. This
leads to nicer error messages when a trait bound is not fulfulled (and
likely better runtime backtraces as well)

We now span calls to `Collect::needs_trace` and `Collect::trace`
with the span of the field that we're generating the call for. This
leads to nicer error messages when a trait bound is not fulfulled (and
likely better runtime backtraces as well)
::: $WORKSPACE/src/gc-arena/src/collect.rs
|
| Self: Sized,
| ----- required by this bound in `needs_trace`
Copy link
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.

@Aaron1011
Copy link
Collaborator Author

The CircleCI tests failed, but I'm getting a 404 page when I click on 'Details'

@kyren
Copy link
Owner

kyren commented Feb 13, 2021

The CircleCI tests failed, but I'm getting a 404 page when I click on 'Details'

CircleCI is failing due to a rustfmt error:

                 let ty = &b.ast().ty;
                 quote_spanned!(b.ast().span()=>
                     || <#ty as gc_arena::Collect>::needs_trace()
-                ).to_tokens(&mut needs_trace_body);
+                )
+                .to_tokens(&mut needs_trace_body);
             }
         }
         // Likewise, this will skip any fields that have `#[collect(require_static)]`

But I'm not too concerned about it, I can make a rustfmt pass in a bit before doing another release. Otherwise this makes sense and LGTM.

Also CircleCI has been erroring for me recently at git checkout for some reason, I have no idea why yet and I haven't fixed it.

@kyren kyren merged commit 1f04104 into kyren:master Feb 13, 2021
Aaron1011 added a commit to Aaron1011/gc-arena that referenced this pull request Feb 13, 2021
PR kyren#12 used `quote_spanned` to make error messages have the span of the
corresponding field in the struct. However, there's no indication that
the error comes from `#[derive(Collect)]`, which could be confusing for
people unfamiliar with the crate.

This PR uses `Span::resolved_at` to give the generated spans the hygiene
information from the call site. This causes rustc to add a note about
the error message originating from a macro, while still keeping the
error message at the proper location.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants