about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-21 18:58:17 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-10-24 00:32:03 +0200
commit49cbfa1a6f6469ddbc0e88161e52104cc87aea9b (patch)
treeaf0abae0cbf18a6f7a19ae19e912bd5b7bee0805
parent04c661ba021730bc13d33c6d55cb9aad05026f36 (diff)
downloadrust-49cbfa1a6f6469ddbc0e88161e52104cc87aea9b.tar.gz
rust-49cbfa1a6f6469ddbc0e88161e52104cc87aea9b.zip
pre-expansion gate const_generics
-rw-r--r--src/libsyntax/feature_gate/check.rs13
-rw-r--r--src/libsyntax/parse/parser/generics.rs4
-rw-r--r--src/libsyntax/sess.rs2
-rw-r--r--src/test/ui/const-generics/const-param-in-trait-ungated.stderr4
-rw-r--r--src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr4
-rw-r--r--src/test/ui/const-generics/issues/issue-60263.stderr4
-rw-r--r--src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr8
-rw-r--r--src/test/ui/feature-gates/feature-gate-const_generics.rs5
-rw-r--r--src/test/ui/feature-gates/feature-gate-const_generics.stderr19
9 files changed, 37 insertions, 26 deletions
diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs
index 58610d8db7e..282b5ae2193 100644
--- a/src/libsyntax/feature_gate/check.rs
+++ b/src/libsyntax/feature_gate/check.rs
@@ -3,7 +3,7 @@ use super::accepted::ACCEPTED_FEATURES;
 use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
 use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
 
-use crate::ast::{self, NodeId, GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
+use crate::ast::{self, NodeId, PatKind, RangeEnd, VariantData};
 use crate::attr::{self, check_builtin_attribute};
 use crate::source_map::Spanned;
 use crate::edition::{ALL_EDITIONS, Edition};
@@ -571,16 +571,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
         visit::walk_fn(self, fn_kind, fn_decl, span)
     }
 
-    fn visit_generic_param(&mut self, param: &'a GenericParam) {
-        match param.kind {
-            GenericParamKind::Const { .. } =>
-                gate_feature_post!(&self, const_generics, param.ident.span,
-                    "const generics are unstable"),
-            _ => {}
-        }
-        visit::walk_generic_param(self, param)
-    }
-
     fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
         match ti.kind {
             ast::TraitItemKind::Method(ref sig, ref block) => {
@@ -840,6 +830,7 @@ pub fn check_crate(krate: &ast::Crate,
     gate_all!(trait_alias, "trait aliases are experimental");
     gate_all!(associated_type_bounds, "associated type bounds are unstable");
     gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
+    gate_all!(const_generics, "const generics are unstable");
 
     visit::walk_crate(&mut visitor, krate);
 }
diff --git a/src/libsyntax/parse/parser/generics.rs b/src/libsyntax/parse/parser/generics.rs
index bfcb0042a75..51caae69c86 100644
--- a/src/libsyntax/parse/parser/generics.rs
+++ b/src/libsyntax/parse/parser/generics.rs
@@ -55,11 +55,15 @@ impl<'a> Parser<'a> {
     }
 
     fn parse_const_param(&mut self, preceding_attrs: Vec<Attribute>) -> PResult<'a, GenericParam> {
+        let lo = self.token.span;
+
         self.expect_keyword(kw::Const)?;
         let ident = self.parse_ident()?;
         self.expect(&token::Colon)?;
         let ty = self.parse_ty()?;
 
+        self.sess.gated_spans.const_generics.borrow_mut().push(lo.to(self.prev_span));
+
         Ok(GenericParam {
             ident,
             id: ast::DUMMY_NODE_ID,
diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs
index 58a2f89aca9..3d2051b4c78 100644
--- a/src/libsyntax/sess.rs
+++ b/src/libsyntax/sess.rs
@@ -36,6 +36,8 @@ crate struct GatedSpans {
     pub associated_type_bounds: Lock<Vec<Span>>,
     /// Spans collected for gating `crate_visibility_modifier`, e.g. `crate fn`.
     pub crate_visibility_modifier: Lock<Vec<Span>>,
+    /// Spans collected for gating `const_generics`, e.g. `const N: usize`.
+    pub const_generics: Lock<Vec<Span>>,
 }
 
 /// Info about a parsing session.
diff --git a/src/test/ui/const-generics/const-param-in-trait-ungated.stderr b/src/test/ui/const-generics/const-param-in-trait-ungated.stderr
index cfb1f8b581c..330c93e83b5 100644
--- a/src/test/ui/const-generics/const-param-in-trait-ungated.stderr
+++ b/src/test/ui/const-generics/const-param-in-trait-ungated.stderr
@@ -1,8 +1,8 @@
 error[E0658]: const generics are unstable
-  --> $DIR/const-param-in-trait-ungated.rs:1:19
+  --> $DIR/const-param-in-trait-ungated.rs:1:13
    |
 LL | trait Trait<const T: ()> {}
-   |                   ^
+   |             ^^^^^^^^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/44580
    = help: add `#![feature(const_generics)]` to the crate attributes to enable
diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr
index c659074a091..969f35bdaa3 100644
--- a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr
+++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr
@@ -5,10 +5,10 @@ LL | struct B<T, const N: T>(PhantomData<[T; N]>);
    |                      ^ const parameter depends on type parameter
 
 error[E0658]: const generics are unstable
-  --> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:19
+  --> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:13
    |
 LL | struct B<T, const N: T>(PhantomData<[T; N]>);
-   |                   ^
+   |             ^^^^^^^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/44580
    = help: add `#![feature(const_generics)]` to the crate attributes to enable
diff --git a/src/test/ui/const-generics/issues/issue-60263.stderr b/src/test/ui/const-generics/issues/issue-60263.stderr
index fe7b6fdb190..5223c8c5137 100644
--- a/src/test/ui/const-generics/issues/issue-60263.stderr
+++ b/src/test/ui/const-generics/issues/issue-60263.stderr
@@ -1,8 +1,8 @@
 error[E0658]: const generics are unstable
-  --> $DIR/issue-60263.rs:1:16
+  --> $DIR/issue-60263.rs:1:10
    |
 LL | struct B<const I: u8>;
-   |                ^
+   |          ^^^^^^^^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/44580
    = help: add `#![feature(const_generics)]` to the crate attributes to enable
diff --git a/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr b/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr
index 935f84b9163..790bc33e268 100644
--- a/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr
+++ b/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr
@@ -1,17 +1,17 @@
 error[E0658]: const generics are unstable
-  --> $DIR/feature-gate-const_generics-ptr.rs:1:22
+  --> $DIR/feature-gate-const_generics-ptr.rs:1:16
    |
 LL | struct ConstFn<const F: fn()>;
-   |                      ^
+   |                ^^^^^^^^^^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/44580
    = help: add `#![feature(const_generics)]` to the crate attributes to enable
 
 error[E0658]: const generics are unstable
-  --> $DIR/feature-gate-const_generics-ptr.rs:5:23
+  --> $DIR/feature-gate-const_generics-ptr.rs:5:17
    |
 LL | struct ConstPtr<const P: *const u32>;
-   |                       ^
+   |                 ^^^^^^^^^^^^^^^^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/44580
    = help: add `#![feature(const_generics)]` to the crate attributes to enable
diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.rs b/src/test/ui/feature-gates/feature-gate-const_generics.rs
index fe1ded1c4bb..0adc9902a69 100644
--- a/src/test/ui/feature-gates/feature-gate-const_generics.rs
+++ b/src/test/ui/feature-gates/feature-gate-const_generics.rs
@@ -2,4 +2,9 @@ fn foo<const X: ()>() {} //~ ERROR const generics are unstable
 
 struct Foo<const X: usize>([(); X]); //~ ERROR const generics are unstable
 
+macro_rules! accept_item { ($i:item) => {} }
+accept_item! {
+    impl<const X: ()> A {} //~ ERROR const generics are unstable
+}
+
 fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.stderr b/src/test/ui/feature-gates/feature-gate-const_generics.stderr
index 468e9c31d37..f0154ed289f 100644
--- a/src/test/ui/feature-gates/feature-gate-const_generics.stderr
+++ b/src/test/ui/feature-gates/feature-gate-const_generics.stderr
@@ -1,21 +1,30 @@
 error[E0658]: const generics are unstable
-  --> $DIR/feature-gate-const_generics.rs:1:14
+  --> $DIR/feature-gate-const_generics.rs:1:8
    |
 LL | fn foo<const X: ()>() {}
-   |              ^
+   |        ^^^^^^^^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/44580
    = help: add `#![feature(const_generics)]` to the crate attributes to enable
 
 error[E0658]: const generics are unstable
-  --> $DIR/feature-gate-const_generics.rs:3:18
+  --> $DIR/feature-gate-const_generics.rs:3:12
    |
 LL | struct Foo<const X: usize>([(); X]);
-   |                  ^
+   |            ^^^^^^^^^^^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/44580
    = help: add `#![feature(const_generics)]` to the crate attributes to enable
 
-error: aborting due to 2 previous errors
+error[E0658]: const generics are unstable
+  --> $DIR/feature-gate-const_generics.rs:7:10
+   |
+LL |     impl<const X: ()> A {}
+   |          ^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/44580
+   = help: add `#![feature(const_generics)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0658`.