Skip to content

Commit 2e81955

Browse files
committed
compiletest: Support matching on diagnostics without a span
1 parent 8194ffc commit 2e81955

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Diff for: src/tests/ui.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ several ways to match the message with the line (see the examples below):
202202
* `~|`: Associates the error level and message with the *same* line as the
203203
*previous comment*. This is more convenient than using multiple carets when
204204
there are multiple messages associated with the same line.
205+
* `~?`: Used to match error levels and messages with errors not having line
206+
information. These can be placed on any line in the test file, but are
207+
conventionally placed at the end.
205208

206209
Example:
207210

@@ -270,10 +273,23 @@ fn main() {
270273
//~| ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields [E0023]
271274
```
272275

276+
#### Error without line information
277+
278+
Use `//~?` to match an error without line information.
279+
`//~?` is precise and will not match errors if their line information is available.
280+
It should be preferred to using `error-pattern`, which is imprecise and non-exhaustive.
281+
282+
```rust,ignore
283+
//@ compile-flags: --print yyyy
284+
285+
//~? ERROR unknown print request: `yyyy`
286+
```
287+
273288
### `error-pattern`
274289

275-
The `error-pattern` [directive](directives.md) can be used for messages that don't
276-
have a specific span.
290+
The `error-pattern` [directive](directives.md) can be used for runtime messages, which don't
291+
have a specific span, or for compile time messages if imprecise matching is required due to
292+
multi-line platform specific diagnostics.
277293

278294
Let's think about this test:
279295

@@ -300,7 +316,9 @@ fn main() {
300316
}
301317
```
302318

303-
But for strict testing, try to use the `ERROR` annotation as much as possible.
319+
But for strict testing, try to use the `ERROR` annotation as much as possible,
320+
including `//~?` annotations for diagnostics without span.
321+
For compile time diagnostics `error-pattern` should very rarely be necessary.
304322

305323
### Error levels
306324

@@ -353,7 +371,7 @@ would be a `.mir.stderr` and `.thir.stderr` file with the different outputs of
353371
the different revisions.
354372

355373
> Note: cfg revisions also work inside the source code with `#[cfg]` attributes.
356-
>
374+
>
357375
> By convention, the `FALSE` cfg is used to have an always-false config.
358376
359377
## Controlling pass/fail expectations

0 commit comments

Comments
 (0)