From 3be6991099d612088c34eeed7cbfd5eaee3873a8 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 10 Jan 2017 11:02:26 +1300 Subject: [PATCH] Give custom derive spans an expansion ID --- src/libsyntax_ext/deriving/mod.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index 2573690d153..096f6dfd5d8 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -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 { + span: Span, + mitem: &MetaItem, + annotatable: Annotatable) + -> Vec { debug!("expand_derive: span = {:?}", span); debug!("expand_derive: mitem = {:?}", mitem); debug!("expand_derive: annotatable input = {:?}", annotatable); @@ -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!() } @@ -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, }, }),