|
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;
|
24 | 21 | 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; |
| 22 | +use syntax::print::pprust; |
| 23 | + |
| 24 | +trait FakeExtCtxt { |
| 25 | + fn call_site(&self) -> codemap::Span; |
| 26 | + fn cfg(&self) -> ast::CrateConfig; |
| 27 | + fn ident_of(&self, st: &str) -> ast::Ident; |
| 28 | + fn name_of(&self, st: &str) -> ast::Name; |
| 29 | + fn parse_sess(&self) -> &parse::ParseSess; |
33 | 30 | }
|
34 | 31 |
|
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 { |
| 32 | +impl FakeExtCtxt for parse::ParseSess { |
| 33 | + fn call_site(&self) -> codemap::Span { |
| 34 | + codemap::Span { |
42 | 35 | lo: codemap::BytePos(0),
|
43 | 36 | hi: codemap::BytePos(0),
|
44 |
| - expn_id: NO_EXPANSION |
| 37 | + expn_id: codemap::NO_EXPANSION, |
45 | 38 | }
|
46 | 39 | }
|
47 |
| - fn ident_of(st: &str) -> ast::ident { |
48 |
| - self.interner.intern(st) |
| 40 | + fn cfg(&self) -> ast::CrateConfig { Vec::new() } |
| 41 | + fn ident_of(&self, st: &str) -> ast::Ident { |
| 42 | + parse::token::str_to_ident(st) |
49 | 43 | }
|
| 44 | + fn name_of(&self, st: &str) -> ast::Name { |
| 45 | + parse::token::intern(st) |
| 46 | + } |
| 47 | + fn parse_sess(&self) -> &parse::ParseSess { self } |
50 | 48 | }
|
51 | 49 |
|
52 |
| -fn mk_ctxt() -> fake_ext_ctxt { |
53 |
| - parse::new_parse_sess(None) as fake_ext_ctxt |
54 |
| -} |
55 |
| - |
56 |
| - |
57 |
| - |
58 | 50 | fn main() {
|
59 |
| - let cx = mk_ctxt(); |
| 51 | + let cx = parse::new_parse_sess(); |
60 | 52 |
|
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 |
| -} |
| 53 | + quote_expr!(&cx, 23).and_then(|expr| { |
| 54 | + assert_eq!(pprust::expr_to_string(&expr), "23") |
| 55 | + }); |
67 | 56 |
|
68 |
| -fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) { |
69 |
| - panic!(); |
| 57 | + quote_expr!(&cx, 2 - $abcd + 7).and_then(|expr| { //~ ERROR unresolved name: abcd |
| 58 | + assert_eq!(pprust::expr_to_string(&expr), "2 - $abcd + 7") |
| 59 | + }); |
70 | 60 | }
|
0 commit comments