Skip to content

Commit

Permalink
Revert "Point macros 1.1 errors to the input item"
Browse files Browse the repository at this point in the history
This reverts commit 3784067.
Any errors in the derived output now point at the derive attribute
instead of the item.
  • Loading branch information
keeperofdakeys committed Nov 8, 2016
1 parent 31a508e commit 134ef4f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
20 changes: 3 additions & 17 deletions src/libsyntax_ext/deriving/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ use errors::FatalError;
use proc_macro::{TokenStream, __internal};
use syntax::ast::{self, ItemKind, Attribute};
use syntax::attr::{mark_used, mark_known};
use syntax::codemap::{ExpnInfo, MacroAttribute, NameAndSpan, Span};
use syntax::codemap::Span;
use syntax::ext::base::*;
use syntax::fold::Folder;
use syntax::parse::token::InternedString;
use syntax::parse::token::intern;
use syntax::print::pprust;
use syntax::visit::Visitor;

struct MarkAttrs<'a>(&'a [InternedString]);
Expand Down Expand Up @@ -50,7 +48,7 @@ impl MultiItemModifier for CustomDerive {
fn expand(&self,
ecx: &mut ExtCtxt,
span: Span,
meta_item: &ast::MetaItem,
_meta_item: &ast::MetaItem,
item: Annotatable)
-> Vec<Annotatable> {
let item = match item {
Expand All @@ -75,18 +73,6 @@ impl MultiItemModifier for CustomDerive {
// Mark attributes as known, and used.
MarkAttrs(&self.attrs).visit_item(&item);

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
};

let input = __internal::new_token_stream(item.clone());
let res = __internal::set_parse_sess(&ecx.parse_sess, || {
let inner = self.inner;
Expand All @@ -113,7 +99,7 @@ impl MultiItemModifier for CustomDerive {
// Reassign spans of all expanded items to the input `item`
// for better errors here.
res.extend(new_items.into_iter().flat_map(|item| {
ChangeSpan { span: input_span }.fold_item(item)
ChangeSpan { span: span }.fold_item(item)
}).map(Annotatable::Item));
res
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
extern crate derive_unstable_2;

#[derive(Unstable)]
struct A;
//~^ ERROR: reserved for internal compiler
struct A;

fn main() {
foo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
extern crate derive_unstable;

#[derive(Unstable)]
struct A;
//~^ ERROR: use of unstable library feature
struct A;

fn main() {
unsafe { foo(); }
Expand Down

0 comments on commit 134ef4f

Please sign in to comment.