summaryrefslogtreecommitdiffstats
path: root/tests/ui/const-generics/generic_arg_infer
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/const-generics/generic_arg_infer')
-rw-r--r--tests/ui/const-generics/generic_arg_infer/array-repeat-expr.rs13
-rw-r--r--tests/ui/const-generics/generic_arg_infer/dont-use-defaults.rs15
-rw-r--r--tests/ui/const-generics/generic_arg_infer/in-signature.rs61
-rw-r--r--tests/ui/const-generics/generic_arg_infer/in-signature.stderr119
-rw-r--r--tests/ui/const-generics/generic_arg_infer/infer-arg-test.rs22
-rw-r--r--tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr24
-rw-r--r--tests/ui/const-generics/generic_arg_infer/infer_arg_and_const_arg.rs12
-rw-r--r--tests/ui/const-generics/generic_arg_infer/issue-91614.rs8
-rw-r--r--tests/ui/const-generics/generic_arg_infer/issue-91614.stderr23
9 files changed, 297 insertions, 0 deletions
diff --git a/tests/ui/const-generics/generic_arg_infer/array-repeat-expr.rs b/tests/ui/const-generics/generic_arg_infer/array-repeat-expr.rs
new file mode 100644
index 000000000..d3e53d7a8
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/array-repeat-expr.rs
@@ -0,0 +1,13 @@
+// run-pass
+
+// To avoid having to `or` gate `_` as an expr.
+#![feature(generic_arg_infer)]
+
+fn foo() -> [u8; 3] {
+ let x: [u8; _] = [0; _];
+ x
+}
+
+fn main() {
+ assert_eq!([0; _], foo());
+}
diff --git a/tests/ui/const-generics/generic_arg_infer/dont-use-defaults.rs b/tests/ui/const-generics/generic_arg_infer/dont-use-defaults.rs
new file mode 100644
index 000000000..251160a0f
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/dont-use-defaults.rs
@@ -0,0 +1,15 @@
+// run-pass
+#![feature(generic_arg_infer)]
+
+// test that we dont use defaults to aide in type inference
+
+struct Foo<const N: usize = 2>;
+impl<const N: usize> Foo<N> {
+ fn make_arr() -> [(); N] {
+ [(); N]
+ }
+}
+
+fn main() {
+ let [(), (), ()] = Foo::<_>::make_arr();
+}
diff --git a/tests/ui/const-generics/generic_arg_infer/in-signature.rs b/tests/ui/const-generics/generic_arg_infer/in-signature.rs
new file mode 100644
index 000000000..1f60b2242
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/in-signature.rs
@@ -0,0 +1,61 @@
+#![crate_type = "rlib"]
+#![feature(generic_arg_infer)]
+
+struct Foo<const N: usize>;
+struct Bar<T, const N: usize>(T);
+
+fn arr_fn() -> [u8; _] {
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
+ [0; 3]
+}
+
+fn ty_fn() -> Bar<i32, _> {
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
+ Bar::<i32, 3>(0)
+}
+
+fn ty_fn_mixed() -> Bar<_, _> {
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
+ Bar::<i32, 3>(0)
+}
+
+const ARR_CT: [u8; _] = [0; 3];
+//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
+static ARR_STATIC: [u8; _] = [0; 3];
+//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
+const TY_CT: Bar<i32, _> = Bar::<i32, 3>(0);
+//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
+static TY_STATIC: Bar<i32, _> = Bar::<i32, 3>(0);
+//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
+const TY_CT_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
+//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
+static TY_STATIC_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
+//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
+trait ArrAssocConst {
+ const ARR: [u8; _];
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
+}
+trait TyAssocConst {
+ const ARR: Bar<i32, _>;
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
+}
+trait TyAssocConstMixed {
+ const ARR: Bar<_, _>;
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
+}
+
+trait AssocTy {
+ type Assoc;
+}
+impl AssocTy for i8 {
+ type Assoc = [u8; _];
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
+}
+impl AssocTy for i16 {
+ type Assoc = Bar<i32, _>;
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
+}
+impl AssocTy for i32 {
+ type Assoc = Bar<_, _>;
+ //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
+}
diff --git a/tests/ui/const-generics/generic_arg_infer/in-signature.stderr b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr
new file mode 100644
index 000000000..52d1b29f9
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr
@@ -0,0 +1,119 @@
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
+ --> $DIR/in-signature.rs:7:21
+ |
+LL | fn arr_fn() -> [u8; _] {
+ | -----^-
+ | | |
+ | | not allowed in type signatures
+ | help: replace with the correct return type: `[u8; 3]`
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
+ --> $DIR/in-signature.rs:12:24
+ |
+LL | fn ty_fn() -> Bar<i32, _> {
+ | ---------^-
+ | | |
+ | | not allowed in type signatures
+ | help: replace with the correct return type: `Bar<i32, 3>`
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
+ --> $DIR/in-signature.rs:17:25
+ |
+LL | fn ty_fn_mixed() -> Bar<_, _> {
+ | ----^--^-
+ | | | |
+ | | | not allowed in type signatures
+ | | not allowed in type signatures
+ | help: replace with the correct return type: `Bar<i32, 3>`
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
+ --> $DIR/in-signature.rs:22:15
+ |
+LL | const ARR_CT: [u8; _] = [0; 3];
+ | ^^^^^^^ not allowed in type signatures
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
+ --> $DIR/in-signature.rs:24:20
+ |
+LL | static ARR_STATIC: [u8; _] = [0; 3];
+ | ^^^^^^^ not allowed in type signatures
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
+ --> $DIR/in-signature.rs:26:14
+ |
+LL | const TY_CT: Bar<i32, _> = Bar::<i32, 3>(0);
+ | ^^^^^^^^^^^
+ | |
+ | not allowed in type signatures
+ | help: replace with the correct type: `Bar<i32, 3>`
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
+ --> $DIR/in-signature.rs:28:19
+ |
+LL | static TY_STATIC: Bar<i32, _> = Bar::<i32, 3>(0);
+ | ^^^^^^^^^^^
+ | |
+ | not allowed in type signatures
+ | help: replace with the correct type: `Bar<i32, 3>`
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
+ --> $DIR/in-signature.rs:30:20
+ |
+LL | const TY_CT_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
+ | ^^^^^^^^^
+ | |
+ | not allowed in type signatures
+ | help: replace with the correct type: `Bar<i32, 3>`
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
+ --> $DIR/in-signature.rs:32:25
+ |
+LL | static TY_STATIC_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
+ | ^^^^^^^^^
+ | |
+ | not allowed in type signatures
+ | help: replace with the correct type: `Bar<i32, 3>`
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
+ --> $DIR/in-signature.rs:35:21
+ |
+LL | const ARR: [u8; _];
+ | ^ not allowed in type signatures
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
+ --> $DIR/in-signature.rs:39:25
+ |
+LL | const ARR: Bar<i32, _>;
+ | ^ not allowed in type signatures
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
+ --> $DIR/in-signature.rs:43:20
+ |
+LL | const ARR: Bar<_, _>;
+ | ^ ^ not allowed in type signatures
+ | |
+ | not allowed in type signatures
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types
+ --> $DIR/in-signature.rs:51:23
+ |
+LL | type Assoc = [u8; _];
+ | ^ not allowed in type signatures
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types
+ --> $DIR/in-signature.rs:55:27
+ |
+LL | type Assoc = Bar<i32, _>;
+ | ^ not allowed in type signatures
+
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types
+ --> $DIR/in-signature.rs:59:22
+ |
+LL | type Assoc = Bar<_, _>;
+ | ^ ^ not allowed in type signatures
+ | |
+ | not allowed in type signatures
+
+error: aborting due to 15 previous errors
+
+For more information about this error, try `rustc --explain E0121`.
diff --git a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.rs b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.rs
new file mode 100644
index 000000000..29aa0f59d
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.rs
@@ -0,0 +1,22 @@
+#![feature(generic_arg_infer)]
+
+struct All<'a, T, const N: usize> {
+ v: &'a T,
+}
+
+struct BadInfer<_>;
+//~^ ERROR expected identifier
+//~| ERROR parameter `_` is never used
+
+fn all_fn<'a, T, const N: usize>() {}
+
+fn bad_infer_fn<_>() {}
+//~^ ERROR expected identifier
+
+
+fn main() {
+ let a: All<_, _, _>;
+ all_fn();
+ let v: [u8; _];
+ let v: [u8; 10] = [0; _];
+}
diff --git a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr
new file mode 100644
index 000000000..e6d0c743d
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr
@@ -0,0 +1,24 @@
+error: expected identifier, found reserved identifier `_`
+ --> $DIR/infer-arg-test.rs:7:17
+ |
+LL | struct BadInfer<_>;
+ | ^ expected identifier, found reserved identifier
+
+error: expected identifier, found reserved identifier `_`
+ --> $DIR/infer-arg-test.rs:13:17
+ |
+LL | fn bad_infer_fn<_>() {}
+ | ^ expected identifier, found reserved identifier
+
+error[E0392]: parameter `_` is never used
+ --> $DIR/infer-arg-test.rs:7:17
+ |
+LL | struct BadInfer<_>;
+ | ^ unused parameter
+ |
+ = help: consider removing `_`, referring to it in a field, or using a marker such as `PhantomData`
+ = help: if you intended `_` to be a const parameter, use `const _: usize` instead
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0392`.
diff --git a/tests/ui/const-generics/generic_arg_infer/infer_arg_and_const_arg.rs b/tests/ui/const-generics/generic_arg_infer/infer_arg_and_const_arg.rs
new file mode 100644
index 000000000..23c8d7537
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/infer_arg_and_const_arg.rs
@@ -0,0 +1,12 @@
+// check-pass
+#![feature(generic_arg_infer)]
+
+struct Foo<const N: bool, const M: u8>;
+struct Bar<const N: u8, const M: u32>;
+
+fn main() {
+ let _: Foo<true, _> = Foo::<_, 1>;
+ let _: Foo<_, 1> = Foo::<true, _>;
+ let _: Bar<1, _> = Bar::<_, 300>;
+ let _: Bar<_, 300> = Bar::<1, _>;
+}
diff --git a/tests/ui/const-generics/generic_arg_infer/issue-91614.rs b/tests/ui/const-generics/generic_arg_infer/issue-91614.rs
new file mode 100644
index 000000000..b45e2cbc7
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/issue-91614.rs
@@ -0,0 +1,8 @@
+#![feature(portable_simd)]
+#![feature(generic_arg_infer)]
+use std::simd::Mask;
+
+fn main() {
+ let y = Mask::<_, _>::splat(false);
+ //~^ ERROR: type annotations needed for
+}
diff --git a/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr
new file mode 100644
index 000000000..13ea4a295
--- /dev/null
+++ b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr
@@ -0,0 +1,23 @@
+error[E0283]: type annotations needed for `Mask<_, LANES>`
+ --> $DIR/issue-91614.rs:6:9
+ |
+LL | let y = Mask::<_, _>::splat(false);
+ | ^ ------------------- type must be known at this point
+ |
+ = note: cannot satisfy `_: MaskElement`
+ = help: the following types implement trait `MaskElement`:
+ i16
+ i32
+ i64
+ i8
+ isize
+note: required by a bound in `Mask::<T, LANES>::splat`
+ --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
+help: consider giving `y` an explicit type, where the type for type parameter `T` is specified
+ |
+LL | let y: Mask<_, LANES> = Mask::<_, _>::splat(false);
+ | ++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0283`.