Skip to content

Commit 70cd955

Browse files
committed
Auto merge of #43179 - oli-obk:mark_all_the_expansions, r=jseyfried
Reintroduce expansion info for proc macros 1.1 r? @jseyfried
2 parents 8658908 + a260baa commit 70cd955

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/libproc_macro/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use syntax::symbol::Symbol;
5757
use syntax::tokenstream;
5858
use syntax_pos::DUMMY_SP;
5959
use syntax_pos::SyntaxContext;
60+
use syntax_pos::hygiene::Mark;
6061

6162
/// The main type provided by this crate, representing an abstract stream of
6263
/// tokens.
@@ -86,8 +87,16 @@ impl FromStr for TokenStream {
8687
__internal::with_sess(|(sess, mark)| {
8788
let src = src.to_string();
8889
let name = "<proc-macro source code>".to_string();
89-
let call_site = mark.expn_info().unwrap().call_site;
90-
let stream = parse::parse_stream_from_source_str(name, src, sess, Some(call_site));
90+
let expn_info = mark.expn_info().unwrap();
91+
let call_site = expn_info.call_site;
92+
// notify the expansion info that it is unhygienic
93+
let mark = Mark::fresh(mark);
94+
mark.set_expn_info(expn_info);
95+
let span = syntax_pos::Span {
96+
ctxt: SyntaxContext::empty().apply_mark(mark),
97+
..call_site
98+
};
99+
let stream = parse::parse_stream_from_source_str(name, src, sess, Some(span));
91100
Ok(__internal::token_stream_wrap(stream))
92101
})
93102
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// force-host
12+
// no-prefer-dynamic
13+
#![feature(proc_macro)]
14+
#![crate_type = "proc-macro"]
15+
16+
extern crate proc_macro;
17+
18+
use proc_macro::TokenStream;
19+
20+
#[proc_macro]
21+
pub fn bang_proc_macro2(_: TokenStream) -> TokenStream {
22+
"let x = foobar2;".parse().unwrap()
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:bang_proc_macro2.rs
12+
13+
#![feature(proc_macro)]
14+
#![allow(unused_macros)]
15+
16+
extern crate bang_proc_macro2;
17+
18+
use bang_proc_macro2::bang_proc_macro2;
19+
20+
fn main() {
21+
let foobar = 42;
22+
bang_proc_macro2!();
23+
//~^ ERROR cannot find value `foobar2` in this scope
24+
//~^^ did you mean `foobar`?
25+
println!("{}", x);
26+
}

0 commit comments

Comments
 (0)