Skip to content

Commit 66f39d9

Browse files
committed
---
yaml --- r: 128793 b: refs/heads/try c: 9434920 h: refs/heads/master i: 128791: bc9a23a v: v3
1 parent 6d40e98 commit 66f39d9

File tree

5 files changed

+130
-1
lines changed

5 files changed

+130
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: c3ce245ba68f62edfc5818f003b2b78a02ce5c03
5+
refs/heads/try: 9434920b24405588d22c17436b184736881ed933
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/test/auxiliary/macro_crate_test.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ macro_rules! unexported_macro (() => (3i))
3131
#[plugin_registrar]
3232
pub fn plugin_registrar(reg: &mut Registry) {
3333
reg.register_macro("make_a_1", expand_make_a_1);
34+
reg.register_macro("forged_ident", expand_forged_ident);
3435
reg.register_syntax_extension(
3536
token::intern("into_foo"),
3637
ItemModifier(expand_into_foo));
@@ -52,4 +53,29 @@ fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: Gc<MetaItem>, it: Gc<Item>)
5253
}
5354
}
5455

56+
fn expand_forged_ident(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResult> {
57+
use syntax::ext::quote::rt::*;
58+
59+
if !tts.is_empty() {
60+
cx.span_fatal(sp, "forged_ident takes no arguments");
61+
}
62+
63+
// Most of this is modelled after the expansion of the `quote_expr!`
64+
// macro ...
65+
let parse_sess = cx.parse_sess();
66+
let cfg = cx.cfg();
67+
68+
// ... except this is where we inject a forged identifier,
69+
// and deliberately do not call `cx.parse_tts_with_hygiene`
70+
// (because we are testing that this will be *rejected*
71+
// by the default parser).
72+
73+
let expr = {
74+
let tt = cx.parse_tts("\x00name_2,ctxt_0\x00".to_string());
75+
let mut parser = new_parser_from_tts(parse_sess, cfg, tt);
76+
parser.parse_expr()
77+
};
78+
MacExpr::new(expr)
79+
}
80+
5581
pub fn foo() {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 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+
// aux-build:macro_crate_test.rs
12+
// ignore-stage1
13+
// ignore-android
14+
// error-pattern: unknown start of token: \x00
15+
16+
// Issue #15750 and #15962 : this test is checking that the standard
17+
// parser rejects embedded idents. pnkfelix did not want to attempt
18+
// to make a test file that itself used the embedded ident input form,
19+
// since he worrid that would be difficult to work with in many text
20+
// editors, so instead he made a macro that expands into the embedded
21+
// ident form.
22+
23+
#![feature(phase)]
24+
25+
#[phase(plugin)]
26+
extern crate macro_crate_test;
27+
28+
fn main() {
29+
let x = 0;
30+
assert_eq!(3, forged_ident!());
31+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-include ../tools.mk
2+
3+
# Issue #15750, #15962 : This test ensures that our special embedded
4+
# ident syntax hack is not treated as legitimate input by the lexer in
5+
# normal mode.
6+
#
7+
# It is modelled after the `unicode-input/` test, since we need to
8+
# create files with syntax that can trip up normal text editting tools
9+
# (namely text with embedded nul-bytes).
10+
11+
# This test attempts to run rustc itself from the compiled binary; but
12+
# that means that you need to set the LD_LIBRARY_PATH for rustc itself
13+
# while running create_and_compile, and that won't work for stage1.
14+
15+
# FIXME ignore windows
16+
ifndef IS_WINDOWS
17+
ifeq ($(RUST_BUILD_STAGE),1)
18+
DOTEST=
19+
else
20+
DOTEST=dotest
21+
endif
22+
endif
23+
24+
all: $(DOTEST)
25+
26+
dotest:
27+
$(RUSTC) create_and_compile.rs
28+
$(call RUN,create_and_compile) "$(RUSTC)" "$(TMPDIR)"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 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+
use std::os;
12+
use std::io::{File, Command};
13+
14+
// creates broken.rs, which has the Ident \x00name_0,ctxt_0\x00
15+
// embedded within it, and then attempts to compile broken.rs with the
16+
// provided `rustc`
17+
18+
fn main() {
19+
let args = os::args();
20+
let rustc = args[1].as_slice();
21+
let tmpdir = Path::new(args[2].as_slice());
22+
23+
let main_file = tmpdir.join("broken.rs");
24+
let _ = File::create(&main_file).unwrap()
25+
.write_str("pub fn main() {
26+
let \x00name_0,ctxt_0\x00 = 3i;
27+
println!(\"{}\", \x00name_0,ctxt_0\x00);
28+
}");
29+
30+
// rustc is passed to us with --out-dir and -L etc., so we
31+
// can't exec it directly
32+
let result = Command::new("sh")
33+
.arg("-c")
34+
.arg(format!("{} {}",
35+
rustc,
36+
main_file.as_str()
37+
.unwrap()).as_slice())
38+
.output().unwrap();
39+
let err = String::from_utf8_lossy(result.error.as_slice());
40+
41+
// positive test so that this test will be updated when the
42+
// compiler changes.
43+
assert!(err.as_slice().contains("unknown start of token"))
44+
}

0 commit comments

Comments
 (0)