|
10 | 10 |
|
11 | 11 | // compile-flags: -Z parse-only
|
12 | 12 |
|
13 |
| -// ignore-test Can't use syntax crate here |
| 13 | +// ignore-cross-compile |
14 | 14 |
|
15 |
| -#![feature(quote)] |
| 15 | +#![feature(quote, rustc_private)] |
16 | 16 |
|
17 | 17 | extern crate syntax;
|
18 | 18 |
|
19 |
| -use io::*; |
20 |
| - |
21 |
| -use syntax::diagnostic; |
22 | 19 | use syntax::ast;
|
23 | 20 | use syntax::codemap;
|
| 21 | +use syntax::parse::token; |
24 | 22 | use syntax::parse;
|
25 |
| -use syntax::print::*; |
26 |
| - |
27 |
| - |
28 |
| -trait fake_ext_ctxt { |
29 |
| - fn cfg() -> ast::CrateConfig; |
30 |
| - fn parse_sess() -> parse::parse_sess; |
31 |
| - fn call_site() -> span; |
32 |
| - fn ident_of(st: &str) -> ast::ident; |
| 23 | +use syntax::print::pprust; |
| 24 | + |
| 25 | +trait FakeExtCtxt { |
| 26 | + fn call_site(&self) -> codemap::Span; |
| 27 | + fn cfg(&self) -> ast::CrateConfig; |
| 28 | + fn ident_of(&self, st: &str) -> ast::Ident; |
| 29 | + fn name_of(&self, st: &str) -> ast::Name; |
| 30 | + fn parse_sess(&self) -> &parse::ParseSess; |
33 | 31 | }
|
34 | 32 |
|
35 |
| -type fake_session = parse::parse_sess; |
36 |
| - |
37 |
| -impl fake_ext_ctxt for fake_session { |
38 |
| - fn cfg() -> ast::CrateConfig { Vec::new() } |
39 |
| - fn parse_sess() -> parse::parse_sess { self } |
40 |
| - fn call_site() -> span { |
41 |
| - codemap::span { |
| 33 | +impl FakeExtCtxt for parse::ParseSess { |
| 34 | + fn call_site(&self) -> codemap::Span { |
| 35 | + codemap::Span { |
42 | 36 | lo: codemap::BytePos(0),
|
43 | 37 | hi: codemap::BytePos(0),
|
44 |
| - expn_id: NO_EXPANSION |
| 38 | + expn_id: codemap::NO_EXPANSION, |
45 | 39 | }
|
46 | 40 | }
|
47 |
| - fn ident_of(st: &str) -> ast::ident { |
48 |
| - self.interner.intern(st) |
| 41 | + fn cfg(&self) -> ast::CrateConfig { Vec::new() } |
| 42 | + fn ident_of(&self, st: &str) -> ast::Ident { |
| 43 | + token::str_to_ident(st) |
49 | 44 | }
|
| 45 | + fn name_of(&self, st: &str) -> ast::Name { |
| 46 | + token::intern(st) |
| 47 | + } |
| 48 | + fn parse_sess(&self) -> &parse::ParseSess { self } |
50 | 49 | }
|
51 | 50 |
|
52 |
| -fn mk_ctxt() -> fake_ext_ctxt { |
53 |
| - parse::new_parse_sess(None) as fake_ext_ctxt |
54 |
| -} |
55 |
| - |
56 |
| - |
57 |
| - |
58 | 51 | fn main() {
|
59 |
| - let cx = mk_ctxt(); |
| 52 | + let cx = parse::new_parse_sess(); |
60 | 53 |
|
61 |
| - let abc = quote_expr!(cx, 23); |
62 |
| - check_pp(abc, pprust::print_expr, "23"); |
63 |
| - |
64 |
| - let expr3 = quote_expr!(cx, 2 - $abcd + 7); //~ ERROR unresolved name: abcd |
65 |
| - check_pp(expr3, pprust::print_expr, "2 - 23 + 7"); |
66 |
| -} |
| 54 | + quote_expr!(&cx, 23).and_then(|expr| { |
| 55 | + assert_eq!(pprust::expr_to_string(&expr), "23") |
| 56 | + }); |
67 | 57 |
|
68 |
| -fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) { |
69 |
| - panic!(); |
| 58 | + quote_expr!(&cx, 2 - $abcd + 7).and_then(|expr| { //~ ERROR unresolved name: abcd |
| 59 | + assert_eq!(pprust::expr_to_string(&expr), "2 - $abcd + 7") |
| 60 | + }); |
70 | 61 | }
|
0 commit comments