about summary refs log tree commit diff
path: root/compiler/rustc_mir_dataflow/src/framework/mod.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-11-18 16:04:03 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-11-26 11:23:40 +1100
commitbe7c6a3b43a8d200ba29f5a768e32287bb95aec2 (patch)
treeceab40e23c07c861a0188fedec772669fa5c332d /compiler/rustc_mir_dataflow/src/framework/mod.rs
parent1914dbe69465132a545fbc4cd0400a02a56a8a77 (diff)
downloadrust-be7c6a3b43a8d200ba29f5a768e32287bb95aec2.tar.gz
rust-be7c6a3b43a8d200ba29f5a768e32287bb95aec2.zip
Make it possible for `ResultsCursor` to borrow a `Results`.
`ResultsCursor` currently owns its `Results`. But sometimes the
`Results` is needed again afterwards. So there is
`ResultsCursor::into_results` for extracting the `Results`, which leads
to some awkwardness.

This commit adds `ResultsHandle`, a `Cow`-like type that can either
borrow or own a a `Results`. `ResultsCursor` now uses it. This is good
because some `ResultsCursor`s really want to own their `Results`, while
others just want to borrow it.

We end with with a few more lines of code, but get some nice cleanups.
- `ResultsCursor::into_results` and `Formatter::into_results` are
  removed.
- `write_graphviz_results` now just borrows a `Results`, instead of the
  awkward "take ownership of a `Results` and then return it unchanged"
  pattern.

This reinstates the cursor flexibility that was lost in #118230 -- which
removed the old `ResultsRefCursor` and `ResultsCloneCursor` types -- but
in a much simpler way. Hooray!
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/framework/mod.rs')
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/mod.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/compiler/rustc_mir_dataflow/src/framework/mod.rs b/compiler/rustc_mir_dataflow/src/framework/mod.rs
index f9e7ba743fc..88bab250781 100644
--- a/compiler/rustc_mir_dataflow/src/framework/mod.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/mod.rs
@@ -302,14 +302,13 @@ pub trait Analysis<'tcx> {
         let results = Results { analysis: self, entry_sets };
 
         if tcx.sess.opts.unstable_opts.dump_mir_dataflow {
-            let (res, results) = write_graphviz_results(tcx, body, results, pass_name);
+            let res = write_graphviz_results(tcx, body, &results, pass_name);
             if let Err(e) = res {
                 error!("Failed to write graphviz dataflow results: {}", e);
             }
-            results
-        } else {
-            results
         }
+
+        results
     }
 }