diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 06f9634d70613..9f011d6e2e8e9 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 = "".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 0000000000000..5fc20bcda8856 --- /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 or the MIT license +// , 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 0000000000000..93dead1a15685 --- /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 or the MIT license +// , 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); +}