]> git.lizzy.rs Git - rust.git/blob - src/librustc_parse/error_codes.rs
Rollup merge of #66257 - mati865:long-section-names-no-more, r=alexcrichton
[rust.git] / src / librustc_parse / error_codes.rs
1 // Error messages for EXXXX errors.
2 // Each message should start and end with a new line, and be wrapped to 80
3 // characters.  In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use
4 // `:set tw=0` to disable.
5 syntax::register_diagnostics! {
6
7 E0178: r##"
8 In types, the `+` type operator has low precedence, so it is often necessary
9 to use parentheses.
10
11 For example:
12
13 ```compile_fail,E0178
14 trait Foo {}
15
16 struct Bar<'a> {
17     w: &'a Foo + Copy,   // error, use &'a (Foo + Copy)
18     x: &'a Foo + 'a,     // error, use &'a (Foo + 'a)
19     y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
20     z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
21 }
22 ```
23
24 More details can be found in [RFC 438].
25
26 [RFC 438]: https://github.com/rust-lang/rfcs/pull/438
27 "##,
28
29 E0583: r##"
30 A file wasn't found for an out-of-line module.
31
32 Erroneous code example:
33
34 ```ignore (compile_fail not working here; see Issue #43707)
35 mod file_that_doesnt_exist; // error: file not found for module
36
37 fn main() {}
38 ```
39
40 Please be sure that a file corresponding to the module exists. If you
41 want to use a module named `file_that_doesnt_exist`, you need to have a file
42 named `file_that_doesnt_exist.rs` or `file_that_doesnt_exist/mod.rs` in the
43 same directory.
44 "##,
45
46 E0584: r##"
47 A doc comment that is not attached to anything has been encountered.
48
49 Erroneous code example:
50
51 ```compile_fail,E0584
52 trait Island {
53     fn lost();
54
55     /// I'm lost!
56 }
57 ```
58
59 A little reminder: a doc comment has to be placed before the item it's supposed
60 to document. So if you want to document the `Island` trait, you need to put a
61 doc comment before it, not inside it. Same goes for the `lost` method: the doc
62 comment needs to be before it:
63
64 ```
65 /// I'm THE island!
66 trait Island {
67     /// I'm lost!
68     fn lost();
69 }
70 ```
71 "##,
72
73 E0585: r##"
74 A documentation comment that doesn't document anything was found.
75
76 Erroneous code example:
77
78 ```compile_fail,E0585
79 fn main() {
80     // The following doc comment will fail:
81     /// This is a useless doc comment!
82 }
83 ```
84
85 Documentation comments need to be followed by items, including functions,
86 types, modules, etc. Examples:
87
88 ```
89 /// I'm documenting the following struct:
90 struct Foo;
91
92 /// I'm documenting the following function:
93 fn foo() {}
94 ```
95 "##,
96
97 E0586: r##"
98 An inclusive range was used with no end.
99
100 Erroneous code example:
101
102 ```compile_fail,E0586
103 fn main() {
104     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
105     let x = &tmp[1..=]; // error: inclusive range was used with no end
106 }
107 ```
108
109 An inclusive range needs an end in order to *include* it. If you just need a
110 start and no end, use a non-inclusive range (with `..`):
111
112 ```
113 fn main() {
114     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
115     let x = &tmp[1..]; // ok!
116 }
117 ```
118
119 Or put an end to your inclusive range:
120
121 ```
122 fn main() {
123     let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
124     let x = &tmp[1..=3]; // ok!
125 }
126 ```
127 "##,
128
129 E0704: r##"
130 This error indicates that a incorrect visibility restriction was specified.
131
132 Example of erroneous code:
133
134 ```compile_fail,E0704
135 mod foo {
136     pub(foo) struct Bar {
137         x: i32
138     }
139 }
140 ```
141
142 To make struct `Bar` only visible in module `foo` the `in` keyword should be
143 used:
144 ```
145 mod foo {
146     pub(in crate::foo) struct Bar {
147         x: i32
148     }
149 }
150 # fn main() {}
151 ```
152
153 For more information see the Rust Reference on [Visibility].
154
155 [Visibility]: https://doc.rust-lang.org/reference/visibility-and-privacy.html
156 "##,
157
158 E0743: r##"
159 C-variadic has been used on a non-foreign function.
160
161 Erroneous code example:
162
163 ```compile_fail,E0743
164 fn foo2(x: u8, ...) {} // error!
165 ```
166
167 Only foreign functions can use C-variadic (`...`). It is used to give an
168 undefined number of parameters to a given function (like `printf` in C). The
169 equivalent in Rust would be to use macros directly.
170 "##,
171
172 ;
173
174 }