Skip to content

Give custom derive spans an expansion ID #38947

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

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ fn allow_unstable(cx: &mut ExtCtxt, span: Span, attr_name: &str) -> Span {
}

pub fn expand_derive(cx: &mut ExtCtxt,
span: Span,
mitem: &MetaItem,
annotatable: Annotatable)
-> Vec<Annotatable> {
span: Span,
mitem: &MetaItem,
annotatable: Annotatable)
-> Vec<Annotatable> {
debug!("expand_derive: span = {:?}", span);
debug!("expand_derive: mitem = {:?}", mitem);
debug!("expand_derive: annotatable input = {:?}", annotatable);
Expand Down Expand Up @@ -235,8 +235,21 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let titem = cx.meta_list_item_word(titem.span, titem.name().unwrap());
let mitem = cx.meta_list(titem.span, derive, vec![titem]);
let item = Annotatable::Item(item);

let span = Span {
expn_id: cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: mitem.span,
callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(Symbol::intern(&format!("derive({})", tname))),
span: None,
allow_internal_unstable: false,
},
}),
..mitem.span
};

if let SyntaxExtension::CustomDerive(ref ext) = *ext {
return ext.expand(cx, mitem.span, &mitem, item);
return ext.expand(cx, span, &mitem, item);
} else {
unreachable!()
}
Expand Down Expand Up @@ -285,8 +298,8 @@ pub fn expand_derive(cx: &mut ExtCtxt,
expn_id: cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: titem.span,
callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(Symbol::intern(&format!("derive({})", tname))),
span: Some(titem.span),
format: codemap::MacroAttribute(name),
span: None,
allow_internal_unstable: true,
},
}),
Expand Down