Auto merge of #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 ```
This commit is contained in:
commit
9f2852f9a2
@ -691,6 +691,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
|
||||
false,
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
let handler = Handler::with_emitter(false, None, Box::new(emitter));
|
||||
let sess = ParseSess::with_span_handler(handler, sm);
|
||||
|
@ -179,6 +179,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||
false,
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
));
|
||||
let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
|
||||
|
||||
|
12
tests/ui/track-diagnostics.rs
Normal file
12
tests/ui/track-diagnostics.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// compile-flags: -Z track-diagnostics
|
||||
// error-pattern: created at
|
||||
|
||||
// Normalize the emitted location so this doesn't need
|
||||
// updating everytime someone adds or removes a line.
|
||||
// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:LL:CC"
|
||||
|
||||
struct A;
|
||||
struct B;
|
||||
const S: A = B;
|
||||
|
||||
fn main() {}
|
10
tests/ui/track-diagnostics.stderr
Normal file
10
tests/ui/track-diagnostics.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/track-diagnostics.rs:LL:CC
|
||||
|
|
||||
LL | const S: A = B;
|
||||
| ^ expected struct `A`, found struct `B`
|
||||
-Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:LL:CC
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
x
Reference in New Issue
Block a user