Skip to content

Commit a42d8e8

Browse files
committed
Unrot and re-enable parse-fail/qquote-{1,2}.rs
FIXME: qquote-2.rs fails at runtime, rather than parse time, which is bad.
1 parent 1c32a34 commit a42d8e8

File tree

2 files changed

+54
-71
lines changed

2 files changed

+54
-71
lines changed

src/test/parse-fail/qquote-1.rs

+28-38
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,51 @@
1010

1111
// compile-flags: -Z parse-only
1212

13-
// ignore-test Can't use syntax crate here
13+
// ignore-cross-compile
1414

15-
#![feature(quote)]
15+
#![feature(quote, rustc_private)]
1616

1717
extern crate syntax;
1818

19-
use io::*;
20-
21-
use syntax::diagnostic;
2219
use syntax::ast;
2320
use syntax::codemap;
2421
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;
3330
}
3431

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 {
4235
lo: codemap::BytePos(0),
4336
hi: codemap::BytePos(0),
44-
expn_id: NO_EXPANSION
37+
expn_id: codemap::NO_EXPANSION,
4538
}
4639
}
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)
4943
}
44+
fn name_of(&self, st: &str) -> ast::Name {
45+
parse::token::intern(st)
46+
}
47+
fn parse_sess(&self) -> &parse::ParseSess { self }
5048
}
5149

52-
fn mk_ctxt() -> fake_ext_ctxt {
53-
parse::new_parse_sess(None) as fake_ext_ctxt
54-
}
55-
56-
57-
5850
fn main() {
59-
let cx = mk_ctxt();
51+
let cx = parse::new_parse_sess();
6052

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+
});
6756

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+
});
7060
}

src/test/parse-fail/qquote-2.rs

+26-33
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,47 @@
1010

1111
// compile-flags: -Z parse-only
1212

13-
// ignore-test Can't use syntax crate here
13+
// ignore-cross-compile
1414

15-
#![feature(quote)]
15+
#![feature(quote, rustc_private)]
1616

1717
extern crate syntax;
1818

19-
use syntax::diagnostic;
2019
use syntax::ast;
2120
use syntax::codemap;
22-
use syntax::parse::parser;
23-
use syntax::print::*;
24-
25-
trait fake_ext_ctxt {
26-
fn cfg() -> ast::CrateConfig;
27-
fn parse_sess() -> parse::parse_sess;
28-
fn call_site() -> span;
29-
fn ident_of(st: &str) -> ast::ident;
21+
use syntax::parse;
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;
3030
}
3131

32-
type fake_session = parse::parse_sess;
33-
34-
impl fake_ext_ctxt for fake_session {
35-
fn cfg() -> ast::CrateConfig { Vec::new() }
36-
fn parse_sess() -> parse::parse_sess { self }
37-
fn call_site() -> span {
38-
codemap::span {
32+
impl FakeExtCtxt for parse::ParseSess {
33+
fn call_site(&self) -> codemap::Span {
34+
codemap::Span {
3935
lo: codemap::BytePos(0),
4036
hi: codemap::BytePos(0),
41-
expn_id: codemap::NO_EXPANSION
37+
expn_id: codemap::NO_EXPANSION,
4238
}
4339
}
44-
fn ident_of(st: &str) -> ast::ident {
45-
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)
4643
}
44+
fn name_of(&self, st: &str) -> ast::Name {
45+
parse::token::intern(st)
46+
}
47+
fn parse_sess(&self) -> &parse::ParseSess { self }
4748
}
4849

49-
fn mk_ctxt() -> fake_ext_ctxt {
50-
parse::new_parse_sess(None) as fake_ext_ctxt
51-
}
52-
53-
5450
fn main() {
55-
let cx = mk_ctxt();
56-
57-
let stmt = quote_stmt!(cx, let x isize = 20;); //~ ERROR expected end-of-string
58-
check_pp(*stmt, pprust::print_stmt, "");
59-
}
51+
let cx = parse::new_parse_sess();
6052

61-
fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) {
62-
panic!();
53+
quote_expr!(&cx, let x isize = 20;).and_then(|expr| { //~ ERROR expected end-of-string
54+
assert_eq!(pprust::expr_to_string(&expr), "let x isize = 20;")
55+
});
6356
}

0 commit comments

Comments
 (0)