about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-01 13:17:42 +0000
committerbors <bors@rust-lang.org>2021-01-01 13:17:42 +0000
commita609fb45efad59dfd459c76e50899be9f0583b5a (patch)
treec1fdab60473e830ac13b75ffaa0175c46bb27f57 /src/test
parent18d27b2c94cff9a5f6d8e4d2ea45f6f2e434e5f6 (diff)
parent942b7ce2c14b1c4fde5b9f27aa5bef39e0b990d5 (diff)
downloadrust-a609fb45efad59dfd459c76e50899be9f0583b5a.tar.gz
rust-a609fb45efad59dfd459c76e50899be9f0583b5a.zip
Auto merge of #80547 - lqd:const_generics_defaults, r=varkor
In which we start to parse const generics defaults

As discussed in this [zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/const.20generic.20defaults), this PR extracts the parsing parts from `@JulianKnodt's` PR #75384 for a better user-experience using the newly stabilized `min_const_generics` (albeit temporary) as shown in #80507: trying to use default values on const generics currently results in parse errors, as if the user didn't use the correct syntax (which is somewhat true but also misleading).

This PR extracts (and slightly modifies in a couple places) `@JulianKnodt's` parsing code (with attribution if I've done everything correctly), AST and HIR changes, and feature gate setup.

This feature is now marked as "incomplete" and thus will also print out the expected "const generics default values are unstable" error instead of a syntax error. Note that, as I've only extracted the parsing part, the actual feature will not work at all if enabled. There will be ICEs, and inference errors on the const generics default values themselves.

Fixes #80507.

Once this merges, I'll:
- modify the const generics tracking issue to refer to the `const_generics_defaults` gate rather than the older temporary name it uses there.
- create the GH `F-const_generics_defaults` label

r? `@varkor`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/const-generics/min_const_generics/default_function_param.rs2
-rw-r--r--src/test/ui/const-generics/min_const_generics/default_function_param.stderr8
-rw-r--r--src/test/ui/const-generics/min_const_generics/default_trait_param.rs2
-rw-r--r--src/test/ui/const-generics/min_const_generics/default_trait_param.stderr8
-rw-r--r--src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs2
-rw-r--r--src/test/ui/feature-gates/feature-gate-const_generics_defaults.rs9
-rw-r--r--src/test/ui/feature-gates/feature-gate-const_generics_defaults.stderr21
7 files changed, 45 insertions, 7 deletions
diff --git a/src/test/ui/const-generics/min_const_generics/default_function_param.rs b/src/test/ui/const-generics/min_const_generics/default_function_param.rs
index d7918a73ab8..5b0a42a4556 100644
--- a/src/test/ui/const-generics/min_const_generics/default_function_param.rs
+++ b/src/test/ui/const-generics/min_const_generics/default_function_param.rs
@@ -1,4 +1,4 @@
 fn foo<const SIZE: usize = 5>() {}
-                      //~^ ERROR expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
+//~^ ERROR default values for const generic parameters are experimental
 
 fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/default_function_param.stderr b/src/test/ui/const-generics/min_const_generics/default_function_param.stderr
index 8eb796d9bb7..31b5ad5123e 100644
--- a/src/test/ui/const-generics/min_const_generics/default_function_param.stderr
+++ b/src/test/ui/const-generics/min_const_generics/default_function_param.stderr
@@ -1,8 +1,12 @@
-error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
+error[E0658]: default values for const generic parameters are experimental
   --> $DIR/default_function_param.rs:1:26
    |
 LL | fn foo<const SIZE: usize = 5>() {}
-   |                          ^ expected one of 7 possible tokens
+   |                          ^^^
+   |
+   = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
+   = help: add `#![feature(const_generics_defaults)]` to the crate attributes to enable
 
 error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/const-generics/min_const_generics/default_trait_param.rs b/src/test/ui/const-generics/min_const_generics/default_trait_param.rs
index c8003ad5d44..14bac473ed9 100644
--- a/src/test/ui/const-generics/min_const_generics/default_trait_param.rs
+++ b/src/test/ui/const-generics/min_const_generics/default_trait_param.rs
@@ -1,4 +1,4 @@
 trait Foo<const KIND: bool = true> {}
-                        //~^ ERROR expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
+//~^ ERROR default values for const generic parameters are experimental
 
 fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/default_trait_param.stderr b/src/test/ui/const-generics/min_const_generics/default_trait_param.stderr
index 6d112ef1de0..5617b35ad01 100644
--- a/src/test/ui/const-generics/min_const_generics/default_trait_param.stderr
+++ b/src/test/ui/const-generics/min_const_generics/default_trait_param.stderr
@@ -1,8 +1,12 @@
-error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
+error[E0658]: default values for const generic parameters are experimental
   --> $DIR/default_trait_param.rs:1:28
    |
 LL | trait Foo<const KIND: bool = true> {}
-   |                            ^ expected one of 7 possible tokens
+   |                            ^^^^^^
+   |
+   = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
+   = help: add `#![feature(const_generics_defaults)]` to the crate attributes to enable
 
 error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs
index 845c6111b59..a85e2a2f2c4 100644
--- a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs
+++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs
@@ -7,7 +7,7 @@ struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
 //[full]~^ ERROR constant values inside of type parameter defaults
 //[min]~^^ ERROR generic parameters may not be used in const operations
 
-// FIXME(const_generics:defaults): We still don't know how to we deal with type defaults.
+// FIXME(const_generics_defaults): We still don't know how to deal with type defaults.
 struct Bar<T = [u8; N], const N: usize>(T);
 //~^ ERROR constant values inside of type parameter defaults
 //~| ERROR type parameters with a default
diff --git a/src/test/ui/feature-gates/feature-gate-const_generics_defaults.rs b/src/test/ui/feature-gates/feature-gate-const_generics_defaults.rs
new file mode 100644
index 00000000000..5b5ccc88873
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-const_generics_defaults.rs
@@ -0,0 +1,9 @@
+#[cfg(FALSE)]
+struct A<const N: usize = 3>;
+//~^ ERROR default values for const generic parameters are experimental
+
+#[cfg(FALSE)]
+fn foo<const B: bool = false>() {}
+//~^ ERROR default values for const generic parameters are experimental
+
+fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-const_generics_defaults.stderr b/src/test/ui/feature-gates/feature-gate-const_generics_defaults.stderr
new file mode 100644
index 00000000000..e2b48d793fd
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-const_generics_defaults.stderr
@@ -0,0 +1,21 @@
+error[E0658]: default values for const generic parameters are experimental
+  --> $DIR/feature-gate-const_generics_defaults.rs:2:25
+   |
+LL | struct A<const N: usize = 3>;
+   |                         ^^^
+   |
+   = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
+   = help: add `#![feature(const_generics_defaults)]` to the crate attributes to enable
+
+error[E0658]: default values for const generic parameters are experimental
+  --> $DIR/feature-gate-const_generics_defaults.rs:6:22
+   |
+LL | fn foo<const B: bool = false>() {}
+   |                      ^^^^^^^
+   |
+   = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
+   = help: add `#![feature(const_generics_defaults)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.