mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Reintroduce expansion info for proc macros 1.1
This commit is contained in:
parent
d84693b93d
commit
a260baae7e
@ -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))
|
||||
})
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user