diff options
| author | bors <bors@rust-lang.org> | 2017-07-15 08:36:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-07-15 08:36:27 +0000 |
| commit | 70cd955277fdd3a941177f18bedae4223a48df02 (patch) | |
| tree | 8fa00583a68ea3c817d1776880774cd7e2034903 | |
| parent | 8658908cf822e9425d0841435c111584750aa236 (diff) | |
| parent | a260baae7e77bbae1497f0d37876947b15946553 (diff) | |
Auto merge of #43179 - oli-obk:mark_all_the_expansions, r=jseyfried
Reintroduce expansion info for proc macros 1.1 r? @jseyfried
| -rw-r--r-- | src/libproc_macro/lib.rs | 13 | ||||
| -rw-r--r-- | src/test/compile-fail-fulldeps/proc-macro/auxiliary/bang_proc_macro2.rs | 23 | ||||
| -rw-r--r-- | src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs | 26 |
3 files changed, 60 insertions, 2 deletions
diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 357e2ab853c..3c5d6aceca9 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -57,6 +57,7 @@ use syntax::symbol::Symbol; 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 @@ impl FromStr for TokenStream { __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 index 00000000000..5fc20bcda88 --- /dev/null +++ b/src/test/compile-fail-fulldeps/proc-macro/auxiliary/bang_proc_macro2.rs @@ -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 index 00000000000..93dead1a156 --- /dev/null +++ b/src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs @@ -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); +} |
