about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-01 21:09:45 +0000
committerbors <bors@rust-lang.org>2022-11-01 21:09:45 +0000
commit11ebe6512b4c77633c59f8dcdd421df3b79d1a9f (patch)
tree1a36082800b7ea78becadcc3442c3241108ec70d /src/tools
parentab5a2bc7316012ee9b2a4a4f3821673f2677f3d5 (diff)
parentcbeb244b0588f8d442514a2b7ab95a6021f9863f (diff)
downloadrust-11ebe6512b4c77633c59f8dcdd421df3b79d1a9f.tar.gz
rust-11ebe6512b4c77633c59f8dcdd421df3b79d1a9f.zip
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
```
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/clippy/clippy_lints/src/doc.rs1
-rw-r--r--src/tools/clippy/src/driver.rs1
-rw-r--r--src/tools/clippy/tests/ui/track-diagnostics.rs12
-rw-r--r--src/tools/clippy/tests/ui/track-diagnostics.stderr10
-rw-r--r--src/tools/rustfmt/src/parse/session.rs1
5 files changed, 25 insertions, 0 deletions
diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs
index 24d6a6951af..daaab79fef9 100644
--- a/src/tools/clippy/clippy_lints/src/doc.rs
+++ b/src/tools/clippy/clippy_lints/src/doc.rs
@@ -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);
diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs
index b12208ac62a..ae54b2078a6 100644
--- a/src/tools/clippy/src/driver.rs
+++ b/src/tools/clippy/src/driver.rs
@@ -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);
 
diff --git a/src/tools/clippy/tests/ui/track-diagnostics.rs b/src/tools/clippy/tests/ui/track-diagnostics.rs
new file mode 100644
index 00000000000..fa9221ed02d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/track-diagnostics.rs
@@ -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() {}
diff --git a/src/tools/clippy/tests/ui/track-diagnostics.stderr b/src/tools/clippy/tests/ui/track-diagnostics.stderr
new file mode 100644
index 00000000000..ec303186253
--- /dev/null
+++ b/src/tools/clippy/tests/ui/track-diagnostics.stderr
@@ -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`.
diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs
index 6efeee98fea..6bfec79cd70 100644
--- a/src/tools/rustfmt/src/parse/session.rs
+++ b/src/tools/rustfmt/src/parse/session.rs
@@ -134,6 +134,7 @@ fn default_handler(
             false,
             None,
             false,
+            false,
         ))
     };
     Handler::with_emitter(