@@ -193,15 +193,76 @@ source.
193
193
194
194
Error annotations specify the errors that the compiler is expected to
195
195
emit. They are "attached" to the line in source where the error is
196
- located.
196
+ located. Error annotations are considered during tidy lints of line
197
+ length and should be formatted according to tidy requirements.
198
+
199
+ The error annotation definition and source line definition association
200
+ is defined with the following set of idioms:
197
201
198
202
* ` ~ ` : Associates the following error level and message with the
199
203
current line
200
204
* ` ~| ` : Associates the following error level and message with the same
201
205
line as the previous comment
202
206
* ` ~^ ` : Associates the following error level and message with the
203
- previous line. Each caret (` ^ ` ) that you add adds a line to this, so
204
- ` ~^^^^^^^ ` is seven lines up.
207
+ previous error annotation line. Each caret (` ^ ` ) that you add adds
208
+ a line to this, so ` ~^^^ ` is three lines above the error annotation
209
+ line.
210
+
211
+ ### Error annotation examples
212
+
213
+ Here are examples of error annotations on different lines of UI test
214
+ source.
215
+
216
+ #### Positioned on error line
217
+
218
+ Use the ` //~ ERROR ` idiom:
219
+
220
+ ``` rust,ignore
221
+ fn main() {
222
+ let x = (1, 2, 3);
223
+ match x {
224
+ (_a, _x @ ..) => {} //~ ERROR `_x @` is not allowed in a tuple
225
+ _ => {}
226
+ }
227
+ }
228
+ ```
229
+
230
+ #### Positioned below error line
231
+
232
+ Use the ` //~^ ` idiom with number of carets in the string to indicate the
233
+ number of lines above. In the example below, the error line is four
234
+ lines above the error annotation line so four carets are included in
235
+ the annotation.
236
+
237
+ ``` rust,ignore
238
+ fn main() {
239
+ let x = (1, 2, 3);
240
+ match x {
241
+ (_a, _x @ ..) => {} // <- the error is on this line
242
+ _ => {}
243
+ }
244
+ }
245
+ //~^^^^ ERROR `_x @` is not allowed in a tuple
246
+ ```
247
+
248
+ #### Use same error line as defined on error annotation line above
249
+
250
+ Use the ` //~| ` idiom to define the same error line as
251
+ the error annotation line above:
252
+
253
+ ``` rust,ignore
254
+ struct Binder(i32, i32, i32);
255
+
256
+ fn main() {
257
+ let x = Binder(1, 2, 3);
258
+ match x {
259
+ Binder(_a, _x @ ..) => {} // <- the error is on this line
260
+ _ => {}
261
+ }
262
+ }
263
+ //~^^^^ ERROR `_x @` is not allowed in a tuple struct
264
+ //~| ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields [E0023]
265
+ ```
205
266
206
267
The error levels that you can have are:
207
268
0 commit comments