about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSean Patrick Santos <SeanPatrickSantos@gmail.com>2015-03-26 13:06:26 -0600
committerSean Patrick Santos <SeanPatrickSantos@gmail.com>2015-04-23 21:02:29 -0600
commitb1db4ec3d0a96a1e83d74fbc7f99dc3be054f4d8 (patch)
treeb716e5a1dace81b0758069179b2fbd3e283f37db /src
parent29eb550ee6a9fd6961bb00e2680a5735aab95de1 (diff)
downloadrust-b1db4ec3d0a96a1e83d74fbc7f99dc3be054f4d8.tar.gz
rust-b1db4ec3d0a96a1e83d74fbc7f99dc3be054f4d8.zip
Feature-gate associated constants.
Diffstat (limited to 'src')
-rw-r--r--src/doc/reference.md5
-rw-r--r--src/libsyntax/feature_gate.rs28
-rw-r--r--src/test/auxiliary/associated-const-cc-lib.rs2
-rw-r--r--src/test/compile-fail/associated-const-dead-code.rs1
-rw-r--r--src/test/compile-fail/associated-const-impl-wrong-type.rs2
-rw-r--r--src/test/compile-fail/associated-const-private-impl.rs2
-rw-r--r--src/test/compile-fail/associated-const-upper-case-lint.rs1
-rw-r--r--src/test/compile-fail/gated-associated_consts.rs25
-rw-r--r--src/test/compile-fail/impl-wrong-item-for-trait.rs2
-rw-r--r--src/test/run-pass/associated-const-cross-crate-defaults.rs2
-rw-r--r--src/test/run-pass/associated-const-cross-crate.rs2
-rw-r--r--src/test/run-pass/associated-const-in-global-const.rs2
-rw-r--r--src/test/run-pass/associated-const-inherent-impl.rs2
-rw-r--r--src/test/run-pass/associated-const-marks-live-code.rs2
-rw-r--r--src/test/run-pass/associated-const-match-patterns.rs2
-rw-r--r--src/test/run-pass/associated-const-overwrite-default.rs2
-rw-r--r--src/test/run-pass/associated-const-public-impl.rs2
-rw-r--r--src/test/run-pass/associated-const-resolution-order.rs2
-rw-r--r--src/test/run-pass/associated-const-self-type.rs2
-rw-r--r--src/test/run-pass/associated-const-ufcs-infer-trait.rs2
-rw-r--r--src/test/run-pass/associated-const-use-default.rs2
-rw-r--r--src/test/run-pass/associated-const-use-impl-of-same-trait.rs2
-rw-r--r--src/test/run-pass/associated-const.rs2
23 files changed, 95 insertions, 1 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md
index d918a320e63..2acd491c657 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -2340,7 +2340,10 @@ The currently implemented features of the reference compiler are:
           semantics are likely to change, so this macro usage must be opted
           into.
 
-* `associated_types` - Allows type aliases in traits. Experimental.
+* `associated_consts` - Allows constants to be defined in `impl` and `trait`
+                        blocks, so that they can be associated with a type or
+                        trait in a similar manner to methods and associated
+                        types.
 
 * `box_patterns` - Allows `box` patterns, the exact semantics of which
                    is subject to change.
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index d0975c76e93..495bbd412ab 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -155,6 +155,10 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
 
     // Allows use of unary negate on unsigned integers, e.g. -e for e: u8
     ("negate_unsigned", "1.0.0", Active),
+
+    // Allows the definition of associated constants in `trait` or `impl`
+    // blocks.
+    ("associated_consts", "1.0.0", Active),
 ];
 // (changing above list without updating src/doc/reference.md makes @cmr sad)
 
@@ -659,6 +663,30 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
         }
         visit::walk_fn(self, fn_kind, fn_decl, block, span);
     }
+
+    fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
+        match ti.node {
+            ast::ConstTraitItem(..) => {
+                self.gate_feature("associated_consts",
+                                  ti.span,
+                                  "associated constants are experimental")
+            }
+            _ => {}
+        }
+        visit::walk_trait_item(self, ti);
+    }
+
+    fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
+        match ii.node {
+            ast::ConstImplItem(..) => {
+                self.gate_feature("associated_consts",
+                                  ii.span,
+                                  "associated constants are experimental")
+            }
+            _ => {}
+        }
+        visit::walk_impl_item(self, ii);
+    }
 }
 
 fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
diff --git a/src/test/auxiliary/associated-const-cc-lib.rs b/src/test/auxiliary/associated-const-cc-lib.rs
index 9735c6cb54d..3508fcd54af 100644
--- a/src/test/auxiliary/associated-const-cc-lib.rs
+++ b/src/test/auxiliary/associated-const-cc-lib.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 #![crate_type="lib"]
 
 use std::marker::MarkerTrait;
diff --git a/src/test/compile-fail/associated-const-dead-code.rs b/src/test/compile-fail/associated-const-dead-code.rs
index 42db13f4f3b..1ed156d45f5 100644
--- a/src/test/compile-fail/associated-const-dead-code.rs
+++ b/src/test/compile-fail/associated-const-dead-code.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
 #![deny(dead_code)]
 
 struct MyFoo;
diff --git a/src/test/compile-fail/associated-const-impl-wrong-type.rs b/src/test/compile-fail/associated-const-impl-wrong-type.rs
index a7b2abc99e5..d76147de3db 100644
--- a/src/test/compile-fail/associated-const-impl-wrong-type.rs
+++ b/src/test/compile-fail/associated-const-impl-wrong-type.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 trait Foo: MarkerTrait {
diff --git a/src/test/compile-fail/associated-const-private-impl.rs b/src/test/compile-fail/associated-const-private-impl.rs
index 1d74873a5d5..4dfe7ea78c5 100644
--- a/src/test/compile-fail/associated-const-private-impl.rs
+++ b/src/test/compile-fail/associated-const-private-impl.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 mod bar1 {
diff --git a/src/test/compile-fail/associated-const-upper-case-lint.rs b/src/test/compile-fail/associated-const-upper-case-lint.rs
index 497ff426b2f..752691fa1c5 100644
--- a/src/test/compile-fail/associated-const-upper-case-lint.rs
+++ b/src/test/compile-fail/associated-const-upper-case-lint.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
 #![deny(non_upper_case_globals)]
 #![allow(dead_code)]
 
diff --git a/src/test/compile-fail/gated-associated_consts.rs b/src/test/compile-fail/gated-associated_consts.rs
new file mode 100644
index 00000000000..d508016357c
--- /dev/null
+++ b/src/test/compile-fail/gated-associated_consts.rs
@@ -0,0 +1,25 @@
+// Copyright 2015 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 std::marker::MarkerTrait;
+
+trait MyTrait: MarkerTrait {
+    const C: bool;
+    //~^ associated constants are experimental
+    //~| add #![feature(associated_consts)] to the crate attributes to enable
+}
+
+struct Foo;
+
+impl Foo {
+    const C: bool = true;
+    //~^ associated constants are experimental
+    //~| add #![feature(associated_consts)] to the crate attributes to enable
+}
diff --git a/src/test/compile-fail/impl-wrong-item-for-trait.rs b/src/test/compile-fail/impl-wrong-item-for-trait.rs
index 3757005b91f..9b3e28cbc01 100644
--- a/src/test/compile-fail/impl-wrong-item-for-trait.rs
+++ b/src/test/compile-fail/impl-wrong-item-for-trait.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 trait Foo {
     fn bar(&self);
     const MY_CONST: u32;
diff --git a/src/test/run-pass/associated-const-cross-crate-defaults.rs b/src/test/run-pass/associated-const-cross-crate-defaults.rs
index 944466f359d..92d2aae61c8 100644
--- a/src/test/run-pass/associated-const-cross-crate-defaults.rs
+++ b/src/test/run-pass/associated-const-cross-crate-defaults.rs
@@ -10,6 +10,8 @@
 
 // aux-build:associated-const-cc-lib.rs
 
+#![feature(associated_consts)]
+
 extern crate associated_const_cc_lib as foolib;
 
 pub struct LocalFooUseDefault;
diff --git a/src/test/run-pass/associated-const-cross-crate.rs b/src/test/run-pass/associated-const-cross-crate.rs
index c18cda018d8..73d5dc5df96 100644
--- a/src/test/run-pass/associated-const-cross-crate.rs
+++ b/src/test/run-pass/associated-const-cross-crate.rs
@@ -10,6 +10,8 @@
 
 // aux-build:associated-const-cc-lib.rs
 
+#![feature(associated_consts)]
+
 extern crate associated_const_cc_lib as foolib;
 
 pub struct LocalFoo;
diff --git a/src/test/run-pass/associated-const-in-global-const.rs b/src/test/run-pass/associated-const-in-global-const.rs
index b9fb067d4fa..e3a1e29d20f 100644
--- a/src/test/run-pass/associated-const-in-global-const.rs
+++ b/src/test/run-pass/associated-const-in-global-const.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 struct Foo;
 
 impl Foo {
diff --git a/src/test/run-pass/associated-const-inherent-impl.rs b/src/test/run-pass/associated-const-inherent-impl.rs
index 71f7a925d55..5c9abf982b1 100644
--- a/src/test/run-pass/associated-const-inherent-impl.rs
+++ b/src/test/run-pass/associated-const-inherent-impl.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 struct Foo;
 
 impl Foo {
diff --git a/src/test/run-pass/associated-const-marks-live-code.rs b/src/test/run-pass/associated-const-marks-live-code.rs
index e86ff0199a1..ea91a953129 100644
--- a/src/test/run-pass/associated-const-marks-live-code.rs
+++ b/src/test/run-pass/associated-const-marks-live-code.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 #![deny(dead_code)]
 
 const GLOBAL_BAR: u32 = 1;
diff --git a/src/test/run-pass/associated-const-match-patterns.rs b/src/test/run-pass/associated-const-match-patterns.rs
index 0085f89822e..63f77b35170 100644
--- a/src/test/run-pass/associated-const-match-patterns.rs
+++ b/src/test/run-pass/associated-const-match-patterns.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 struct Foo;
diff --git a/src/test/run-pass/associated-const-overwrite-default.rs b/src/test/run-pass/associated-const-overwrite-default.rs
index 26ece859e14..5134ad35659 100644
--- a/src/test/run-pass/associated-const-overwrite-default.rs
+++ b/src/test/run-pass/associated-const-overwrite-default.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 trait Foo: MarkerTrait {
diff --git a/src/test/run-pass/associated-const-public-impl.rs b/src/test/run-pass/associated-const-public-impl.rs
index 08676425a51..686ac19dad1 100644
--- a/src/test/run-pass/associated-const-public-impl.rs
+++ b/src/test/run-pass/associated-const-public-impl.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 mod bar1 {
diff --git a/src/test/run-pass/associated-const-resolution-order.rs b/src/test/run-pass/associated-const-resolution-order.rs
index e42dd25022b..ad20c084ff4 100644
--- a/src/test/run-pass/associated-const-resolution-order.rs
+++ b/src/test/run-pass/associated-const-resolution-order.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 struct MyType;
diff --git a/src/test/run-pass/associated-const-self-type.rs b/src/test/run-pass/associated-const-self-type.rs
index b4fb452e020..dc8b1307f76 100644
--- a/src/test/run-pass/associated-const-self-type.rs
+++ b/src/test/run-pass/associated-const-self-type.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 trait MyInt: MarkerTrait {
diff --git a/src/test/run-pass/associated-const-ufcs-infer-trait.rs b/src/test/run-pass/associated-const-ufcs-infer-trait.rs
index 21e1159366d..4cee76eb5aa 100644
--- a/src/test/run-pass/associated-const-ufcs-infer-trait.rs
+++ b/src/test/run-pass/associated-const-ufcs-infer-trait.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 trait Foo: MarkerTrait {
diff --git a/src/test/run-pass/associated-const-use-default.rs b/src/test/run-pass/associated-const-use-default.rs
index 59c83e267db..59df2fc41ed 100644
--- a/src/test/run-pass/associated-const-use-default.rs
+++ b/src/test/run-pass/associated-const-use-default.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 trait Foo: MarkerTrait {
diff --git a/src/test/run-pass/associated-const-use-impl-of-same-trait.rs b/src/test/run-pass/associated-const-use-impl-of-same-trait.rs
index 2f95d4275c5..6c9c6767cbd 100644
--- a/src/test/run-pass/associated-const-use-impl-of-same-trait.rs
+++ b/src/test/run-pass/associated-const-use-impl-of-same-trait.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 // The main purpose of this test is to ensure that different impls of the same
diff --git a/src/test/run-pass/associated-const.rs b/src/test/run-pass/associated-const.rs
index 5e7cc12cf48..9214467275f 100644
--- a/src/test/run-pass/associated-const.rs
+++ b/src/test/run-pass/associated-const.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(associated_consts)]
+
 use std::marker::MarkerTrait;
 
 trait Foo: MarkerTrait {