-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Point macros 1.1 errors to the input item #36308
Conversation
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 ```
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks @dtolnay! I wonder if perhaps the error could also somehow mention that the code originally came from Also looks like there are some errors on travis:
|
I tried the following: let input_span = Span {
expn_id: ecx.codemap().record_expansion(ExpnInfo {
call_site: span,
callee: NameAndSpan {
format: MacroAttribute(intern(&pprust::meta_item_to_string(meta_item))),
span: Some(span),
allow_internal_unstable: true,
},
}),
..item.span
}; expecting to see "note: in this macro invocation" pointing to the derive Serialize, but it didn't show that so I'll leave it to you. I will update the tests. |
Thanks! I talked with @nrc offline a bit and the conclusion was:
I think that the latter may already be true though? @dtolnay could you check to see if it's the case? |
Yep, working on confirming now. Side note: it would have helped if |
No, unfortunately the expanded code doesn't already have an struct A;
#[derive(Identity)]
struct B;
macro_rules! c {
() => {
struct C;
};
}
c!(); where #[rustc_macro_derive(Identity)]
pub fn id(input: TokenStream) -> TokenStream {
input
} The expanded code of course looks like: struct A;
struct B;
struct C; As expected, |
I pushed a commit that adds |
⌛ Testing commit fe41520 with merge d9a533f... |
💔 Test failed - auto-win-msvc-64-cargotest |
@bors: retry On Sat, Sep 10, 2016 at 11:47 AM, bors notifications@github.com wrote:
|
Point macros 1.1 errors to the input item Moved from alexcrichton#6 to continue discussion. Fixes #36218. 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 ```
So, uh, I filed #37563 to ask for the exact opposite change. I got an "unreachable expression" warning with the span pointing to an (empty) enum declaration. This made no sense to me, there is no expression there, it’s a type! It did not even occur to me that the error could be in code generated by a custom derive, until I asked for help on IRC and someone suggested it. |
Responded in #37563 (comment). |
Moved from alexcrichton#6 to continue discussion. Fixes #36218.
Before:
After: