Skip to content

Commit

Permalink
Point macros 1.1 errors to the input item
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
dtolnay committed Sep 6, 2016
1 parent 13c4e32 commit 3784067
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libsyntax_ext/deriving/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
}
}
Expand Down

0 comments on commit 3784067

Please sign in to comment.