summary refs log tree commit diff
path: root/tests/coverage/partial_eq.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-11-01 21:26:53 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-11-07 11:15:19 +1100
commite9d04c5e2444526ffde83662f2d57fa35c772891 (patch)
tree6dbc04c3253992f8968d5914d7b1c631db528892 /tests/coverage/partial_eq.rs
parentaea7c27eae5e34b11c64ec6d11c75627ef24f8b1 (diff)
downloadrust-e9d04c5e2444526ffde83662f2d57fa35c772891.tar.gz
rust-e9d04c5e2444526ffde83662f2d57fa35c772891.zip
coverage: Migrate `tests/run-coverage` into `tests/coverage`
Diffstat (limited to 'tests/coverage/partial_eq.rs')
-rw-r--r--tests/coverage/partial_eq.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/coverage/partial_eq.rs b/tests/coverage/partial_eq.rs
new file mode 100644
index 00000000000..dd8b42c18ce
--- /dev/null
+++ b/tests/coverage/partial_eq.rs
@@ -0,0 +1,46 @@
+// This test confirms an earlier problem was resolved, supporting the MIR graph generated by the
+// structure of this test.
+
+#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
+pub struct Version {
+    major: usize,
+    minor: usize,
+    patch: usize,
+}
+
+impl Version {
+    pub fn new(major: usize, minor: usize, patch: usize) -> Self {
+        Self {
+            major,
+            minor,
+            patch,
+        }
+    }
+}
+
+fn main() {
+    let version_3_2_1 = Version::new(3, 2, 1);
+    let version_3_3_0 = Version::new(3, 3, 0);
+
+    println!("{:?} < {:?} = {}", version_3_2_1, version_3_3_0, version_3_2_1 < version_3_3_0);
+}
+
+/*
+
+This test verifies a bug was fixed that otherwise generated this error:
+
+thread 'rustc' panicked at 'No counters provided the source_hash for function:
+    Instance {
+        def: Item(WithOptConstParam {
+            did: DefId(0:101 ~ autocfg[c44a]::version::{impl#2}::partial_cmp),
+            const_param_did: None
+        }),
+        args: []
+    }'
+The `PartialOrd` derived by `Version` happened to generate a MIR that generated coverage
+without a code region associated with any `Counter`. Code regions were associated with at least
+one expression, which is allowed, but the `function_source_hash` was only passed to the codegen
+(coverage mapgen) phase from a `Counter`s code region. A new method was added to pass the
+`function_source_hash` without a code region, if necessary.
+
+*/