]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/qquote-1.rs
rollup merge of #17355 : gamazeps/issue17210
[rust.git] / src / test / compile-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 // ignore-test Can't use syntax crate here
12
13 #![feature(quote)]
14
15 extern crate syntax;
16
17 use io::*;
18
19 use syntax::diagnostic;
20 use syntax::ast;
21 use syntax::codemap;
22 use syntax::parse;
23 use syntax::print::*;
24
25
26 trait fake_ext_ctxt {
27     fn cfg() -> ast::CrateConfig;
28     fn parse_sess() -> parse::parse_sess;
29     fn call_site() -> span;
30     fn ident_of(st: &str) -> ast::ident;
31 }
32
33 type fake_session = parse::parse_sess;
34
35 impl fake_ext_ctxt for fake_session {
36     fn cfg() -> ast::CrateConfig { Vec::new() }
37     fn parse_sess() -> parse::parse_sess { self }
38     fn call_site() -> span {
39         codemap::span {
40             lo: codemap::BytePos(0),
41             hi: codemap::BytePos(0),
42             expn_id: NO_EXPANSION
43         }
44     }
45     fn ident_of(st: &str) -> ast::ident {
46         self.interner.intern(st)
47     }
48 }
49
50 fn mk_ctxt() -> fake_ext_ctxt {
51     parse::new_parse_sess(None) as fake_ext_ctxt
52 }
53
54
55
56 fn main() {
57     let cx = mk_ctxt();
58
59     let abc = quote_expr!(cx, 23);
60     check_pp(abc,  pprust::print_expr, "23");
61
62     let expr3 = quote_expr!(cx, 2 - $abcd + 7); //~ ERROR unresolved name: abcd
63     check_pp(expr3,  pprust::print_expr, "2 - 23 + 7");
64 }
65
66 fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) {
67     fail!();
68 }