Skip to content

Commit 9f2852f

Browse files
committed
Auto merge of rust-lang#103217 - mejrs:track, r=eholk
Track where diagnostics were created. This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`. For example, the following code... ```rust struct A; struct B; fn main(){ let _: A = B; } ``` ...now emits the following error message: ``` error[E0308]: mismatched types --> src\main.rs:5:16 | 5 | let _: A = B; | - ^ expected struct `A`, found struct `B` | | | expected due to this -Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31 ```
2 parents 16566e9 + 4b1cebb commit 9f2852f

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

clippy_lints/src/doc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
691691
false,
692692
None,
693693
false,
694+
false,
694695
);
695696
let handler = Handler::with_emitter(false, None, Box::new(emitter));
696697
let sess = ParseSess::with_span_handler(handler, sm);

src/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
179179
false,
180180
None,
181181
false,
182+
false,
182183
));
183184
let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
184185

tests/ui/track-diagnostics.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Z track-diagnostics
2+
// error-pattern: created at
3+
4+
// Normalize the emitted location so this doesn't need
5+
// updating everytime someone adds or removes a line.
6+
// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:LL:CC"
7+
8+
struct A;
9+
struct B;
10+
const S: A = B;
11+
12+
fn main() {}

tests/ui/track-diagnostics.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/track-diagnostics.rs:LL:CC
3+
|
4+
LL | const S: A = B;
5+
| ^ expected struct `A`, found struct `B`
6+
-Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:LL:CC
7+
8+
error: aborting due to previous error
9+
10+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)