Skip to content

Commit d51df3d

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 e5afca4 commit d51df3d

File tree

2 files changed

+56
-71
lines changed

2 files changed

+56
-71
lines changed

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

+29-38
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,52 @@
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;
21+
use syntax::parse::token;
2422
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;
3331
}
3432

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 {
4236
lo: codemap::BytePos(0),
4337
hi: codemap::BytePos(0),
44-
expn_id: NO_EXPANSION
38+
expn_id: codemap::NO_EXPANSION,
4539
}
4640
}
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)
4944
}
45+
fn name_of(&self, st: &str) -> ast::Name {
46+
token::intern(st)
47+
}
48+
fn parse_sess(&self) -> &parse::ParseSess { self }
5049
}
5150

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

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

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

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

+27-33
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,48 @@
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::token;
22+
use syntax::parse;
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;
3031
}
3132

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 {
33+
impl FakeExtCtxt for parse::ParseSess {
34+
fn call_site(&self) -> codemap::Span {
35+
codemap::Span {
3936
lo: codemap::BytePos(0),
4037
hi: codemap::BytePos(0),
41-
expn_id: codemap::NO_EXPANSION
38+
expn_id: codemap::NO_EXPANSION,
4239
}
4340
}
44-
fn ident_of(st: &str) -> ast::ident {
45-
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)
4644
}
45+
fn name_of(&self, st: &str) -> ast::Name {
46+
token::intern(st)
47+
}
48+
fn parse_sess(&self) -> &parse::ParseSess { self }
4749
}
4850

49-
fn mk_ctxt() -> fake_ext_ctxt {
50-
parse::new_parse_sess(None) as fake_ext_ctxt
51-
}
52-
53-
5451
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-
}
52+
let cx = parse::new_parse_sess();
6053

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

0 commit comments

Comments
 (0)