From 3784067edcbcd0614f6c4c88f6445ca17ae27ff6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 2 Sep 2016 12:01:03 -0700 Subject: [PATCH] Point macros 1.1 errors to the input item Before: ```rust error[E0106]: missing lifetime specifier --> src/main.rs:10:10 | 10 | #[derive(Serialize, Deserialize)] | ^ expected lifetime parameter error[E0038]: the trait `T` cannot be made into an object --> src/main.rs:15:15 | 15 | #[derive(Serialize, Deserialize)] | ^^^^^^^^^^ the trait `T` cannot be made into an object ``` After: ```rust error[E0106]: missing lifetime specifier --> src/main.rs:11:1 | 11 | struct A { | ^ expected lifetime parameter error[E0038]: the trait `T` cannot be made into an object --> src/main.rs:16:1 | 16 | struct B<'a> { | ^ the trait `T` cannot be made into an object ``` --- src/libsyntax_ext/deriving/custom.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index 1f9c24a0dcd69..716cf3a94b516 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -53,6 +53,7 @@ impl MultiItemModifier for CustomDerive { } } + let input_span = item.span; let input = __internal::new_token_stream(item); let res = __internal::set_parse_sess(&ecx.parse_sess, || { let inner = self.inner; @@ -77,9 +78,9 @@ impl MultiItemModifier for CustomDerive { // Right now we have no knowledge of spans at all in custom derive // macros, everything is just parsed as a string. Reassign all spans to - // the #[derive] attribute for better errors here. + // the input `item` for better errors here. item.into_iter().flat_map(|item| { - ChangeSpan { span: span }.fold_item(item) + ChangeSpan { span: input_span }.fold_item(item) }).map(Annotatable::Item).collect() } }