]> git.lizzy.rs Git - rust.git/blob - src/test/parse-fail/qquote-1.rs
rollup merge of #24541: alexcrichton/issue-24538
[rust.git] / src / test / parse-fail / qquote-1.rs
1 // Copyright 2012-2014 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 // compile-flags: -Z parse-only
12
13 // ignore-test Can't use syntax crate here
14
15 #![feature(quote)]
16
17 extern crate syntax;
18
19 use io::*;
20
21 use syntax::diagnostic;
22 use syntax::ast;
23 use syntax::codemap;
24 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;
33 }
34
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 {
42             lo: codemap::BytePos(0),
43             hi: codemap::BytePos(0),
44             expn_id: NO_EXPANSION
45         }
46     }
47     fn ident_of(st: &str) -> ast::ident {
48         self.interner.intern(st)
49     }
50 }
51
52 fn mk_ctxt() -> fake_ext_ctxt {
53     parse::new_parse_sess(None) as fake_ext_ctxt
54 }
55
56
57
58 fn main() {
59     let cx = mk_ctxt();
60
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 }
67
68 fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) {
69     panic!();
70 }