Skip to content

Commit 1b220ea

Browse files
committed
const_items_unit_type_default: bless tests
1 parent d1e4d9a commit 1b220ea

17 files changed

+115
-84
lines changed

tests/ui/consts/missing_assoc_const_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ trait Range {
99

1010
struct TwoDigits;
1111
impl Range for TwoDigits {
12-
const FIRST: = 10; //~ ERROR missing type for `const` item
12+
const FIRST: _ = 10;
13+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121]
1314
const LAST: u8 = 99;
1415
}
1516

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
error: missing type for `const` item
2-
--> $DIR/missing_assoc_const_type.rs:12:17
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
2+
--> $DIR/missing_assoc_const_type.rs:12:18
3+
|
4+
LL | const FIRST: _ = 10;
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace this with a fully-specified type
8+
|
9+
LL - const FIRST: _ = 10;
10+
LL + const FIRST: u8 = 10;
311
|
4-
LL | const FIRST: = 10;
5-
| ^ help: provide a type for the associated constant: `u8`
612

713
error: aborting due to 1 previous error
814

15+
For more information about this error, try `rustc --explain E0121`.

tests/ui/consts/missing_assoc_const_type2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ trait Range {
99

1010
struct TwoDigits;
1111
impl Range for TwoDigits {
12-
const FIRST: = 10;
13-
//~^ ERROR: missing type
12+
const FIRST: _ = 10;
13+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121]
1414
const LAST: u8 = 99;
1515
}
1616

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
error: missing type for `const` item
2-
--> $DIR/missing_assoc_const_type2.rs:12:17
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
2+
--> $DIR/missing_assoc_const_type2.rs:12:18
3+
|
4+
LL | const FIRST: _ = 10;
5+
| ^ not allowed in type signatures
6+
|
7+
help: replace this with a fully-specified type
8+
|
9+
LL - const FIRST: _ = 10;
10+
LL + const FIRST: u8 = 10;
311
|
4-
LL | const FIRST: = 10;
5-
| ^ help: provide a type for the associated constant: `u8`
612

713
error: aborting due to 1 previous error
814

15+
For more information about this error, try `rustc --explain E0121`.

tests/ui/generic-const-items/assoc-const-missing-type.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ trait Trait {
1010

1111
impl Trait for () {
1212
const K<T> = ();
13-
//~^ ERROR missing type for `const` item
14-
//~| ERROR mismatched types
13+
//~^ ERROR omitting type on const item declaration is experimental [E0658]
14+
//~| ERROR implemented const `K` has an incompatible type for trait [E0326]
1515
const Q = "";
16-
//~^ ERROR missing type for `const` item
16+
//~^ ERROR omitting type on const item declaration is experimental [E0658]
1717
//~| ERROR lifetime parameters or bounds on associated const `Q` do not match the trait declaration
18+
//~| ERROR mismatched types
1819
}
1920

2021
fn main() {}
Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/assoc-const-missing-type.rs:12:18
1+
error[E0658]: omitting type on const item declaration is experimental
2+
--> $DIR/assoc-const-missing-type.rs:12:15
33
|
44
LL | const K<T> = ();
5-
| - ^^ expected type parameter `T`, found `()`
6-
| |
7-
| expected this type parameter
5+
| ^
86
|
9-
= note: expected type parameter `T`
10-
found unit type `()`
7+
= note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
8+
= help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= help: consider specifying the type explicitly
1111

12-
error: missing type for `const` item
12+
error[E0658]: omitting type on const item declaration is experimental
13+
--> $DIR/assoc-const-missing-type.rs:15:12
14+
|
15+
LL | const Q = "";
16+
| ^
17+
|
18+
= note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
19+
= help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
20+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
21+
= help: consider specifying the type explicitly
22+
23+
error[E0326]: implemented const `K` has an incompatible type for trait
1324
--> $DIR/assoc-const-missing-type.rs:12:15
1425
|
1526
LL | const K<T> = ();
16-
| ^ help: provide a type for the associated constant: `()`
27+
| - ^ expected type parameter `T`, found `()`
28+
| |
29+
| expected this type parameter
30+
|
31+
note: type in trait
32+
--> $DIR/assoc-const-missing-type.rs:7:17
33+
|
34+
LL | const K<T>: T;
35+
| ^
36+
= note: expected type parameter `T`
37+
found unit type `()`
1738

1839
error[E0195]: lifetime parameters or bounds on associated const `Q` do not match the trait declaration
1940
--> $DIR/assoc-const-missing-type.rs:15:12
@@ -24,13 +45,13 @@ LL | const Q<'a>: &'a str;
2445
LL | const Q = "";
2546
| ^ lifetimes do not match associated const in trait
2647

27-
error: missing type for `const` item
28-
--> $DIR/assoc-const-missing-type.rs:15:12
48+
error[E0308]: mismatched types
49+
--> $DIR/assoc-const-missing-type.rs:15:15
2950
|
3051
LL | const Q = "";
31-
| ^ help: provide a type for the associated constant: `: &str`
52+
| ^^ expected `()`, found `&str`
3253

33-
error: aborting due to 4 previous errors
54+
error: aborting due to 5 previous errors
3455

35-
Some errors have detailed explanations: E0195, E0308.
56+
Some errors have detailed explanations: E0195, E0308, E0326, E0658.
3657
For more information about an error, try `rustc --explain E0195`.

tests/ui/macros/issue-69396-const-no-type-in-macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
macro_rules! suite {
22
( $( $fn:ident; )* ) => {
33
$(
4-
const A = "A".$fn();
4+
static A = "A".$fn();
55
//~^ ERROR the name `A` is defined multiple times
6-
//~| ERROR missing type for `const` item
6+
//~| ERROR missing type for `static` item
77
//~| ERROR missing type for item
88
)*
99
}

tests/ui/macros/issue-69396-const-no-type-in-macro.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0428]: the name `A` is defined multiple times
22
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:13
33
|
4-
LL | const A = "A".$fn();
5-
| ^^^^^^^^^^^^^^^^^^^^ `A` redefined here
4+
LL | static A = "A".$fn();
5+
| ^^^^^^^^^^^^^^^^^^^^^ `A` redefined here
66
...
77
LL | / suite! {
88
LL | | len;
@@ -13,11 +13,11 @@ LL | | }
1313
= note: `A` must be defined only once in the value namespace of this module
1414
= note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info)
1515

16-
error: missing type for `const` item
17-
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:20
16+
error: missing type for `static` item
17+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:21
1818
|
19-
LL | const A = "A".$fn();
20-
| ^ help: provide a type for the constant: `: usize`
19+
LL | static A = "A".$fn();
20+
| ^ help: provide a type for the static variable: `: usize`
2121
...
2222
LL | / suite! {
2323
LL | | len;
@@ -28,10 +28,10 @@ LL | | }
2828
= note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info)
2929

3030
error[E0121]: missing type for item
31-
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:20
31+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:21
3232
|
33-
LL | const A = "A".$fn();
34-
| ^ not allowed in type signatures
33+
LL | static A = "A".$fn();
34+
| ^ not allowed in type signatures
3535
...
3636
LL | / suite! {
3737
LL | | len;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
2-
const EMPTY_ARRAY = [];
3-
//~^ ERROR missing type for `const` item
2+
const EMPTY_ARRAY: _ = [];
3+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants [E0121]
44
//~| ERROR type annotations needed
55
}
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/issue-89574.rs:2:25
2+
--> $DIR/issue-89574.rs:2:28
33
|
4-
LL | const EMPTY_ARRAY = [];
5-
| ^^ cannot infer type
4+
LL | const EMPTY_ARRAY: _ = [];
5+
| ^^ cannot infer type
66

7-
error: missing type for `const` item
8-
--> $DIR/issue-89574.rs:2:22
7+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
8+
--> $DIR/issue-89574.rs:2:24
99
|
10-
LL | const EMPTY_ARRAY = [];
11-
| ^
12-
|
13-
help: provide a type for the item
14-
|
15-
LL | const EMPTY_ARRAY: <type> = [];
16-
| ++++++++
10+
LL | const EMPTY_ARRAY: _ = [];
11+
| ^ not allowed in type signatures
1712

1813
error: aborting due to 2 previous errors
1914

20-
For more information about this error, try `rustc --explain E0282`.
15+
Some errors have detailed explanations: E0121, E0282.
16+
For more information about an error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)