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
```
This commit is contained in:
David Tolnay 2016-09-02 12:01:03 -07:00
parent 13c4e32e7a
commit 3784067edc

View File

@ -53,6 +53,7 @@ fn expand(&self,
}
}
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 @@ fn expand(&self,
// 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()
}
}