Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proc-macro: Use transparent marks for call-site hygiene
- Loading branch information
1 parent
99ecdb3
commit 297109e
Showing
5 changed files
with
116 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/run-pass-fulldeps/proc-macro/auxiliary/call-site.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2018 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. | ||
|
||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
#![feature(proc_macro)] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::*; | ||
|
||
#[proc_macro] | ||
pub fn check(input: TokenStream) -> TokenStream { | ||
// Parsed `x2` can refer to `x2` from `input` | ||
let parsed1: TokenStream = "let x3 = x2;".parse().unwrap(); | ||
// `x3` parsed from one string can refer to `x3` parsed from another string. | ||
let parsed2: TokenStream = "let x4 = x3;".parse().unwrap(); | ||
// Manually assembled `x4` can refer to parsed `x4`. | ||
let manual: Vec<TokenTree> = vec![ | ||
Ident::new("let", Span::call_site()).into(), | ||
Ident::new("x5", Span::call_site()).into(), | ||
Punct::new('=', Spacing::Alone).into(), | ||
Ident::new("x4", Span::call_site()).into(), | ||
Punct::new(';', Spacing::Alone).into(), | ||
]; | ||
input.into_iter().chain(parsed1.into_iter()) | ||
.chain(parsed2.into_iter()) | ||
.chain(manual.into_iter()) | ||
.collect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
// aux-build:call-site.rs | ||
// ignore-stage1 | ||
|
||
#![feature(proc_macro, proc_macro_non_items)] | ||
|
||
extern crate call_site; | ||
use call_site::*; | ||
|
||
fn main() { | ||
let x1 = 10; | ||
call_site::check!(let x2 = x1;); | ||
let x6 = x5; | ||
} |