]> git.lizzy.rs Git - rust.git/blob - src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.rs
Rollup merge of #100559 - nnethercote:parser-simplifications, r=compiler-errors
[rust.git] / src / test / ui / resolve / suggest-path-instead-of-mod-dot-item.rs
1 // Beginners write `mod.item` when they should write `mod::item`.
2 // This tests that we suggest the latter when we encounter the former.
3
4 pub mod a {
5     pub const I: i32 = 1;
6
7     pub fn f() -> i32 { 2 }
8
9     pub mod b {
10         pub const J: i32 = 3;
11
12         pub fn g() -> i32 { 4 }
13     }
14 }
15
16 fn h1() -> i32 {
17     a.I
18     //~^ ERROR expected value, found module `a`
19     //~| HELP use the path separator
20 }
21
22 fn h2() -> i32 {
23     a.g()
24     //~^ ERROR expected value, found module `a`
25     //~| HELP use the path separator
26 }
27
28 fn h3() -> i32 {
29     a.b.J
30     //~^ ERROR expected value, found module `a`
31     //~| HELP use the path separator
32 }
33
34 fn h4() -> i32 {
35     a::b.J
36     //~^ ERROR expected value, found module `a::b`
37     //~| HELP a constant with a similar name exists
38     //~| HELP use the path separator
39 }
40
41 fn h5() {
42     a.b.f();
43     //~^ ERROR expected value, found module `a`
44     //~| HELP use the path separator
45     let v = Vec::new();
46     v.push(a::b);
47     //~^ ERROR expected value, found module `a::b`
48     //~| HELP a constant with a similar name exists
49 }
50
51 fn h6() -> i32 {
52     a::b.f()
53     //~^ ERROR expected value, found module `a::b`
54     //~| HELP a constant with a similar name exists
55     //~| HELP use the path separator
56 }
57
58 fn h7() {
59     a::b
60     //~^ ERROR expected value, found module `a::b`
61     //~| HELP a constant with a similar name exists
62 }
63
64 fn h8() -> i32 {
65     a::b()
66     //~^ ERROR expected function, found module `a::b`
67     //~| HELP a constant with a similar name exists
68 }
69
70 macro_rules! module {
71     () => {
72         a
73         //~^ ERROR expected value, found module `a`
74         //~| ERROR expected value, found module `a`
75     };
76 }
77
78 macro_rules! create {
79     (method) => {
80         a.f()
81         //~^ ERROR expected value, found module `a`
82         //~| HELP use the path separator
83     };
84     (field) => {
85         a.f
86         //~^ ERROR expected value, found module `a`
87         //~| HELP use the path separator
88     };
89 }
90
91 fn h9() {
92     //
93     // Note that if the receiver is a macro call, we do not want to suggest to replace
94     // `.` with `::` as that would be a syntax error.
95     // Since the receiver is a module and not a type, we cannot suggest to surround
96     // it with angle brackets.
97     //
98
99     module!().g::<()>(); // no `help` here!
100
101     module!().g; // no `help` here!
102
103     //
104     // Ensure that the suggestion is shown for expressions inside of macro definitions.
105     //
106
107     let _ = create!(method);
108     let _ = create!(field);
109 }
110
111 fn main() {}