]> git.lizzy.rs Git - rust.git/commitdiff
Reintroduce expansion info for proc macros 1.1
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 11 Jul 2017 07:52:50 +0000 (09:52 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 12 Jul 2017 07:47:04 +0000 (09:47 +0200)
src/libproc_macro/lib.rs
src/test/compile-fail-fulldeps/proc-macro/auxiliary/bang_proc_macro2.rs [new file with mode: 0644]
src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs [new file with mode: 0644]

index 06f9634d70613e2a47fe4b7d5a246087aff9a865..9f011d6e2e8e9d3d42c708816e209d03856a3b5d 100644 (file)
@@ -57,6 +57,7 @@
 use syntax::tokenstream;
 use syntax_pos::DUMMY_SP;
 use syntax_pos::SyntaxContext;
+use syntax_pos::hygiene::Mark;
 
 /// The main type provided by this crate, representing an abstract stream of
 /// tokens.
@@ -86,8 +87,16 @@ fn from_str(src: &str) -> Result<TokenStream, LexError> {
         __internal::with_sess(|(sess, mark)| {
             let src = src.to_string();
             let name = "<proc-macro source code>".to_string();
-            let call_site = mark.expn_info().unwrap().call_site;
-            let stream = parse::parse_stream_from_source_str(name, src, sess, Some(call_site));
+            let expn_info = mark.expn_info().unwrap();
+            let call_site = expn_info.call_site;
+            // notify the expansion info that it is unhygienic
+            let mark = Mark::fresh(mark);
+            mark.set_expn_info(expn_info);
+            let span = syntax_pos::Span {
+                ctxt: SyntaxContext::empty().apply_mark(mark),
+                ..call_site
+            };
+            let stream = parse::parse_stream_from_source_str(name, src, sess, Some(span));
             Ok(__internal::token_stream_wrap(stream))
         })
     }
diff --git a/src/test/compile-fail-fulldeps/proc-macro/auxiliary/bang_proc_macro2.rs b/src/test/compile-fail-fulldeps/proc-macro/auxiliary/bang_proc_macro2.rs
new file mode 100644 (file)
index 0000000..5fc20bc
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// force-host
+// no-prefer-dynamic
+#![feature(proc_macro)]
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro]
+pub fn bang_proc_macro2(_: TokenStream) -> TokenStream {
+    "let x = foobar2;".parse().unwrap()
+}
diff --git a/src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs b/src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs
new file mode 100644 (file)
index 0000000..93dead1
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:bang_proc_macro2.rs
+
+#![feature(proc_macro)]
+#![allow(unused_macros)]
+
+extern crate bang_proc_macro2;
+
+use bang_proc_macro2::bang_proc_macro2;
+
+fn main() {
+    let foobar = 42;
+    bang_proc_macro2!();
+    //~^ ERROR cannot find value `foobar2` in this scope
+    //~^^ did you mean `foobar`?
+    println!("{}", x);
+}