Skip to content

Commit 1bb94fb

Browse files
committed
Expand impl type parameter suggestion tests
1 parent 693e957 commit 1bb94fb

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![allow(incomplete_features)]
2+
#![feature(const_generics_defaults)]
3+
4+
struct X<const N: u8>();
5+
6+
impl X<N> {}
7+
//~^ ERROR cannot find type `N` in this scope
8+
//~| ERROR unresolved item provided when a constant was expected
9+
impl<T, const A: u8 = 2> X<N> {}
10+
//~^ ERROR cannot find type `N` in this scope
11+
//~| ERROR defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
12+
//~| ERROR unresolved item provided when a constant was expected
13+
14+
fn bar<const N: u8>(a: A) {}
15+
//~^ ERROR cannot find type `A` in this scope
16+
17+
fn main() {
18+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
error[E0412]: cannot find type `N` in this scope
2+
--> $DIR/missing-type-parameter2.rs:6:8
3+
|
4+
LL | struct X<const N: u8>();
5+
| ------------------------ similarly named struct `X` defined here
6+
LL |
7+
LL | impl X<N> {}
8+
| ^
9+
|
10+
help: a struct with a similar name exists
11+
|
12+
LL | impl X<X> {}
13+
| ^
14+
help: you might be missing a type parameter
15+
|
16+
LL | impl<N> X<N> {}
17+
| ^^^
18+
19+
error[E0412]: cannot find type `N` in this scope
20+
--> $DIR/missing-type-parameter2.rs:9:28
21+
|
22+
LL | impl<T, const A: u8 = 2> X<N> {}
23+
| - ^
24+
| |
25+
| similarly named type parameter `T` defined here
26+
|
27+
help: a type parameter with a similar name exists
28+
|
29+
LL | impl<T, const A: u8 = 2> X<T> {}
30+
| ^
31+
help: you might be missing a type parameter
32+
|
33+
LL | impl<T, const A, N: u8 = 2> X<N> {}
34+
| ^^^
35+
36+
error[E0412]: cannot find type `A` in this scope
37+
--> $DIR/missing-type-parameter2.rs:14:24
38+
|
39+
LL | struct X<const N: u8>();
40+
| ------------------------ similarly named struct `X` defined here
41+
...
42+
LL | fn bar<const N: u8>(a: A) {}
43+
| ^
44+
|
45+
help: a struct with a similar name exists
46+
|
47+
LL | fn bar<const N: u8>(a: X) {}
48+
| ^
49+
help: you might be missing a type parameter
50+
|
51+
LL | fn bar<const N, A: u8>(a: A) {}
52+
| ^^^
53+
54+
error[E0747]: unresolved item provided when a constant was expected
55+
--> $DIR/missing-type-parameter2.rs:6:8
56+
|
57+
LL | impl X<N> {}
58+
| ^
59+
|
60+
help: if this generic argument was intended as a const parameter, surround it with braces
61+
|
62+
LL | impl X<{ N }> {}
63+
| ^ ^
64+
65+
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
66+
--> $DIR/missing-type-parameter2.rs:9:15
67+
|
68+
LL | impl<T, const A: u8 = 2> X<N> {}
69+
| ^
70+
71+
error[E0747]: unresolved item provided when a constant was expected
72+
--> $DIR/missing-type-parameter2.rs:9:28
73+
|
74+
LL | impl<T, const A: u8 = 2> X<N> {}
75+
| ^
76+
|
77+
help: if this generic argument was intended as a const parameter, surround it with braces
78+
|
79+
LL | impl<T, const A: u8 = 2> X<{ N }> {}
80+
| ^ ^
81+
82+
error: aborting due to 6 previous errors
83+
84+
Some errors have detailed explanations: E0412, E0747.
85+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)