about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-01-28 10:46:43 -0800
committerPatrick Walton <pcwalton@mimiga.net>2013-01-29 10:42:58 -0800
commit6ce74460e6a5c8045a7b43b86a656f28354f4b0c (patch)
treea09e6a6b8ba8566e6dc9f223d6cbbfbbdcde19e2 /src/libsyntax
parenteb4d39e1fef918242a5dba2a09d7b9faa437b911 (diff)
librustc: Disallow trait bounds in types, enumerations, and structure definitions. r=tjc
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/pipes/ast_builder.rs7
-rw-r--r--src/libsyntax/ext/pipes/pipec.rs8
-rw-r--r--src/libsyntax/parse/obsolete.rs18
-rw-r--r--src/libsyntax/util/interner.rs2
4 files changed, 20 insertions, 15 deletions
diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs
index 8a5b8a127d0..0433aab51fc 100644
--- a/src/libsyntax/ext/pipes/ast_builder.rs
+++ b/src/libsyntax/ext/pipes/ast_builder.rs
@@ -110,6 +110,7 @@ pub trait ext_ctxt_ast_builder {
     fn ty_option(ty: @ast::Ty) -> @ast::Ty;
     fn ty_infer() -> @ast::Ty;
     fn ty_nil_ast_builder() -> @ast::Ty;
+    fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param];
 }
 
 impl ext_ctxt: ext_ctxt_ast_builder {
@@ -370,6 +371,12 @@ impl ext_ctxt: ext_ctxt_ast_builder {
         }
     }
 
+    fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
+        do bounds.map |ty_param| {
+            ast::ty_param { bounds: @~[], ..copy *ty_param }
+        }
+    }
+
     fn item_ty_poly(name: ident,
                     span: span,
                     ty: @ast::Ty,
diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs
index 774a5596258..e7a8cbb9891 100644
--- a/src/libsyntax/ext/pipes/pipec.rs
+++ b/src/libsyntax/ext/pipes/pipec.rs
@@ -248,7 +248,7 @@ impl state: to_type_decls {
                 ast::enum_def(enum_def_ {
                     variants: items_msg,
                     common: None }),
-                self.ty_params
+                cx.strip_bounds(self.ty_params)
             )
         ]
     }
@@ -281,7 +281,7 @@ impl state: to_type_decls {
                                    self.data_name()],
                                  dummy_sp())
                             .add_tys(cx.ty_vars_global(self.ty_params))))),
-                    self.ty_params));
+                    cx.strip_bounds(self.ty_params)));
         }
         else {
             items.push(
@@ -299,7 +299,7 @@ impl state: to_type_decls {
                                         dummy_sp())
                             .add_tys(cx.ty_vars_global(self.ty_params))),
                                    self.proto.buffer_ty_path(cx)])),
-                    self.ty_params));
+                    cx.strip_bounds(self.ty_params)));
         };
         items
     }
@@ -417,7 +417,7 @@ impl protocol: gen_init {
             cx.ident_of(~"__Buffer"),
             dummy_sp(),
             cx.ty_rec(fields),
-            params)
+            cx.strip_bounds(params))
     }
 
     fn compile(cx: ext_ctxt) -> @ast::item {
diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs
index 67f6c4bed3f..86dea693f8a 100644
--- a/src/libsyntax/parse/obsolete.rs
+++ b/src/libsyntax/parse/obsolete.rs
@@ -33,6 +33,7 @@ use core::str;
 use core::to_bytes;
 
 /// The specific types of unsupported syntax
+#[deriving_eq]
 pub enum ObsoleteSyntax {
     ObsoleteLowerCaseKindBounds,
     ObsoleteLet,
@@ -45,16 +46,8 @@ pub enum ObsoleteSyntax {
     ObsoleteModeInFnType,
     ObsoleteMoveInit,
     ObsoleteBinaryMove,
-    ObsoleteUnsafeBlock
-}
-
-impl ObsoleteSyntax : cmp::Eq {
-    pure fn eq(&self, other: &ObsoleteSyntax) -> bool {
-        (*self) as uint == (*other) as uint
-    }
-    pure fn ne(&self, other: &ObsoleteSyntax) -> bool {
-        !(*self).eq(other)
-    }
+    ObsoleteUnsafeBlock,
+    ObsoleteUnenforcedBound
 }
 
 impl ObsoleteSyntax: to_bytes::IterBytes {
@@ -123,6 +116,11 @@ impl Parser {
             ObsoleteUnsafeBlock => (
                 "non-standalone unsafe block",
                 "use an inner `unsafe { ... }` block instead"
+            ),
+            ObsoleteUnenforcedBound => (
+                "unenforced type parameter bound",
+                "use trait bounds on the functions that take the type as \
+                 arguments, not on the types themselves"
             )
         };
 
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs
index e4a09c3c349..9de875485db 100644
--- a/src/libsyntax/util/interner.rs
+++ b/src/libsyntax/util/interner.rs
@@ -18,7 +18,7 @@ use core::dvec::DVec;
 use std::map::HashMap;
 use std::map;
 
-type hash_interner<T: Const> =
+type hash_interner<T> =
     {map: HashMap<T, uint>,
      vect: DVec<T>};