~~~~
# fn main() { }
mod quux {
- pub use quux::foo::*;
+ pub use quux::foo::{bar, baz};
pub mod foo {
pub fn bar() { }
}
~~~~
-In this example, the module `quux` re-exports all of the public names defined in `foo`.
+In this example, the module `quux` re-exports two public names defined in `foo`.
Also note that the paths contained in `use` items are relative to the crate root.
-So, in the previous example, the `use` refers to `quux::foo::*`, and not simply to `foo::*`.
+So, in the previous example, the `use` refers to `quux::foo::{bar, baz}`, and not simply to `foo::{bar, baz}`.
This also means that top-level module declarations should be at the crate root if direct usage
of the declared modules within `use` items is desired. It is also possible to use `self` and `super`
at the beginning of a `use` item to refer to the current and direct parent modules respectively.
html_root_url = "http://doc.rust-lang.org/")]
#![feature(macro_registrar, managed_boxes, quote)]
+#![allow(unused_imports)] // `quote_expr!` adds some `use` globs which may be unused
extern crate regex;
extern crate syntax;
slice::raw::buf_as_slice((*lang).data,
(*lang).size as uint, |lang| {
let s = str::from_utf8(lang).unwrap();
- (s.contains("should_fail"),
- s.contains("no_run"),
- s.contains("ignore"),
- s.contains("notrust"))
+ parse_lang_string(s)
})
};
if notrust { return }
}
}
+fn parse_lang_string(string: &str) -> (bool,bool,bool,bool) {
+ let mut seen_rust_tags = false;
+ let mut seen_other_tags = false;
+ let mut should_fail = false;
+ let mut no_run = false;
+ let mut ignore = false;
+ let mut notrust = false;
+
+ let mut tokens = string.as_slice().split(|c: char|
+ !(c == '_' || c == '-' || c.is_alphanumeric())
+ );
+
+ for token in tokens {
+ match token {
+ "" => {},
+ "should_fail" => { should_fail = true; seen_rust_tags = true; },
+ "no_run" => { no_run = true; seen_rust_tags = true; },
+ "ignore" => { ignore = true; seen_rust_tags = true; },
+ "notrust" => { notrust = true; seen_rust_tags = true; },
+ "rust" => { notrust = false; seen_rust_tags = true; },
+ _ => { seen_other_tags = true }
+ }
+ }
+
+ let notrust = notrust || (seen_other_tags && !seen_rust_tags);
+
+ (should_fail, no_run, ignore, notrust)
+}
+
/// By default this markdown renderer generates anchors for each header in the
/// rendered document. The anchor name is the contents of the header spearated
/// by hyphens, and a task-local map is used to disambiguate among duplicate
render(fmt, md.as_slice(), true)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::parse_lang_string;
+
+ #[test]
+ fn test_parse_lang_string() {
+ assert_eq!(parse_lang_string(""), (false,false,false,false))
+ assert_eq!(parse_lang_string("rust"), (false,false,false,false))
+ assert_eq!(parse_lang_string("sh"), (false,false,false,true))
+ assert_eq!(parse_lang_string("notrust"), (false,false,false,true))
+ assert_eq!(parse_lang_string("ignore"), (false,false,true,false))
+ assert_eq!(parse_lang_string("should_fail"), (true,false,false,false))
+ assert_eq!(parse_lang_string("no_run"), (false,true,false,false))
+ assert_eq!(parse_lang_string("{.no_run .example}"), (false,true,false,false))
+ assert_eq!(parse_lang_string("{.sh .should_fail}"), (true,false,false,false))
+ assert_eq!(parse_lang_string("{.example .rust}"), (false,false,false,false))
+ }
+}
\ No newline at end of file
// except according to those terms.
use abi;
-use ast::{P, Ident};
+use ast::{P, Ident, Generics, NodeId, Expr};
use ast;
use ast_util;
use attr;
use codemap::{Span, respan, Spanned, DUMMY_SP};
use ext::base::ExtCtxt;
-use ext::quote::rt::*;
use fold::Folder;
use owned_slice::OwnedSlice;
use parse::token::special_idents;
+use parse::token::InternedString;
use parse::token;
pub struct Field {
use codemap::Span;
use ext::base::ExtCtxt;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
pub fn expand_deriving_bound(cx: &mut ExtCtxt,
span: Span,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_clone(cx: &mut ExtCtxt,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_eq(cx: &mut ExtCtxt,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_ord(cx: &mut ExtCtxt,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
use std::cmp::{Ordering, Equal, Less, Greater};
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
use parse::token;
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_default(cx: &mut ExtCtxt,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token;
pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
stmts.push(cx.stmt_expr(call));
}
+ // unit structs have no fields and need to return Ok()
+ if stmts.is_empty() {
+ let ret_ok = cx.expr(trait_span,
+ ExprRet(Some(cx.expr_ok(trait_span,
+ cx.expr_lit(trait_span, LitNil)))));
+ stmts.push(cx.stmt_expr(ret_ok));
+ }
+
let blk = cx.lambda_stmts_1(trait_span, stmts, blkarg);
cx.expr_method_call(trait_span,
encoder,
use owned_slice::OwnedSlice;
use parse::token::InternedString;
-pub use self::ty::*;
-mod ty;
+use self::ty::*;
+
+pub mod ty;
pub struct TraitDef<'a> {
/// The span for the current #[deriving(Foo)] header.
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_hash(cx: &mut ExtCtxt,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
use ext::base::ExtCtxt;
use ext::build::{AstBuilder};
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
pub fn expand_deriving_rand(cx: &mut ExtCtxt,
span: Span,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token;
use collections::HashMap;
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+use ext::deriving::generic::ty::*;
use parse::token::InternedString;
pub fn expand_deriving_zero(cx: &mut ExtCtxt,
use parse;
use print::pprust;
- pub use ast::*;
- pub use parse::token::*;
+ #[cfg(not(stage0))]
+ use ast::{TokenTree, Generics, Expr};
+
+ // NOTE remove this after snapshot
+ // (stage0 quasiquoter needs this)
+ #[cfg(stage0)]
+ pub use ast::{Generics, TokenTree, TTTok};
+ #[cfg(stage0)]
+ pub use parse::token::{IDENT, SEMI, LBRACE, RBRACE, LIFETIME, COLON, AND, BINOP, EQ,
+ LBRACKET, RBRACKET, LPAREN, RPAREN, POUND, NOT, MOD_SEP, DOT, COMMA};
+
pub use parse::new_parser_from_tts;
pub use codemap::{BytePos, Span, dummy_spanned};
impl ToSource for ast::Ident {
fn to_source(&self) -> String {
- get_ident(*self).get().to_string()
+ token::get_ident(*self).get().to_string()
}
}
sp: Span,
cx_expr: @ast::Expr,
expr: @ast::Expr) -> @ast::Expr {
- let uses = vec![ cx.view_use_glob(sp, ast::Inherited,
- ids_ext(vec!["syntax".to_string(),
- "ext".to_string(),
- "quote".to_string(),
- "rt".to_string()])) ];
+ let uses = [
+ &["syntax", "ast"],
+ &["syntax", "parse", "token"],
+ &["syntax", "ext", "quote", "rt"],
+ ].iter().map(|path| {
+ let path = path.iter().map(|s| s.to_string()).collect();
+ cx.view_use_glob(sp, ast::Inherited, ids_ext(path))
+ }).collect();
let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr);
pub mod syntax {
pub use ext;
pub use parse;
+ pub use ast;
}
pub mod owned_slice;
// Test a foreign function that accepts and returns a struct
// by value.
-// ignore-win32 #9205
-
#[deriving(PartialEq, Show)]
struct TwoU64s {
one: u64, two: u64
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-win32 #9205
-
struct TwoU64s {
one: u64, two: u64
}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+extern crate serialize;
+
+use serialize::{Encodable, Decodable};
+use serialize::json;
+
+#[deriving(Encodable, Decodable, PartialEq, Show)]
+struct UnitLikeStruct;
+
+pub fn main() {
+ let obj = UnitLikeStruct;
+ let json_str: String = json::Encoder::str_encode(&obj);
+
+ let json_object = json::from_str(json_str.as_slice());
+ let mut decoder = json::Decoder::new(json_object.unwrap());
+ let mut decoded_obj: UnitLikeStruct = Decodable::decode(&mut decoder).unwrap();
+
+ assert_eq!(obj, decoded_obj);
+}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-win32 #9205
-
pub struct Quad { a: u64, b: u64, c: u64, d: u64 }
pub struct Floats { a: f64, b: u8, c: f64 }