about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/comp/middle/resolve.rs16
-rw-r--r--src/comp/syntax/ast.rs2
-rw-r--r--src/comp/syntax/parse/parser.rs9
-rw-r--r--src/comp/syntax/print/pprust.rs4
-rw-r--r--src/test/run-pass/type-param-constraints.rs25
5 files changed, 49 insertions, 7 deletions
diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs
index 443e5cc8c73..a9a02b8a88f 100644
--- a/src/comp/middle/resolve.rs
+++ b/src/comp/middle/resolve.rs
@@ -710,7 +710,7 @@ fn lookup_in_ty_params(name: &ident, ty_params: &ast::ty_param[]) ->
    option::t[def] {
     let i = 0u;
     for tp: ast::ty_param  in ty_params {
-        if str::eq(tp, name) { ret some(ast::def_ty_arg(i)); }
+        if str::eq(tp.ident, name) { ret some(ast::def_ty_arg(i)); }
         i += 1u;
     }
     ret none[def];
@@ -1215,11 +1215,17 @@ fn mie_span(mie: &mod_index_entry) -> span {
 }
 
 fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt[()]) {
+    fn typaram_names(tps: &ast::ty_param[]) -> ident[] {
+        let x: ast::ident[] = ~[];
+        for tp: ast::ty_param in tps { x += ~[tp.ident] }
+        ret x;
+    }
     visit::visit_item(i, x, v);
     alt i.node {
       ast::item_fn(f, ty_params) {
         check_fn(*e, i.span, f);
-        ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
+        ensure_unique(*e, i.span, typaram_names(ty_params),
+                      ident_id, "type parameter");
       }
       ast::item_obj(ob, ty_params, _) {
         fn field_name(field: &ast::obj_field) -> ident { ret field.ident; }
@@ -1227,10 +1233,12 @@ fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt[()]) {
         for m: @ast::method  in ob.methods {
             check_fn(*e, m.span, m.node.meth);
         }
-        ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
+        ensure_unique(*e, i.span, typaram_names(ty_params),
+                      ident_id, "type parameter");
       }
       ast::item_tag(_, ty_params) {
-        ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
+        ensure_unique(*e, i.span, typaram_names(ty_params),
+                      ident_id, "type parameter");
       }
       _ { }
     }
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 45be817f91a..d5d99a886aa 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -31,7 +31,7 @@ type def_id = {crate: crate_num, node: node_id};
 const local_crate: crate_num = 0;
 fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; }
 
-type ty_param = ident;
+type ty_param = {ident: ident, kind: kind};
 
 tag def {
     def_fn(def_id, purity);
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 4d8fe833559..79728fade13 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1696,7 +1696,14 @@ fn parse_block_tail(p: &parser, lo: uint) -> ast::blk {
     ret spanned(lo, hi, bloc);
 }
 
-fn parse_ty_param(p: &parser) -> ast::ty_param { ret parse_ident(p); }
+fn parse_ty_param(p: &parser) -> ast::ty_param {
+    let k = alt p.peek() {
+      token::TILDE. { p.bump(); ast::kind_unique }
+      token::AT. { p.bump(); ast::kind_shared }
+      _ { ast::kind_pinned }
+    };
+    ret {ident: parse_ident(p), kind: k};
+}
 
 fn parse_ty_params(p: &parser) -> ast::ty_param[] {
     let ty_params: ast::ty_param[] = ~[];
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 92510af42cf..db3586d9275 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -1149,7 +1149,9 @@ fn print_alias(s: &ps, m: ast::mode) {
 fn print_type_params(s: &ps, params: &ast::ty_param[]) {
     if ivec::len(params) > 0u {
         word(s.s, "[");
-        fn printParam(s: &ps, param: &ast::ty_param) { word(s.s, param); }
+        fn printParam(s: &ps, param: &ast::ty_param) {
+            word(s.s, param.ident);
+        }
         commasep(s, inconsistent, params, printParam);
         word(s.s, "]");
     }
diff --git a/src/test/run-pass/type-param-constraints.rs b/src/test/run-pass/type-param-constraints.rs
new file mode 100644
index 00000000000..34ebdadcd95
--- /dev/null
+++ b/src/test/run-pass/type-param-constraints.rs
@@ -0,0 +1,25 @@
+fn p_foo[T](pinned: &T) {  }
+fn s_foo[@T](shared: &T) {  }
+fn u_foo[~T](unique: &T) {  }
+
+resource r(i: int) { }
+
+fn main() {
+    // FIXME: passing resources doesn't work?
+    //p_foo(r(10));
+    //p_foo(@r(10));
+    // FIXME: unique boxes not yet supported.
+    // p_foo(~r(10));
+    p_foo(@10);
+    // p_foo(~10);
+    p_foo(10);
+
+    //s_foo(@r(10));
+    //s_foo(~r(10));
+    s_foo(@10);
+    //s_foo(~10);
+    s_foo(10);
+
+    //u_foo(~10);
+    u_foo(10);
+}
\ No newline at end of file