summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-14 20:27:56 +0000
committerbors <bors@rust-lang.org>2018-07-14 20:27:56 +0000
commitb486d3d13f1f8127614e1e182439c55fbac82964 (patch)
tree95c53051893b9f5663c7d2da7fcbef444e90fab2 /src/libsyntax_ext
parentcbcd81a4a9312146942f8781376cabc109bfbcf0 (diff)
parent94c9ea4baee98c1d6579865d0e0d78a45927aa83 (diff)
downloadrust-b486d3d13f1f8127614e1e182439c55fbac82964.tar.gz
rust-b486d3d13f1f8127614e1e182439c55fbac82964.zip
Auto merge of #52326 - alexcrichton:tweak-proc-macro-expand, r=petrochenkov
rustc: Tweak expansion of #[proc_macro] for 2018

The syntactical expansion of `#[proc_macro]` and related attributes currently
contains absolute paths which conflicts with a lint for the 2018 edition,
causing issues like #52214. This commit puts a band-aid on the issue by ensuring
that procedural macros can also migrate to the 2018 edition for now by tweaking
the expansion based on what features are activated. A more long-term solution
would probably tweak the edition hygiene of spans, but this should do the trick
for now.

Closes #52214
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/proc_macro_registrar.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/libsyntax_ext/proc_macro_registrar.rs b/src/libsyntax_ext/proc_macro_registrar.rs
index 2522fa769c5..3cfa50b3e7d 100644
--- a/src/libsyntax_ext/proc_macro_registrar.rs
+++ b/src/libsyntax_ext/proc_macro_registrar.rs
@@ -23,6 +23,7 @@ use syntax::fold::Folder;
 use syntax::parse::ParseSess;
 use syntax::ptr::P;
 use syntax::symbol::Symbol;
+use syntax::symbol::keywords;
 use syntax::visit::{self, Visitor};
 
 use syntax_pos::{Span, DUMMY_SP};
@@ -380,9 +381,13 @@ fn mk_registrar(cx: &mut ExtCtxt,
     let register_custom_derive = Ident::from_str("register_custom_derive");
     let register_attr_proc_macro = Ident::from_str("register_attr_proc_macro");
     let register_bang_proc_macro = Ident::from_str("register_bang_proc_macro");
+    let crate_kw = Ident::with_empty_ctxt(keywords::Crate.name());
+    let local_path = |cx: &mut ExtCtxt, sp: Span, name: Ident| {
+        cx.path(sp.with_ctxt(span.ctxt()), vec![crate_kw, name])
+    };
 
     let mut stmts = custom_derives.iter().map(|cd| {
-        let path = cx.path_global(cd.span, vec![cd.function_name]);
+        let path = local_path(cx, cd.span, cd.function_name);
         let trait_name = cx.expr_str(cd.span, cd.trait_name);
         let attrs = cx.expr_vec_slice(
             span,
@@ -399,7 +404,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
 
     stmts.extend(custom_attrs.iter().map(|ca| {
         let name = cx.expr_str(ca.span, ca.function_name.name);
-        let path = cx.path_global(ca.span, vec![ca.function_name]);
+        let path = local_path(cx, ca.span, ca.function_name);
         let registrar = cx.expr_ident(ca.span, registrar);
 
         let ufcs_path = cx.path(span,
@@ -411,7 +416,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
 
     stmts.extend(custom_macros.iter().map(|cm| {
         let name = cx.expr_str(cm.span, cm.function_name.name);
-        let path = cx.path_global(cm.span, vec![cm.function_name]);
+        let path = local_path(cx, cm.span, cm.function_name);
         let registrar = cx.expr_ident(cm.span, registrar);
 
         let ufcs_path = cx.path(span,