about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-15 01:05:03 +0000
committerbors <bors@rust-lang.org>2015-04-15 01:05:03 +0000
commit16e1fcead14628701e1b10b9d00c898d748db2ed (patch)
tree37d18d85fa9631880c287c3795d5b4b3d8994f20 /src/libsyntax
parent8415fa27877a4309a79b08c75a52eb4c3546b7a5 (diff)
parente053571df21fda7bb909c1b79de9b0cbe1a2931d (diff)
downloadrust-16e1fcead14628701e1b10b9d00c898d748db2ed.tar.gz
rust-16e1fcead14628701e1b10b9d00c898d748db2ed.zip
Auto merge of #24433 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_map/blocks.rs29
-rw-r--r--src/libsyntax/ast_util.rs4
-rw-r--r--src/libsyntax/ext/deriving/mod.rs3
-rw-r--r--src/libsyntax/ext/deriving/rand.rs175
-rw-r--r--src/libsyntax/feature_gate.rs6
-rw-r--r--src/libsyntax/lib.rs1
-rw-r--r--src/libsyntax/parse/parser.rs2
-rw-r--r--src/libsyntax/parse/token.rs16
-rw-r--r--src/libsyntax/print/pprust.rs4
-rw-r--r--src/libsyntax/visit.rs14
10 files changed, 35 insertions, 219 deletions
diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs
index 475970ac30a..1505d1e91b8 100644
--- a/src/libsyntax/ast_map/blocks.rs
+++ b/src/libsyntax/ast_map/blocks.rs
@@ -121,6 +121,7 @@ struct ItemFnParts<'a> {
     decl:     &'a ast::FnDecl,
     unsafety: ast::Unsafety,
     abi:      abi::Abi,
+    vis:      ast::Visibility,
     generics: &'a ast::Generics,
     body:     &'a Block,
     id:       ast::NodeId,
@@ -155,44 +156,50 @@ impl<'a> FnLikeNode<'a> {
 
     pub fn body(self) -> &'a Block {
         self.handle(|i: ItemFnParts<'a>|  &*i.body,
-                    |_, _, _: &'a ast::MethodSig, body: &'a ast::Block, _|  body,
+                    |_, _, _: &'a ast::MethodSig, _, body: &'a ast::Block, _|  body,
                     |c: ClosureParts<'a>| c.body)
     }
 
     pub fn decl(self) -> &'a FnDecl {
         self.handle(|i: ItemFnParts<'a>|  &*i.decl,
-                    |_, _, sig: &'a ast::MethodSig, _, _|  &sig.decl,
+                    |_, _, sig: &'a ast::MethodSig, _, _, _|  &sig.decl,
                     |c: ClosureParts<'a>| c.decl)
     }
 
     pub fn span(self) -> Span {
         self.handle(|i: ItemFnParts|     i.span,
-                    |_, _, _: &'a ast::MethodSig, _, span| span,
+                    |_, _, _: &'a ast::MethodSig, _, _, span| span,
                     |c: ClosureParts|    c.span)
     }
 
     pub fn id(self) -> NodeId {
         self.handle(|i: ItemFnParts|     i.id,
-                    |id, _, _: &'a ast::MethodSig, _, _| id,
+                    |id, _, _: &'a ast::MethodSig, _, _, _| id,
                     |c: ClosureParts|    c.id)
     }
 
     pub fn kind(self) -> visit::FnKind<'a> {
         let item = |p: ItemFnParts<'a>| -> visit::FnKind<'a> {
-            visit::FkItemFn(p.ident, p.generics, p.unsafety, p.abi)
+            visit::FkItemFn(p.ident, p.generics, p.unsafety, p.abi, p.vis)
         };
         let closure = |_: ClosureParts| {
             visit::FkFnBlock
         };
-        let method = |_, ident, sig: &'a ast::MethodSig, _, _| {
-            visit::FkMethod(ident, sig)
+        let method = |_, ident, sig: &'a ast::MethodSig, vis, _, _| {
+            visit::FkMethod(ident, sig, vis)
         };
         self.handle(item, method, closure)
     }
 
     fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
         I: FnOnce(ItemFnParts<'a>) -> A,
-        M: FnOnce(NodeId, ast::Ident, &'a ast::MethodSig, &'a ast::Block, Span) -> A,
+        M: FnOnce(NodeId,
+                  ast::Ident,
+                  &'a ast::MethodSig,
+                  Option<ast::Visibility>,
+                  &'a ast::Block,
+                  Span)
+                  -> A,
         C: FnOnce(ClosureParts<'a>) -> A,
     {
         match self.node {
@@ -200,20 +207,20 @@ impl<'a> FnLikeNode<'a> {
                 ast::ItemFn(ref decl, unsafety, abi, ref generics, ref block) =>
                     item_fn(ItemFnParts{
                         ident: i.ident, decl: &**decl, unsafety: unsafety, body: &**block,
-                        generics: generics, abi: abi, id: i.id, span: i.span
+                        generics: generics, abi: abi, vis: i.vis, id: i.id, span: i.span
                     }),
                 _ => panic!("item FnLikeNode that is not fn-like"),
             },
             ast_map::NodeTraitItem(ti) => match ti.node {
                 ast::MethodTraitItem(ref sig, Some(ref body)) => {
-                    method(ti.id, ti.ident, sig, body, ti.span)
+                    method(ti.id, ti.ident, sig, None, body, ti.span)
                 }
                 _ => panic!("trait method FnLikeNode that is not fn-like"),
             },
             ast_map::NodeImplItem(ii) => {
                 match ii.node {
                     ast::MethodImplItem(ref sig, ref body) => {
-                        method(ii.id, ii.ident, sig, body, ii.span)
+                        method(ii.id, ii.ident, sig, Some(ii.vis), body, ii.span)
                     }
                     ast::TypeImplItem(_) |
                     ast::MacImplItem(_) => {
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index c4c2249d029..0ad75c5ec8c 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -440,10 +440,10 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
         self.operation.visit_id(node_id);
 
         match function_kind {
-            visit::FkItemFn(_, generics, _, _) => {
+            visit::FkItemFn(_, generics, _, _, _) => {
                 self.visit_generics_helper(generics)
             }
-            visit::FkMethod(_, sig) => {
+            visit::FkMethod(_, sig, _) => {
                 self.visit_generics_helper(&sig.generics)
             }
             visit::FkFnBlock => {}
diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs
index d8c50b5a094..65554efdd68 100644
--- a/src/libsyntax/ext/deriving/mod.rs
+++ b/src/libsyntax/ext/deriving/mod.rs
@@ -61,7 +61,6 @@ pub mod clone;
 pub mod encodable;
 pub mod decodable;
 pub mod hash;
-pub mod rand;
 pub mod show;
 pub mod default;
 pub mod primitive;
@@ -168,8 +167,6 @@ derive_traits! {
     "PartialOrd" => ord::expand_deriving_ord,
     "Ord" => totalord::expand_deriving_totalord,
 
-    "Rand" => rand::expand_deriving_rand,
-
     "Debug" => show::expand_deriving_show,
 
     "Default" => default::expand_deriving_default,
diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs
deleted file mode 100644
index 631e5f979d9..00000000000
--- a/src/libsyntax/ext/deriving/rand.rs
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright 2012-2013 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.
-
-use ast;
-use ast::{MetaItem, Item, Expr};
-use codemap::Span;
-use ext::base::ExtCtxt;
-use ext::build::AstBuilder;
-use ext::deriving::generic::*;
-use ext::deriving::generic::ty::*;
-use ptr::P;
-
-pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
-                               span: Span,
-                               mitem: &MetaItem,
-                               item: &Item,
-                               push: F) where
-    F: FnOnce(P<Item>),
-{
-    cx.span_warn(span,
-                 "`#[derive(Rand)]` is deprecated in favour of `#[derive_Rand]` from \
-                  `rand_macros` on crates.io");
-
-    if !cx.use_std {
-        // FIXME(#21880): lift this requirement.
-        cx.span_err(span, "this trait cannot be derived with #![no_std]");
-        return;
-    }
-
-    let trait_def = TraitDef {
-        span: span,
-        attributes: Vec::new(),
-        path: path!(std::rand::Rand),
-        additional_bounds: Vec::new(),
-        generics: LifetimeBounds::empty(),
-        methods: vec!(
-            MethodDef {
-                name: "rand",
-                generics: LifetimeBounds {
-                    lifetimes: Vec::new(),
-                    bounds: vec!(("R",
-                                  vec!( path!(std::rand::Rng) ))),
-                },
-                explicit_self: None,
-                args: vec!(
-                    Ptr(box Literal(Path::new_local("R")),
-                        Borrowed(None, ast::MutMutable))
-                ),
-                ret_ty: Self_,
-                attributes: Vec::new(),
-                combine_substructure: combine_substructure(Box::new(|a, b, c| {
-                    rand_substructure(a, b, c)
-                }))
-            }
-        ),
-        associated_types: Vec::new(),
-    };
-    trait_def.expand(cx, mitem, item, push)
-}
-
-fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
-    let rng = match substr.nonself_args {
-        [ref rng] => rng,
-        _ => cx.bug("Incorrect number of arguments to `rand` in `derive(Rand)`")
-    };
-    let rand_ident = vec!(
-        cx.ident_of("std"),
-        cx.ident_of("rand"),
-        cx.ident_of("Rand"),
-        cx.ident_of("rand")
-    );
-    let rand_call = |cx: &mut ExtCtxt, span| {
-        cx.expr_call_global(span,
-                            rand_ident.clone(),
-                            vec!(rng.clone()))
-    };
-
-    return match *substr.fields {
-        StaticStruct(_, ref summary) => {
-            let path = cx.path_ident(trait_span, substr.type_ident);
-            rand_thing(cx, trait_span, path, summary, rand_call)
-        }
-        StaticEnum(_, ref variants) => {
-            if variants.is_empty() {
-                cx.span_err(trait_span, "`Rand` cannot be derived for enums with no variants");
-                // let compilation continue
-                return cx.expr_usize(trait_span, 0);
-            }
-
-            let variant_count = cx.expr_usize(trait_span, variants.len());
-
-            let rand_name = cx.path_all(trait_span,
-                                        true,
-                                        rand_ident.clone(),
-                                        Vec::new(),
-                                        Vec::new(),
-                                        Vec::new());
-            let rand_name = cx.expr_path(rand_name);
-
-            // ::rand::Rand::rand(rng)
-            let rv_call = cx.expr_call(trait_span,
-                                       rand_name,
-                                       vec!(rng.clone()));
-
-            // need to specify the usize-ness of the random number
-            let usize_ty = cx.ty_ident(trait_span, cx.ident_of("usize"));
-            let value_ident = cx.ident_of("__value");
-            let let_statement = cx.stmt_let_typed(trait_span,
-                                                  false,
-                                                  value_ident,
-                                                  usize_ty,
-                                                  rv_call);
-
-            // rand() % variants.len()
-            let value_ref = cx.expr_ident(trait_span, value_ident);
-            let rand_variant = cx.expr_binary(trait_span,
-                                              ast::BiRem,
-                                              value_ref,
-                                              variant_count);
-
-            let mut arms = variants.iter().enumerate().map(|(i, &(ident, v_span, ref summary))| {
-                let i_expr = cx.expr_usize(v_span, i);
-                let pat = cx.pat_lit(v_span, i_expr);
-
-                let path = cx.path(v_span, vec![substr.type_ident, ident]);
-                let thing = rand_thing(cx, v_span, path, summary, |cx, sp| rand_call(cx, sp));
-                cx.arm(v_span, vec!( pat ), thing)
-            }).collect::<Vec<ast::Arm> >();
-
-            // _ => {} at the end. Should never occur
-            arms.push(cx.arm_unreachable(trait_span));
-
-            let match_expr = cx.expr_match(trait_span, rand_variant, arms);
-
-            let block = cx.block(trait_span, vec!( let_statement ), Some(match_expr));
-            cx.expr_block(block)
-        }
-        _ => cx.bug("Non-static method in `derive(Rand)`")
-    };
-
-    fn rand_thing<F>(cx: &mut ExtCtxt,
-                     trait_span: Span,
-                     ctor_path: ast::Path,
-                     summary: &StaticFields,
-                     mut rand_call: F)
-                     -> P<Expr> where
-        F: FnMut(&mut ExtCtxt, Span) -> P<Expr>,
-    {
-        let path = cx.expr_path(ctor_path.clone());
-        match *summary {
-            Unnamed(ref fields) => {
-                if fields.is_empty() {
-                    path
-                } else {
-                    let exprs = fields.iter().map(|span| rand_call(cx, *span)).collect();
-                    cx.expr_call(trait_span, path, exprs)
-                }
-            }
-            Named(ref fields) => {
-                let rand_fields = fields.iter().map(|&(ident, span)| {
-                    let e = rand_call(cx, span);
-                    cx.field_imm(span, ident, e)
-                }).collect();
-                cx.expr_struct(trait_span, ctor_path, rand_fields)
-            }
-        }
-    }
-}
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 689b4595d39..a6f8a718b33 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -644,13 +644,13 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
                 span: Span,
                 _node_id: NodeId) {
         match fn_kind {
-            visit::FkItemFn(_, _, _, abi) if abi == Abi::RustIntrinsic => {
+            visit::FkItemFn(_, _, _, abi, _) if abi == Abi::RustIntrinsic => {
                 self.gate_feature("intrinsics",
                                   span,
                                   "intrinsics are subject to change")
             }
-            visit::FkItemFn(_, _, _, abi) |
-            visit::FkMethod(_, &ast::MethodSig { abi, .. }) if abi == Abi::RustCall => {
+            visit::FkItemFn(_, _, _, abi, _) |
+            visit::FkMethod(_, &ast::MethodSig { abi, .. }, _) if abi == Abi::RustCall => {
                 self.gate_feature("unboxed_closures",
                                   span,
                                   "rust-call ABI is subject to change")
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index bf95daf8755..3f36d0e8eda 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -30,7 +30,6 @@
 #![feature(collections)]
 #![feature(core)]
 #![feature(libc)]
-#![feature(old_path)]
 #![feature(quote, unsafe_destructor)]
 #![feature(rustc_private)]
 #![feature(staged_api)]
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a3dd77b8197..e45b7c1df91 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -3855,7 +3855,7 @@ impl<'a> Parser<'a> {
     /// ```
     /// where T : Trait<U, V> + 'b, 'a : 'b
     /// ```
-    fn parse_where_clause(&mut self) -> PResult<ast::WhereClause> {
+    pub fn parse_where_clause(&mut self) -> PResult<ast::WhereClause> {
         let mut where_clause = WhereClause {
             id: ast::DUMMY_NODE_ID,
             predicates: Vec::new(),
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 4db85eeea46..2bb74944ce9 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -23,10 +23,7 @@ use util::interner;
 
 use serialize::{Decodable, Decoder, Encodable, Encoder};
 use std::fmt;
-use std::mem;
 use std::ops::Deref;
-#[allow(deprecated)]
-use std::old_path::BytesContainer;
 use std::rc::Rc;
 
 #[allow(non_camel_case_types)]
@@ -639,19 +636,6 @@ impl Deref for InternedString {
     fn deref(&self) -> &str { &*self.string }
 }
 
-#[allow(deprecated)]
-impl BytesContainer for InternedString {
-    fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
-        // FIXME #12938: This is a workaround for the incorrect signature
-        // of `BytesContainer`, which is itself a workaround for the lack of
-        // DST.
-        unsafe {
-            let this = &self[..];
-            mem::transmute::<&[u8],&[u8]>(this.container_as_bytes())
-        }
-    }
-}
-
 impl fmt::Debug for InternedString {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         fmt::Debug::fmt(&self.string, f)
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 46d196d13fa..3f883fb1172 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -352,6 +352,10 @@ pub fn stmt_to_string(stmt: &ast::Stmt) -> String {
     $to_string(|s| s.print_stmt(stmt))
 }
 
+pub fn attr_to_string(attr: &ast::Attribute) -> String {
+    $to_string(|s| s.print_attribute(attr))
+}
+
 pub fn item_to_string(i: &ast::Item) -> String {
     $to_string(|s| s.print_item(i))
 }
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index 5c345c75642..4c70fc9f81f 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -35,10 +35,10 @@ use owned_slice::OwnedSlice;
 #[derive(Copy, Clone)]
 pub enum FnKind<'a> {
     /// fn foo() or extern "Abi" fn foo()
-    FkItemFn(Ident, &'a Generics, Unsafety, Abi),
+    FkItemFn(Ident, &'a Generics, Unsafety, Abi, Visibility),
 
     /// fn foo(&self)
-    FkMethod(Ident, &'a MethodSig),
+    FkMethod(Ident, &'a MethodSig, Option<Visibility>),
 
     /// |x, y| ...
     /// proc(x, y) ...
@@ -247,7 +247,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
             visitor.visit_expr(&**expr);
         }
         ItemFn(ref declaration, fn_style, abi, ref generics, ref body) => {
-            visitor.visit_fn(FkItemFn(item.ident, generics, fn_style, abi),
+            visitor.visit_fn(FkItemFn(item.ident, generics, fn_style, abi, item.vis),
                              &**declaration,
                              &**body,
                              item.span,
@@ -600,10 +600,10 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
     walk_fn_decl(visitor, function_declaration);
 
     match function_kind {
-        FkItemFn(_, generics, _, _) => {
+        FkItemFn(_, generics, _, _, _) => {
             visitor.visit_generics(generics);
         }
-        FkMethod(_, sig) => {
+        FkMethod(_, sig, _) => {
             visitor.visit_generics(&sig.generics);
             visitor.visit_explicit_self(&sig.explicit_self);
         }
@@ -625,7 +625,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
             walk_fn_decl(visitor, &sig.decl);
         }
         MethodTraitItem(ref sig, Some(ref body)) => {
-            visitor.visit_fn(FkMethod(trait_item.ident, sig), &sig.decl,
+            visitor.visit_fn(FkMethod(trait_item.ident, sig, None), &sig.decl,
                              body, trait_item.span, trait_item.id);
         }
         TypeTraitItem(ref bounds, ref default) => {
@@ -642,7 +642,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
     }
     match impl_item.node {
         MethodImplItem(ref sig, ref body) => {
-            visitor.visit_fn(FkMethod(impl_item.ident, sig), &sig.decl,
+            visitor.visit_fn(FkMethod(impl_item.ident, sig, Some(impl_item.vis)), &sig.decl,
                              body, impl_item.span, impl_item.id);
         }
         TypeImplItem(ref ty) => {