]> git.lizzy.rs Git - rust.git/commitdiff
Point macros 1.1 errors to the input item
authorDavid Tolnay <dtolnay@gmail.com>
Fri, 2 Sep 2016 19:01:03 +0000 (12:01 -0700)
committerDavid Tolnay <dtolnay@gmail.com>
Tue, 6 Sep 2016 21:11:19 +0000 (14:11 -0700)
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

index 1f9c24a0dcd699ca7c191a9b97b1f96aff1d6b44..716cf3a94b5166bfec642b62a1a4b05ab8ccfbb3 100644 (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()
     }
 }