]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/const-no-type.rs
Rollup merge of #106805 - madsravn:master, r=compiler-errors
[rust.git] / tests / ui / suggestions / const-no-type.rs
1 // In the cases below, the type is missing from the `const` and `static` items.
2 //
3 // Here, we test that we:
4 //
5 // a) Perform parser recovery.
6 //
7 // b) Emit a diagnostic with the actual inferred type to RHS of `=` as the suggestion.
8
9 fn main() {}
10
11 // These will not reach typeck:
12
13 #[cfg(FALSE)]
14 const C2 = 42;
15 //~^ ERROR missing type for `const` item
16 //~| HELP provide a type for the item
17 //~| SUGGESTION : <type>
18
19 #[cfg(FALSE)]
20 static S2 = "abc";
21 //~^ ERROR missing type for `static` item
22 //~| HELP provide a type for the item
23 //~| SUGGESTION : <type>
24
25 #[cfg(FALSE)]
26 static mut SM2 = "abc";
27 //~^ ERROR missing type for `static mut` item
28 //~| HELP provide a type for the item
29 //~| SUGGESTION : <type>
30
31 // These will, so the diagnostics should be stolen by typeck:
32
33 const C = 42;
34 //~^ ERROR missing type for `const` item
35 //~| HELP provide a type for the constant
36 //~| SUGGESTION : i32
37
38 const D = &&42;
39 //~^ ERROR missing type for `const` item
40 //~| HELP provide a type for the constant
41 //~| SUGGESTION : &&i32
42
43 static S = Vec::<String>::new();
44 //~^ ERROR missing type for `static` item
45 //~| HELP provide a type for the static variable
46 //~| SUGGESTION : Vec<String>
47
48 static mut SM = "abc";
49 //~^ ERROR missing type for `static mut` item
50 //~| HELP provide a type for the static variable
51 //~| SUGGESTION : &str