File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,40 @@ stack backtrace:
185
185
186
186
Cool, now I have a backtrace for the error!
187
187
188
+ # # Getting the the error creation location
189
+
190
+ ` -Z track-diagnostics` can help figure out where errors are emitted. It uses ` # [track_caller]`
191
+ for this and prints its location alongside the error:
192
+
193
+ ` ` ` bash
194
+ $ RUST_BACKTRACE=1 rustc +stage1 error.rs -Z track-diagnostics
195
+ error[E0277]: cannot add ` ()` to ` {integer}`
196
+ --> src\e rror.rs:2:7
197
+ |
198
+ 2 | 1 + ();
199
+ | ^ no implementation for ` {integer} + ()`
200
+ -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:638:39
201
+ |
202
+ = help: the trait ` Add<( ) > ` is not implemented for ` {integer}`
203
+ = help: the following other types implement trait ` Add< Rhs> ` :
204
+ < & ' a f32 as Add<f32>>
205
+ <&' a f64 as Add< f64>>
206
+ < & ' a i128 as Add<i128>>
207
+ <&' a i16 as Add< i16>>
208
+ < & ' a i32 as Add<i32>>
209
+ <&' a i64 as Add< i64>>
210
+ < & ' a i8 as Add<i8>>
211
+ <&' a isize as Add< isize>>
212
+ and 48 others
213
+
214
+ For more information about this error, try ` rustc --explain E0277` .
215
+ ` ` `
216
+
217
+ This is similar but different to ` -Z treat-err-as-bug` :
218
+ - it will print the locations for all errors emitted
219
+ - it does not require a compiler built with debug symbols
220
+ - you don' t have to read through a big stack trace.
221
+
188
222
## Getting logging output
189
223
190
224
The compiler uses the [`tracing`] crate for logging.
Original file line number Diff line number Diff line change @@ -269,7 +269,7 @@ book][rustc-lint-levels] and the [reference][reference-diagnostics].
269
269
270
270
### Finding the source of errors
271
271
272
- There are two main ways to find where a given error is emitted:
272
+ There are three main ways to find where a given error is emitted:
273
273
274
274
- ` grep ` for either a sub-part of the error message/label or error code. This
275
275
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:
287
287
- The _ construction_ of the error is far away from where it is _ emitted_ ,
288
288
a problem similar to the one we faced with the ` grep ` approach.
289
289
In some cases, we buffer multiple errors in order to emit them in order.
290
+ - Invoking ` rustc ` with the nightly-only flag ` -Z track-diagnostics ` will print error creation
291
+ locations alongside the error.
290
292
291
293
The regular development practices apply: judicious use of ` debug!() ` statements
292
294
and use of a debugger to trigger break points in order to figure out in what
You can’t perform that action at this time.
0 commit comments