about summary refs log tree commit diff
path: root/src/test/ui/missing/missing-items
diff options
context:
space:
mode:
authormibac138 <5672750+mibac138@users.noreply.github.com>2021-05-06 14:33:02 +0200
committermibac138 <5672750+mibac138@users.noreply.github.com>2021-05-06 18:27:36 +0200
commit1bb94fbbeb703806817a09806365e26a18f5daa4 (patch)
tree927fabc623d3b9e10e8c0f2b196c2a5dc617b6fc /src/test/ui/missing/missing-items
parent693e9579bc796e5a8f38f58563e20d3cc1c21ce3 (diff)
downloadrust-1bb94fbbeb703806817a09806365e26a18f5daa4.tar.gz
rust-1bb94fbbeb703806817a09806365e26a18f5daa4.zip
Expand impl type parameter suggestion tests
Diffstat (limited to 'src/test/ui/missing/missing-items')
-rw-r--r--src/test/ui/missing/missing-items/missing-type-parameter2.rs18
-rw-r--r--src/test/ui/missing/missing-items/missing-type-parameter2.stderr85
2 files changed, 103 insertions, 0 deletions
diff --git a/src/test/ui/missing/missing-items/missing-type-parameter2.rs b/src/test/ui/missing/missing-items/missing-type-parameter2.rs
new file mode 100644
index 00000000000..e5d90bb6ff0
--- /dev/null
+++ b/src/test/ui/missing/missing-items/missing-type-parameter2.rs
@@ -0,0 +1,18 @@
+#![allow(incomplete_features)]
+#![feature(const_generics_defaults)]
+
+struct X<const N: u8>();
+
+impl X<N> {}
+//~^ ERROR cannot find type `N` in this scope
+//~| ERROR unresolved item provided when a constant was expected
+impl<T, const A: u8 = 2> X<N> {}
+//~^ ERROR cannot find type `N` in this scope
+//~| ERROR defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
+//~| ERROR unresolved item provided when a constant was expected
+
+fn bar<const N: u8>(a: A) {}
+//~^ ERROR cannot find type `A` in this scope
+
+fn main() {
+}
diff --git a/src/test/ui/missing/missing-items/missing-type-parameter2.stderr b/src/test/ui/missing/missing-items/missing-type-parameter2.stderr
new file mode 100644
index 00000000000..545be1c34fb
--- /dev/null
+++ b/src/test/ui/missing/missing-items/missing-type-parameter2.stderr
@@ -0,0 +1,85 @@
+error[E0412]: cannot find type `N` in this scope
+  --> $DIR/missing-type-parameter2.rs:6:8
+   |
+LL | struct X<const N: u8>();
+   | ------------------------ similarly named struct `X` defined here
+LL | 
+LL | impl X<N> {}
+   |        ^
+   |
+help: a struct with a similar name exists
+   |
+LL | impl X<X> {}
+   |        ^
+help: you might be missing a type parameter
+   |
+LL | impl<N> X<N> {}
+   |     ^^^
+
+error[E0412]: cannot find type `N` in this scope
+  --> $DIR/missing-type-parameter2.rs:9:28
+   |
+LL | impl<T, const A: u8 = 2> X<N> {}
+   |      -                     ^
+   |      |
+   |      similarly named type parameter `T` defined here
+   |
+help: a type parameter with a similar name exists
+   |
+LL | impl<T, const A: u8 = 2> X<T> {}
+   |                            ^
+help: you might be missing a type parameter
+   |
+LL | impl<T, const A, N: u8 = 2> X<N> {}
+   |                ^^^
+
+error[E0412]: cannot find type `A` in this scope
+  --> $DIR/missing-type-parameter2.rs:14:24
+   |
+LL | struct X<const N: u8>();
+   | ------------------------ similarly named struct `X` defined here
+...
+LL | fn bar<const N: u8>(a: A) {}
+   |                        ^
+   |
+help: a struct with a similar name exists
+   |
+LL | fn bar<const N: u8>(a: X) {}
+   |                        ^
+help: you might be missing a type parameter
+   |
+LL | fn bar<const N, A: u8>(a: A) {}
+   |               ^^^
+
+error[E0747]: unresolved item provided when a constant was expected
+  --> $DIR/missing-type-parameter2.rs:6:8
+   |
+LL | impl X<N> {}
+   |        ^
+   |
+help: if this generic argument was intended as a const parameter, surround it with braces
+   |
+LL | impl X<{ N }> {}
+   |        ^   ^
+
+error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
+  --> $DIR/missing-type-parameter2.rs:9:15
+   |
+LL | impl<T, const A: u8 = 2> X<N> {}
+   |               ^
+
+error[E0747]: unresolved item provided when a constant was expected
+  --> $DIR/missing-type-parameter2.rs:9:28
+   |
+LL | impl<T, const A: u8 = 2> X<N> {}
+   |                            ^
+   |
+help: if this generic argument was intended as a const parameter, surround it with braces
+   |
+LL | impl<T, const A: u8 = 2> X<{ N }> {}
+   |                            ^   ^
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0412, E0747.
+For more information about an error, try `rustc --explain E0412`.