Skip to content

Commit 3182bbb

Browse files
committed
---
yaml --- r: 116442 b: refs/heads/snap-stage3 c: f5ead0d h: refs/heads/master v: v3
1 parent d1ffca4 commit 3182bbb

File tree

5 files changed

+110
-72
lines changed

5 files changed

+110
-72
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 296102ec869834a7faed34106ad2cf24dd83766a
4+
refs/heads/snap-stage3: f5ead0dd66ab7c3aaaaabcc34e1726a4acd74b07
55
refs/heads/try: 009d898a9422ac04c1aa60c0e9aff3abc5fa4672
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/doc/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and its implications on a task that programmers usually find very difficult: con
1818

1919
Ownership is central to Rust,
2020
and is the feature from which many of Rust's powerful capabilities are derived.
21-
"Ownership" refers to which parts of your code are allowed read,
21+
"Ownership" refers to which parts of your code are allowed to read,
2222
write, and ultimately release, memory.
2323
Let's start by looking at some C++ code:
2424

branches/snap-stage3/src/libregex_macros/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
html_root_url = "http://doc.rust-lang.org/")]
2121

2222
#![feature(macro_registrar, managed_boxes, quote)]
23-
#![allow(unused_imports)] // `quote_expr!` adds some `use` globs which may be unused
2423

2524
extern crate regex;
2625
extern crate syntax;

branches/snap-stage3/src/libserialize/json.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,10 @@ impl<A:ToJson,B:ToJson,C:ToJson> ToJson for (A, B, C) {
22272227
}
22282228
}
22292229

2230+
impl<'a, A:ToJson> ToJson for &'a [A] {
2231+
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
2232+
}
2233+
22302234
impl<A:ToJson> ToJson for ~[A] {
22312235
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
22322236
}
@@ -3334,6 +3338,56 @@ mod tests {
33343338
assert!(stack.get(1) == Key("foo"));
33353339
}
33363340

3341+
#[test]
3342+
fn test_to_json() {
3343+
use collections::{HashMap,TreeMap};
3344+
use super::ToJson;
3345+
3346+
let list2 = List(vec!(Number(1.0_f64), Number(2.0_f64)));
3347+
let list3 = List(vec!(Number(1.0f64), Number(2.0f64), Number(3.0f64)));
3348+
let object = {
3349+
let mut tree_map = TreeMap::new();
3350+
tree_map.insert("a".to_string(), Number(1.0_f64));
3351+
tree_map.insert("b".to_string(), Number(2.0_f64));
3352+
Object(box tree_map)
3353+
};
3354+
3355+
assert_eq!(list2.to_json(), list2);
3356+
assert_eq!(object.to_json(), object);
3357+
assert_eq!(3_i.to_json(), Number(3.0_f64));
3358+
assert_eq!(4_i8.to_json(), Number(4.0_f64));
3359+
assert_eq!(5_i16.to_json(), Number(5.0_f64));
3360+
assert_eq!(6_i32.to_json(), Number(6.0_f64));
3361+
assert_eq!(7_i64.to_json(), Number(7.0_f64));
3362+
assert_eq!(8_u.to_json(), Number(8.0_f64));
3363+
assert_eq!(9_u8.to_json(), Number(9.0_f64));
3364+
assert_eq!(10_u16.to_json(), Number(10.0_f64));
3365+
assert_eq!(11_u32.to_json(), Number(11.0_f64));
3366+
assert_eq!(12_u64.to_json(), Number(12.0_f64));
3367+
assert_eq!(13.0_f32.to_json(), Number(13.0_f64));
3368+
assert_eq!(14.0_f64.to_json(), Number(14.0_f64));
3369+
assert_eq!(().to_json(), Null);
3370+
assert_eq!(true.to_json(), Boolean(true));
3371+
assert_eq!(false.to_json(), Boolean(false));
3372+
assert_eq!("abc".to_string().to_json(), String("abc".to_string()));
3373+
assert_eq!((1, 2).to_json(), list2);
3374+
assert_eq!((1, 2, 3).to_json(), list3);
3375+
assert_eq!([1, 2].to_json(), list2);
3376+
assert_eq!((&[1, 2, 3]).to_json(), list3);
3377+
assert_eq!((~[1, 2]).to_json(), list2);
3378+
assert_eq!(vec!(1, 2, 3).to_json(), list3);
3379+
let mut tree_map = TreeMap::new();
3380+
tree_map.insert("a".to_string(), 1);
3381+
tree_map.insert("b".to_string(), 2);
3382+
assert_eq!(tree_map.to_json(), object);
3383+
let mut hash_map = HashMap::new();
3384+
hash_map.insert("a".to_string(), 1);
3385+
hash_map.insert("b".to_string(), 2);
3386+
assert_eq!(hash_map.to_json(), object);
3387+
assert_eq!(Some(15).to_json(), Number(15 as f64));
3388+
assert_eq!(None::<int>.to_json(), Null);
3389+
}
3390+
33373391
#[bench]
33383392
fn bench_streaming_small(b: &mut Bencher) {
33393393
b.iter( || {

branches/snap-stage3/src/libsyntax/ext/quote.rs

Lines changed: 54 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,16 @@ fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
401401
vec!(e_str))
402402
}
403403

404+
fn mk_ast_path(cx: &ExtCtxt, sp: Span, name: &str) -> @ast::Expr {
405+
let idents = vec!(id_ext("syntax"), id_ext("ast"), id_ext(name));
406+
cx.expr_path(cx.path_global(sp, idents))
407+
}
408+
409+
fn mk_token_path(cx: &ExtCtxt, sp: Span, name: &str) -> @ast::Expr {
410+
let idents = vec!(id_ext("syntax"), id_ext("parse"), id_ext("token"), id_ext(name));
411+
cx.expr_path(cx.path_global(sp, idents))
412+
}
413+
404414
fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOp) -> @ast::Expr {
405415
let name = match bop {
406416
PLUS => "PLUS",
@@ -414,116 +424,96 @@ fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOp) -> @ast::Expr {
414424
SHL => "SHL",
415425
SHR => "SHR"
416426
};
417-
cx.expr_ident(sp, id_ext(name))
427+
mk_token_path(cx, sp, name)
418428
}
419429

420430
fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
421431

422432
match *tok {
423433
BINOP(binop) => {
424-
return cx.expr_call_ident(sp,
425-
id_ext("BINOP"),
426-
vec!(mk_binop(cx, sp, binop)));
434+
return cx.expr_call(sp, mk_token_path(cx, sp, "BINOP"), vec!(mk_binop(cx, sp, binop)));
427435
}
428436
BINOPEQ(binop) => {
429-
return cx.expr_call_ident(sp,
430-
id_ext("BINOPEQ"),
431-
vec!(mk_binop(cx, sp, binop)));
437+
return cx.expr_call(sp, mk_token_path(cx, sp, "BINOPEQ"),
438+
vec!(mk_binop(cx, sp, binop)));
432439
}
433440

434441
LIT_CHAR(i) => {
435442
let e_char = cx.expr_lit(sp, ast::LitChar(i));
436443

437-
return cx.expr_call_ident(sp, id_ext("LIT_CHAR"), vec!(e_char));
444+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_CHAR"), vec!(e_char));
438445
}
439446

440447
LIT_INT(i, ity) => {
441448
let s_ity = match ity {
442-
ast::TyI => "TyI".to_string(),
443-
ast::TyI8 => "TyI8".to_string(),
444-
ast::TyI16 => "TyI16".to_string(),
445-
ast::TyI32 => "TyI32".to_string(),
446-
ast::TyI64 => "TyI64".to_string()
449+
ast::TyI => "TyI",
450+
ast::TyI8 => "TyI8",
451+
ast::TyI16 => "TyI16",
452+
ast::TyI32 => "TyI32",
453+
ast::TyI64 => "TyI64"
447454
};
448-
let e_ity = cx.expr_ident(sp, id_ext(s_ity.as_slice()));
449-
455+
let e_ity = mk_ast_path(cx, sp, s_ity);
450456
let e_i64 = cx.expr_lit(sp, ast::LitInt(i, ast::TyI64));
451-
452-
return cx.expr_call_ident(sp,
453-
id_ext("LIT_INT"),
454-
vec!(e_i64, e_ity));
457+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_INT"), vec!(e_i64, e_ity));
455458
}
456459

457460
LIT_UINT(u, uty) => {
458461
let s_uty = match uty {
459-
ast::TyU => "TyU".to_string(),
460-
ast::TyU8 => "TyU8".to_string(),
461-
ast::TyU16 => "TyU16".to_string(),
462-
ast::TyU32 => "TyU32".to_string(),
463-
ast::TyU64 => "TyU64".to_string()
462+
ast::TyU => "TyU",
463+
ast::TyU8 => "TyU8",
464+
ast::TyU16 => "TyU16",
465+
ast::TyU32 => "TyU32",
466+
ast::TyU64 => "TyU64"
464467
};
465-
let e_uty = cx.expr_ident(sp, id_ext(s_uty.as_slice()));
466-
468+
let e_uty = mk_ast_path(cx, sp, s_uty);
467469
let e_u64 = cx.expr_lit(sp, ast::LitUint(u, ast::TyU64));
468-
469-
return cx.expr_call_ident(sp,
470-
id_ext("LIT_UINT"),
471-
vec!(e_u64, e_uty));
470+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_UINT"), vec!(e_u64, e_uty));
472471
}
473472

474473
LIT_INT_UNSUFFIXED(i) => {
475474
let e_i64 = cx.expr_lit(sp, ast::LitInt(i, ast::TyI64));
476-
477-
return cx.expr_call_ident(sp,
478-
id_ext("LIT_INT_UNSUFFIXED"),
479-
vec!(e_i64));
475+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_INT_UNSUFFIXED"), vec!(e_i64));
480476
}
481477

482478
LIT_FLOAT(fident, fty) => {
483479
let s_fty = match fty {
484-
ast::TyF32 => "TyF32".to_string(),
485-
ast::TyF64 => "TyF64".to_string(),
486-
ast::TyF128 => "TyF128".to_string()
480+
ast::TyF32 => "TyF32",
481+
ast::TyF64 => "TyF64",
482+
ast::TyF128 => "TyF128"
487483
};
488-
let e_fty = cx.expr_ident(sp, id_ext(s_fty.as_slice()));
489-
484+
let e_fty = mk_ast_path(cx, sp, s_fty);
490485
let e_fident = mk_ident(cx, sp, fident);
491-
492-
return cx.expr_call_ident(sp,
493-
id_ext("LIT_FLOAT"),
494-
vec!(e_fident, e_fty));
486+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_FLOAT"), vec!(e_fident, e_fty));
495487
}
496488

497489
LIT_STR(ident) => {
498-
return cx.expr_call_ident(sp,
499-
id_ext("LIT_STR"),
500-
vec!(mk_ident(cx, sp, ident)));
490+
return cx.expr_call(sp,
491+
mk_token_path(cx, sp, "LIT_STR"),
492+
vec!(mk_ident(cx, sp, ident)));
501493
}
502494

503495
LIT_STR_RAW(ident, n) => {
504-
return cx.expr_call_ident(sp,
505-
id_ext("LIT_STR_RAW"),
506-
vec!(mk_ident(cx, sp, ident),
507-
cx.expr_uint(sp, n)));
496+
return cx.expr_call(sp,
497+
mk_token_path(cx, sp, "LIT_STR_RAW"),
498+
vec!(mk_ident(cx, sp, ident), cx.expr_uint(sp, n)));
508499
}
509500

510501
IDENT(ident, b) => {
511-
return cx.expr_call_ident(sp,
512-
id_ext("IDENT"),
513-
vec!(mk_ident(cx, sp, ident),
514-
cx.expr_bool(sp, b)));
502+
return cx.expr_call(sp,
503+
mk_token_path(cx, sp, "IDENT"),
504+
vec!(mk_ident(cx, sp, ident), cx.expr_bool(sp, b)));
515505
}
516506

517507
LIFETIME(ident) => {
518-
return cx.expr_call_ident(sp,
519-
id_ext("LIFETIME"),
520-
vec!(mk_ident(cx, sp, ident)));
508+
return cx.expr_call(sp,
509+
mk_token_path(cx, sp, "LIFETIME"),
510+
vec!(mk_ident(cx, sp, ident)));
521511
}
522512

523513
DOC_COMMENT(ident) => {
524-
return cx.expr_call_ident(sp,
525-
id_ext("DOC_COMMENT"),
526-
vec!(mk_ident(cx, sp, ident)));
514+
return cx.expr_call(sp,
515+
mk_token_path(cx, sp, "DOC_COMMENT"),
516+
vec!(mk_ident(cx, sp, ident)));
527517
}
528518

529519
INTERPOLATED(_) => fail!("quote! with interpolated token"),
@@ -565,19 +555,16 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
565555
EOF => "EOF",
566556
_ => fail!()
567557
};
568-
cx.expr_ident(sp, id_ext(name))
558+
mk_token_path(cx, sp, name)
569559
}
570560

571-
572561
fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> Vec<@ast::Stmt> {
573-
574562
match *tt {
575-
576563
ast::TTTok(sp, ref tok) => {
577564
let e_sp = cx.expr_ident(sp, id_ext("_sp"));
578-
let e_tok = cx.expr_call_ident(sp,
579-
id_ext("TTTok"),
580-
vec!(e_sp, mk_token(cx, sp, tok)));
565+
let e_tok = cx.expr_call(sp,
566+
mk_ast_path(cx, sp, "TTTok"),
567+
vec!(e_sp, mk_token(cx, sp, tok)));
581568
let e_push =
582569
cx.expr_method_call(sp,
583570
cx.expr_ident(sp, id_ext("tt")),
@@ -695,8 +682,6 @@ fn expand_wrapper(cx: &ExtCtxt,
695682
cx_expr: @ast::Expr,
696683
expr: @ast::Expr) -> @ast::Expr {
697684
let uses = [
698-
&["syntax", "ast"],
699-
&["syntax", "parse", "token"],
700685
&["syntax", "ext", "quote", "rt"],
701686
].iter().map(|path| {
702687
let path = path.iter().map(|s| s.to_string()).collect();

0 commit comments

Comments
 (0)