about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-04 08:11:53 +0000
committerbors <bors@rust-lang.org>2014-11-04 08:11:53 +0000
commit82fb413d370f1f1094964ed07b65f97dba52cc30 (patch)
tree4a282dbec3c595c1b9937566237cf79a851efba4 /src/libsyntax
parentec28b4a6c8c0a249fe341afde55d026177aabac6 (diff)
parentf2aa8c41876cce93c6bb4ada79600b8ef8e3d599 (diff)
downloadrust-82fb413d370f1f1094964ed07b65f97dba52cc30.tar.gz
rust-82fb413d370f1f1094964ed07b65f97dba52cc30.zip
auto merge of #18596 : alexcrichton/rust/rollup, r=alexcrichton
Let's see if we can clear out the queue entirely today!
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs8
-rw-r--r--src/libsyntax/ast_map/mod.rs14
-rw-r--r--src/libsyntax/ast_util.rs35
-rw-r--r--src/libsyntax/ext/deriving/clone.rs14
-rw-r--r--src/libsyntax/feature_gate.rs2
-rw-r--r--src/libsyntax/fold.rs11
-rw-r--r--src/libsyntax/parse/lexer/mod.rs13
-rw-r--r--src/libsyntax/parse/parser.rs31
-rw-r--r--src/libsyntax/parse/token.rs4
-rw-r--r--src/libsyntax/print/pprust.rs57
-rw-r--r--src/libsyntax/visit.rs3
11 files changed, 97 insertions, 95 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index a2c859cf9fd..18fc970c218 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -119,7 +119,7 @@ impl Name {
     pub fn as_str<'a>(&'a self) -> &'a str {
         unsafe {
             // FIXME #12938: can't use copy_lifetime since &str isn't a &T
-            ::std::mem::transmute(token::get_name(*self).get())
+            ::std::mem::transmute::<&str,&str>(token::get_name(*self).get())
         }
     }
 
@@ -385,7 +385,7 @@ pub enum Pat_ {
     PatLit(P<Expr>),
     PatRange(P<Expr>, P<Expr>),
     /// [a, b, ..i, y, z] is represented as:
-    ///     PatVec(~[a, b], Some(i), ~[y, z])
+    ///     PatVec(box [a, b], Some(i), box [y, z])
     PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
     PatMac(Mac),
 }
@@ -861,10 +861,8 @@ pub enum ImplItem {
 
 #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
 pub struct AssociatedType {
-    pub id: NodeId,
-    pub span: Span,
-    pub ident: Ident,
     pub attrs: Vec<Attribute>,
+    pub ty_param: TyParam,
 }
 
 #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs
index fa36577ebdb..f049b964ff3 100644
--- a/src/libsyntax/ast_map/mod.rs
+++ b/src/libsyntax/ast_map/mod.rs
@@ -405,7 +405,9 @@ impl<'ast> Map<'ast> {
                         MethMac(_) => panic!("no path elem for {}", node),
                     }
                 }
-                TypeTraitItem(ref m) => PathName(m.ident.name),
+                TypeTraitItem(ref m) => {
+                    PathName(m.ty_param.ident.name)
+                }
             },
             NodeVariant(v) => PathName(v.node.name.name),
             _ => panic!("no path elem for {}", node)
@@ -510,7 +512,7 @@ impl<'ast> Map<'ast> {
                 match *trait_method {
                     RequiredMethod(ref type_method) => type_method.span,
                     ProvidedMethod(ref method) => method.span,
-                    TypeTraitItem(ref typedef) => typedef.span,
+                    TypeTraitItem(ref typedef) => typedef.ty_param.span,
                 }
             }
             Some(NodeImplItem(ref impl_item)) => {
@@ -650,7 +652,7 @@ impl Named for TraitItem {
         match *self {
             RequiredMethod(ref tm) => tm.ident.name,
             ProvidedMethod(ref m) => m.name(),
-            TypeTraitItem(ref at) => at.ident.name,
+            TypeTraitItem(ref at) => at.ty_param.ident.name,
         }
     }
 }
@@ -783,7 +785,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
                             self.insert(m.id, NodeTraitItem(tm));
                         }
                         TypeTraitItem(ref typ) => {
-                            self.insert(typ.id, NodeTraitItem(tm));
+                            self.insert(typ.ty_param.id, NodeTraitItem(tm));
                         }
                     }
                 }
@@ -976,7 +978,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
             let trait_item_id = match *trait_item {
                 ProvidedMethod(ref m) => m.id,
                 RequiredMethod(ref m) => m.id,
-                TypeTraitItem(ref ty) => ty.id,
+                TypeTraitItem(ref ty) => ty.ty_param.id,
             };
 
             collector.insert(trait_item_id, NodeTraitItem(trait_item));
@@ -1080,7 +1082,7 @@ fn node_id_to_string(map: &Map, id: NodeId) -> String {
                 }
                 TypeTraitItem(ref t) => {
                     format!("type item {} in {} (id={})",
-                            token::get_ident(t.ident),
+                            token::get_ident(t.ty_param.ident),
                             map.path_to_string(id),
                             id)
                 }
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 8b0e1f32fd4..3aa60236d70 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -21,7 +21,6 @@ use ptr::P;
 use visit::Visitor;
 use visit;
 
-use std::cell::Cell;
 use std::cmp;
 use std::u32;
 
@@ -333,20 +332,20 @@ impl IdRange {
 }
 
 pub trait IdVisitingOperation {
-    fn visit_id(&self, node_id: NodeId);
+    fn visit_id(&mut self, node_id: NodeId);
 }
 
 /// A visitor that applies its operation to all of the node IDs
 /// in a visitable thing.
 
 pub struct IdVisitor<'a, O:'a> {
-    pub operation: &'a O,
+    pub operation: &'a mut O,
     pub pass_through_items: bool,
     pub visited_outermost: bool,
 }
 
 impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> {
-    fn visit_generics_helper(&self, generics: &Generics) {
+    fn visit_generics_helper(&mut self, generics: &Generics) {
         for type_parameter in generics.ty_params.iter() {
             self.operation.visit_id(type_parameter.id)
         }
@@ -525,7 +524,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
         match *tm {
             ast::RequiredMethod(ref m) => self.operation.visit_id(m.id),
             ast::ProvidedMethod(ref m) => self.operation.visit_id(m.id),
-            ast::TypeTraitItem(ref typ) => self.operation.visit_id(typ.id),
+            ast::TypeTraitItem(ref typ) => self.operation.visit_id(typ.ty_param.id),
         }
         visit::walk_trait_item(self, tm);
     }
@@ -540,7 +539,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
 }
 
 pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem,
-                                                          operation: &O) {
+                                                          operation: &mut O) {
     let mut id_visitor = IdVisitor {
         operation: operation,
         pass_through_items: true,
@@ -551,23 +550,21 @@ pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem,
 }
 
 struct IdRangeComputingVisitor {
-    result: Cell<IdRange>,
+    result: IdRange,
 }
 
 impl IdVisitingOperation for IdRangeComputingVisitor {
-    fn visit_id(&self, id: NodeId) {
-        let mut id_range = self.result.get();
-        id_range.add(id);
-        self.result.set(id_range)
+    fn visit_id(&mut self, id: NodeId) {
+        self.result.add(id);
     }
 }
 
 pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange {
-    let visitor = IdRangeComputingVisitor {
-        result: Cell::new(IdRange::max())
+    let mut visitor = IdRangeComputingVisitor {
+        result: IdRange::max()
     };
-    visit_ids_for_inlined_item(item, &visitor);
-    visitor.result.get()
+    visit_ids_for_inlined_item(item, &mut visitor);
+    visitor.result
 }
 
 pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
@@ -582,16 +579,16 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
      * ignoring nested items.
      */
 
-    let visitor = IdRangeComputingVisitor {
-        result: Cell::new(IdRange::max())
+    let mut visitor = IdRangeComputingVisitor {
+        result: IdRange::max()
     };
     let mut id_visitor = IdVisitor {
-        operation: &visitor,
+        operation: &mut visitor,
         pass_through_items: false,
         visited_outermost: false,
     };
     id_visitor.visit_fn(fk, decl, body, sp, id);
-    visitor.result.get()
+    id_visitor.operation.result
 }
 
 pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs
index 9748b531345..e653c8aebf4 100644
--- a/src/libsyntax/ext/deriving/clone.rs
+++ b/src/libsyntax/ext/deriving/clone.rs
@@ -52,11 +52,19 @@ fn cs_clone(
     name: &str,
     cx: &mut ExtCtxt, trait_span: Span,
     substr: &Substructure) -> P<Expr> {
-    let clone_ident = substr.method_ident;
     let ctor_ident;
     let all_fields;
-    let subcall = |field: &FieldInfo|
-        cx.expr_method_call(field.span, field.self_.clone(), clone_ident, Vec::new());
+    let fn_path = vec![
+        cx.ident_of("std"),
+        cx.ident_of("clone"),
+        cx.ident_of("Clone"),
+        cx.ident_of("clone"),
+    ];
+    let subcall = |field: &FieldInfo| {
+        let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
+
+        cx.expr_call_global(field.span, fn_path.clone(), args)
+    };
 
     match *substr.fields {
         Struct(ref af) => {
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 330e4552e2f..7701f495f72 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -260,7 +260,7 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
             ast::RequiredMethod(_) | ast::ProvidedMethod(_) => {}
             ast::TypeTraitItem(ref ti) => {
                 self.gate_feature("associated_types",
-                                  ti.span,
+                                  ti.ty_param.span,
                                   "associated types are experimental")
             }
         }
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 9a55f07e98d..6535c8e89fd 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -793,19 +793,16 @@ pub fn noop_fold_typedef<T>(t: Typedef, folder: &mut T)
 
 pub fn noop_fold_associated_type<T>(at: AssociatedType, folder: &mut T)
                                     -> AssociatedType
-                                    where T: Folder {
-    let new_id = folder.new_id(at.id);
-    let new_span = folder.new_span(at.span);
-    let new_ident = folder.fold_ident(at.ident);
+                                    where T: Folder
+{
     let new_attrs = at.attrs
                       .iter()
                       .map(|attr| folder.fold_attribute((*attr).clone()))
                       .collect();
+    let new_param = folder.fold_ty_param(at.ty_param);
     ast::AssociatedType {
-        ident: new_ident,
         attrs: new_attrs,
-        id: new_id,
-        span: new_span,
+        ty_param: new_param,
     }
 }
 
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index 293b91111b5..1bc1d42d888 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -35,6 +35,19 @@ pub trait Reader {
     /// Report a non-fatal error with the current span.
     fn err(&self, &str);
     fn peek(&self) -> TokenAndSpan;
+    /// Get a token the parser cares about.
+    fn real_token(&mut self) -> TokenAndSpan {
+        let mut t = self.next_token();
+        loop {
+            match t.tok {
+                token::Whitespace | token::Comment | token::Shebang(_) => {
+                    t = self.next_token();
+                },
+                _ => break
+            }
+        }
+        t
+    }
 }
 
 #[deriving(Clone, PartialEq, Eq, Show)]
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 5e18c6bae48..8ad5bdac7e2 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -338,27 +338,13 @@ fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
     t.is_plain_ident() || *t == token::Underscore
 }
 
-/// Get a token the parser cares about
-fn real_token(rdr: &mut Reader) -> TokenAndSpan {
-    let mut t = rdr.next_token();
-    loop {
-        match t.tok {
-            token::Whitespace | token::Comment | token::Shebang(_) => {
-                t = rdr.next_token();
-            },
-            _ => break
-        }
-    }
-    t
-}
-
 impl<'a> Parser<'a> {
     pub fn new(sess: &'a ParseSess,
                cfg: ast::CrateConfig,
                mut rdr: Box<Reader+'a>)
                -> Parser<'a>
     {
-        let tok0 = real_token(&mut *rdr);
+        let tok0 = rdr.real_token();
         let span = tok0.sp;
         let placeholder = TokenAndSpan {
             tok: token::Underscore,
@@ -898,7 +884,7 @@ impl<'a> Parser<'a> {
             None
         };
         let next = if self.buffer_start == self.buffer_end {
-            real_token(&mut *self.reader)
+            self.reader.real_token()
         } else {
             // Avoid token copies with `replace`.
             let buffer_start = self.buffer_start as uint;
@@ -942,7 +928,7 @@ impl<'a> Parser<'a> {
                       -> R {
         let dist = distance as int;
         while self.buffer_length() < dist {
-            self.buffer[self.buffer_end as uint] = real_token(&mut *self.reader);
+            self.buffer[self.buffer_end as uint] = self.reader.real_token();
             self.buffer_end = (self.buffer_end + 1) & 3;
         }
         f(&self.buffer[((self.buffer_start + dist - 1) & 3) as uint].tok)
@@ -1229,16 +1215,13 @@ impl<'a> Parser<'a> {
     /// Parses `type Foo;` in a trait declaration only. The `type` keyword has
     /// already been parsed.
     fn parse_associated_type(&mut self, attrs: Vec<Attribute>)
-                             -> AssociatedType {
-        let lo = self.span.lo;
-        let ident = self.parse_ident();
-        let hi = self.span.hi;
+                             -> AssociatedType
+    {
+        let ty_param = self.parse_ty_param();
         self.expect(&token::Semi);
         AssociatedType {
-            id: ast::DUMMY_NODE_ID,
-            span: mk_sp(lo, hi),
-            ident: ident,
             attrs: attrs,
+            ty_param: ty_param,
         }
     }
 
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index d56aa8da72a..615cd34ca14 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -668,12 +668,12 @@ impl InternedString {
 
 impl BytesContainer for InternedString {
     fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
-        // FIXME(pcwalton): This is a workaround for the incorrect signature
+        // 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.get();
-            mem::transmute(this.container_as_bytes())
+            mem::transmute::<&[u8],&[u8]>(this.container_as_bytes())
         }
     }
 }
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 386fd8ae5a6..4cae3691f2a 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -169,17 +169,14 @@ pub fn to_string(f: |&mut State| -> IoResult<()>) -> String {
     let mut s = rust_printer(box MemWriter::new());
     f(&mut s).unwrap();
     eof(&mut s.s).unwrap();
-    unsafe {
+    let wr = unsafe {
         // FIXME(pcwalton): A nasty function to extract the string from an `io::Writer`
         // that we "know" to be a `MemWriter` that works around the lack of checked
         // downcasts.
-        let obj: TraitObject = mem::transmute_copy(&s.s.out);
-        let wr: Box<MemWriter> = mem::transmute(obj.data);
-        let result =
-            String::from_utf8(wr.get_ref().as_slice().to_vec()).unwrap();
-        mem::forget(wr);
-        result.to_string()
-    }
+        let obj: &TraitObject = mem::transmute(&s.s.out);
+        mem::transmute::<*mut (), &MemWriter>(obj.data)
+    };
+    String::from_utf8(wr.get_ref().to_vec()).unwrap()
 }
 
 pub fn binop_to_string(op: BinOpToken) -> &'static str {
@@ -818,9 +815,11 @@ impl<'a> State<'a> {
     }
 
     fn print_associated_type(&mut self, typedef: &ast::AssociatedType)
-                             -> IoResult<()> {
+                             -> IoResult<()>
+    {
+        try!(self.print_outer_attributes(typedef.attrs[]));
         try!(self.word_space("type"));
-        try!(self.print_ident(typedef.ident));
+        try!(self.print_ty_param(&typedef.ty_param));
         word(&mut self.s, ";")
     }
 
@@ -2434,23 +2433,7 @@ impl<'a> State<'a> {
             } else {
                 let idx = idx - generics.lifetimes.len();
                 let param = generics.ty_params.get(idx);
-                match param.unbound {
-                    Some(TraitTyParamBound(ref tref)) => {
-                        try!(s.print_trait_ref(tref));
-                        try!(s.word_space("?"));
-                    }
-                    _ => {}
-                }
-                try!(s.print_ident(param.ident));
-                try!(s.print_bounds(":", &param.bounds));
-                match param.default {
-                    Some(ref default) => {
-                        try!(space(&mut s.s));
-                        try!(s.word_space("="));
-                        s.print_type(&**default)
-                    }
-                    _ => Ok(())
-                }
+                s.print_ty_param(param)
             }
         }));
 
@@ -2458,6 +2441,26 @@ impl<'a> State<'a> {
         Ok(())
     }
 
+    pub fn print_ty_param(&mut self, param: &ast::TyParam) -> IoResult<()> {
+        match param.unbound {
+            Some(TraitTyParamBound(ref tref)) => {
+                try!(self.print_trait_ref(tref));
+                try!(self.word_space("?"));
+            }
+            _ => {}
+        }
+        try!(self.print_ident(param.ident));
+        try!(self.print_bounds(":", &param.bounds));
+        match param.default {
+            Some(ref default) => {
+                try!(space(&mut self.s));
+                try!(self.word_space("="));
+                self.print_type(&**default)
+            }
+            _ => Ok(())
+        }
+    }
+
     pub fn print_where_clause(&mut self, generics: &ast::Generics)
                               -> IoResult<()> {
         if generics.where_clause.predicates.len() == 0 {
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index bec72e88f99..86ee23d71a6 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -596,7 +596,8 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v Tr
         RequiredMethod(ref method_type) => visitor.visit_ty_method(method_type),
         ProvidedMethod(ref method) => walk_method_helper(visitor, &**method),
         TypeTraitItem(ref associated_type) => {
-            visitor.visit_ident(associated_type.span, associated_type.ident)
+            visitor.visit_ident(associated_type.ty_param.span,
+                                associated_type.ty_param.ident)
         }
     }
 }