Add -Ztrack-diagnostics information
This commit is contained in:
parent
58077bf772
commit
a213de4efe
|
|
@ -185,6 +185,40 @@ stack backtrace:
|
||||||
|
|
||||||
Cool, now I have a backtrace for the error!
|
Cool, now I have a backtrace for the error!
|
||||||
|
|
||||||
|
## Getting the the error creation location
|
||||||
|
|
||||||
|
`-Z track-diagnostics` can help figure out where errors are emitted. It uses `#[track_caller]`
|
||||||
|
for this and prints its location alongside the error:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ RUST_BACKTRACE=1 rustc +stage1 error.rs -Z track-diagnostics
|
||||||
|
error[E0277]: cannot add `()` to `{integer}`
|
||||||
|
--> src\error.rs:2:7
|
||||||
|
|
|
||||||
|
2 | 1 + ();
|
||||||
|
| ^ no implementation for `{integer} + ()`
|
||||||
|
-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:638:39
|
||||||
|
|
|
||||||
|
= help: the trait `Add<()>` is not implemented for `{integer}`
|
||||||
|
= help: the following other types implement trait `Add<Rhs>`:
|
||||||
|
<&'a f32 as Add<f32>>
|
||||||
|
<&'a f64 as Add<f64>>
|
||||||
|
<&'a i128 as Add<i128>>
|
||||||
|
<&'a i16 as Add<i16>>
|
||||||
|
<&'a i32 as Add<i32>>
|
||||||
|
<&'a i64 as Add<i64>>
|
||||||
|
<&'a i8 as Add<i8>>
|
||||||
|
<&'a isize as Add<isize>>
|
||||||
|
and 48 others
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
```
|
||||||
|
|
||||||
|
This is similar but different to `-Z treat-err-as-bug`:
|
||||||
|
- it will print the locations for all errors emitted
|
||||||
|
- it does not require a compiler built with debug symbols
|
||||||
|
- you don't have to read through a big stack trace.
|
||||||
|
|
||||||
## Getting logging output
|
## Getting logging output
|
||||||
|
|
||||||
The compiler uses the [`tracing`] crate for logging.
|
The compiler uses the [`tracing`] crate for logging.
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ book][rustc-lint-levels] and the [reference][reference-diagnostics].
|
||||||
|
|
||||||
### Finding the source of errors
|
### Finding the source of errors
|
||||||
|
|
||||||
There are two main ways to find where a given error is emitted:
|
There are three main ways to find where a given error is emitted:
|
||||||
|
|
||||||
- `grep` for either a sub-part of the error message/label or error code. This
|
- `grep` for either a sub-part of the error message/label or error code. This
|
||||||
usually works well and is straightforward, but there are some cases where
|
usually works well and is straightforward, but there are some cases where
|
||||||
|
|
@ -287,6 +287,8 @@ There are two main ways to find where a given error is emitted:
|
||||||
- The _construction_ of the error is far away from where it is _emitted_,
|
- The _construction_ of the error is far away from where it is _emitted_,
|
||||||
a problem similar to the one we faced with the `grep` approach.
|
a problem similar to the one we faced with the `grep` approach.
|
||||||
In some cases, we buffer multiple errors in order to emit them in order.
|
In some cases, we buffer multiple errors in order to emit them in order.
|
||||||
|
- Invoking `rustc` with the nightly-only flag `-Z track-diagnostics` will print error creation
|
||||||
|
locations alongside the error.
|
||||||
|
|
||||||
The regular development practices apply: judicious use of `debug!()` statements
|
The regular development practices apply: judicious use of `debug!()` statements
|
||||||
and use of a debugger to trigger break points in order to figure out in what
|
and use of a debugger to trigger break points in order to figure out in what
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue