summaryrefslogtreecommitdiffstats
path: root/tests/ui/const-generics/infer
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/const-generics/infer')
-rw-r--r--tests/ui/const-generics/infer/cannot-infer-const-args.rs7
-rw-r--r--tests/ui/const-generics/infer/cannot-infer-const-args.stderr14
-rw-r--r--tests/ui/const-generics/infer/issue-77092.rs14
-rw-r--r--tests/ui/const-generics/infer/issue-77092.stderr14
-rw-r--r--tests/ui/const-generics/infer/method-chain.rs16
-rw-r--r--tests/ui/const-generics/infer/method-chain.stderr14
-rw-r--r--tests/ui/const-generics/infer/one-param-uninferred.rs11
-rw-r--r--tests/ui/const-generics/infer/one-param-uninferred.stderr14
-rw-r--r--tests/ui/const-generics/infer/uninferred-consts.rs11
-rw-r--r--tests/ui/const-generics/infer/uninferred-consts.stderr14
10 files changed, 129 insertions, 0 deletions
diff --git a/tests/ui/const-generics/infer/cannot-infer-const-args.rs b/tests/ui/const-generics/infer/cannot-infer-const-args.rs
new file mode 100644
index 000000000..f85a72910
--- /dev/null
+++ b/tests/ui/const-generics/infer/cannot-infer-const-args.rs
@@ -0,0 +1,7 @@
+fn foo<const X: usize>() -> usize {
+ 0
+}
+
+fn main() {
+ foo(); //~ ERROR type annotations needed
+}
diff --git a/tests/ui/const-generics/infer/cannot-infer-const-args.stderr b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr
new file mode 100644
index 000000000..93e45a88a
--- /dev/null
+++ b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/cannot-infer-const-args.rs:6:5
+ |
+LL | foo();
+ | ^^^ cannot infer the value of the const parameter `X` declared on the function `foo`
+ |
+help: consider specifying the generic argument
+ |
+LL | foo::<X>();
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/const-generics/infer/issue-77092.rs b/tests/ui/const-generics/infer/issue-77092.rs
new file mode 100644
index 000000000..fcf7d3282
--- /dev/null
+++ b/tests/ui/const-generics/infer/issue-77092.rs
@@ -0,0 +1,14 @@
+use std::convert::TryInto;
+
+fn take_array_from_mut<T, const N: usize>(data: &mut [T], start: usize) -> &mut [T; N] {
+ (&mut data[start .. start + N]).try_into().unwrap()
+}
+
+fn main() {
+ let mut arr = [0, 1, 2, 3, 4, 5, 6, 7, 8];
+
+ for i in 1 .. 4 {
+ println!("{:?}", take_array_from_mut(&mut arr, i));
+ //~^ ERROR type annotations needed
+ }
+}
diff --git a/tests/ui/const-generics/infer/issue-77092.stderr b/tests/ui/const-generics/infer/issue-77092.stderr
new file mode 100644
index 000000000..1682b26ac
--- /dev/null
+++ b/tests/ui/const-generics/infer/issue-77092.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/issue-77092.rs:11:26
+ |
+LL | println!("{:?}", take_array_from_mut(&mut arr, i));
+ | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut`
+ |
+help: consider specifying the generic arguments
+ |
+LL | println!("{:?}", take_array_from_mut::<i32, N>(&mut arr, i));
+ | ++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/const-generics/infer/method-chain.rs b/tests/ui/const-generics/infer/method-chain.rs
new file mode 100644
index 000000000..0c5eed489
--- /dev/null
+++ b/tests/ui/const-generics/infer/method-chain.rs
@@ -0,0 +1,16 @@
+struct Foo;
+
+impl Foo {
+ fn bar(self) -> Foo {
+ Foo
+ }
+
+ fn baz<const N: usize>(self) -> Foo {
+ println!("baz: {}", N);
+ Foo
+ }
+}
+
+fn main() {
+ Foo.bar().bar().bar().bar().baz(); //~ ERROR type annotations needed
+}
diff --git a/tests/ui/const-generics/infer/method-chain.stderr b/tests/ui/const-generics/infer/method-chain.stderr
new file mode 100644
index 000000000..ff6da535b
--- /dev/null
+++ b/tests/ui/const-generics/infer/method-chain.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/method-chain.rs:15:33
+ |
+LL | Foo.bar().bar().bar().bar().baz();
+ | ^^^ cannot infer the value of the const parameter `N` declared on the associated function `baz`
+ |
+help: consider specifying the generic argument
+ |
+LL | Foo.bar().bar().bar().bar().baz::<N>();
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/const-generics/infer/one-param-uninferred.rs b/tests/ui/const-generics/infer/one-param-uninferred.rs
new file mode 100644
index 000000000..d6018650f
--- /dev/null
+++ b/tests/ui/const-generics/infer/one-param-uninferred.rs
@@ -0,0 +1,11 @@
+// Test that we emit an error if we cannot properly infer a constant.
+fn foo<const N: usize, const M: usize>() -> [u8; N] {
+ todo!()
+}
+
+fn main() {
+ // FIXME(const_generics): Currently this only suggests one const parameter,
+ // but instead it should suggest to provide all parameters.
+ let _: [u8; 17] = foo();
+ //~^ ERROR type annotations needed
+}
diff --git a/tests/ui/const-generics/infer/one-param-uninferred.stderr b/tests/ui/const-generics/infer/one-param-uninferred.stderr
new file mode 100644
index 000000000..cf70c2181
--- /dev/null
+++ b/tests/ui/const-generics/infer/one-param-uninferred.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/one-param-uninferred.rs:9:23
+ |
+LL | let _: [u8; 17] = foo();
+ | ^^^ cannot infer the value of the const parameter `M` declared on the function `foo`
+ |
+help: consider specifying the generic arguments
+ |
+LL | let _: [u8; 17] = foo::<17, M>();
+ | +++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/const-generics/infer/uninferred-consts.rs b/tests/ui/const-generics/infer/uninferred-consts.rs
new file mode 100644
index 000000000..657f4b513
--- /dev/null
+++ b/tests/ui/const-generics/infer/uninferred-consts.rs
@@ -0,0 +1,11 @@
+// Test that we emit an error if we cannot properly infer a constant.
+
+// taken from https://github.com/rust-lang/rust/issues/70507#issuecomment-615268893
+struct Foo;
+impl Foo {
+ fn foo<const A: usize, const B: usize>(self) {}
+}
+fn main() {
+ Foo.foo();
+ //~^ ERROR type annotations needed
+}
diff --git a/tests/ui/const-generics/infer/uninferred-consts.stderr b/tests/ui/const-generics/infer/uninferred-consts.stderr
new file mode 100644
index 000000000..3980ecea8
--- /dev/null
+++ b/tests/ui/const-generics/infer/uninferred-consts.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/uninferred-consts.rs:9:9
+ |
+LL | Foo.foo();
+ | ^^^ cannot infer the value of the const parameter `A` declared on the associated function `foo`
+ |
+help: consider specifying the generic arguments
+ |
+LL | Foo.foo::<A, B>();
+ | ++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.