From 15888c172db34055f4595dfabdec2bda2f208734 Mon Sep 17 00:00:00 2001 From: Justus Adam Date: Wed, 18 Dec 2024 17:13:46 -0500 Subject: [PATCH] Formatting and clippy --- crates/flowistry_pdg_construction/src/body_cache.rs | 4 ++-- crates/flowistry_pdg_construction/src/construct.rs | 2 +- crates/paralegal-flow/src/ana/inline_judge.rs | 5 ++--- crates/paralegal-flow/src/ana/mod.rs | 4 ++-- crates/paralegal-flow/tests/control_flow_tests.rs | 2 -- crates/paralegal-policy/src/context.rs | 2 +- crates/paralegal-policy/src/test_utils.rs | 6 +++++- crates/paralegal-policy/tests/helpers/mod.rs | 2 +- guide/deletion-policy/Cargo.lock | 1 + guide/deletion-policy/src/main.rs | 6 +++--- 10 files changed, 18 insertions(+), 16 deletions(-) diff --git a/crates/flowistry_pdg_construction/src/body_cache.rs b/crates/flowistry_pdg_construction/src/body_cache.rs index cdc979bdb4..bff59cb0ba 100644 --- a/crates/flowistry_pdg_construction/src/body_cache.rs +++ b/crates/flowistry_pdg_construction/src/body_cache.rs @@ -222,7 +222,7 @@ pub fn dump_mir_and_borrowck_facts<'tcx>(tcx: TyCtxt<'tcx>) -> (Duration, Durati let tc_time = tc_start.elapsed(); let dump_time = Instant::now(); let path = intermediate_out_dir(tcx, INTERMEDIATE_ARTIFACT_EXT); - encode_to_file(tcx, &path, &bodies); + encode_to_file(tcx, path, &bodies); (tc_time, dump_time.elapsed()) } @@ -243,7 +243,7 @@ pub fn local_or_remote_paths(krate: CrateNum, tcx: TyCtxt, ext: &str) -> Vec(tcx: TyCtxt<'tcx>, krate: CrateNum) -> BodyMap<'tcx> { +fn load_body_and_facts(tcx: TyCtxt<'_>, krate: CrateNum) -> BodyMap<'_> { let paths = local_or_remote_paths(krate, tcx, INTERMEDIATE_ARTIFACT_EXT); for path in &paths { if !path.exists() { diff --git a/crates/flowistry_pdg_construction/src/construct.rs b/crates/flowistry_pdg_construction/src/construct.rs index d8795a504b..b6986e6cc7 100644 --- a/crates/flowistry_pdg_construction/src/construct.rs +++ b/crates/flowistry_pdg_construction/src/construct.rs @@ -437,7 +437,7 @@ impl<'tcx> PartialGraph<'tcx> { child_graph .nodes .iter() - .map(move |dest| (ctrl_src.clone(), dest.clone(), edge.clone())) + .map(move |dest| (ctrl_src, *dest, edge)) }), ); self.nodes.extend(child_graph.nodes); diff --git a/crates/paralegal-flow/src/ana/inline_judge.rs b/crates/paralegal-flow/src/ana/inline_judge.rs index 1c6f23bb6d..78964b6b96 100644 --- a/crates/paralegal-flow/src/ana/inline_judge.rs +++ b/crates/paralegal-flow/src/ana/inline_judge.rs @@ -45,9 +45,8 @@ pub enum InlineJudgement { impl Display for InlineJudgement { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(self.as_ref())?; - match self { - Self::AbstractViaType(reason) => write!(f, "({reason})")?, - _ => (), + if let Self::AbstractViaType(reason) = self { + write!(f, "({reason})")?; } Ok(()) } diff --git a/crates/paralegal-flow/src/ana/mod.rs b/crates/paralegal-flow/src/ana/mod.rs index 6a0ab3d970..56acd979da 100644 --- a/crates/paralegal-flow/src/ana/mod.rs +++ b/crates/paralegal-flow/src/ana/mod.rs @@ -236,7 +236,7 @@ impl<'tcx> SPDGGenerator<'tcx> { let analyzed_spans = analyzed_functions .into_iter() - .filter_map(|f| { + .map(|f| { let body = self.pdg_constructor.body_for_def_id(f); let span = body_span(tcx, body.body()); let pspan = src_loc_for_span(span, tcx); @@ -258,7 +258,7 @@ impl<'tcx> SPDGGenerator<'tcx> { FunctionHandling::Elided }; - Some((f, (pspan, handling))) + (f, (pspan, handling)) }) .collect::(); diff --git a/crates/paralegal-flow/tests/control_flow_tests.rs b/crates/paralegal-flow/tests/control_flow_tests.rs index a5eb377de1..913aa23b64 100644 --- a/crates/paralegal-flow/tests/control_flow_tests.rs +++ b/crates/paralegal-flow/tests/control_flow_tests.rs @@ -2,8 +2,6 @@ #[macro_use] extern crate lazy_static; -use std::fs::File; - use paralegal_flow::test_utils::*; const CRATE_DIR: &str = "tests/control-flow-tests"; diff --git a/crates/paralegal-policy/src/context.rs b/crates/paralegal-policy/src/context.rs index 0028d041bb..a26881edcf 100644 --- a/crates/paralegal-policy/src/context.rs +++ b/crates/paralegal-policy/src/context.rs @@ -583,7 +583,7 @@ impl RootContext { self.desc .def_info .iter() - .filter(|(did, _)| self.desc.analyzed_spans.contains_key(&did)) + .filter(|(did, _)| self.desc.analyzed_spans.contains_key(did)) .map(|(_, i)| (&i.src_info, matches!(i.kind, DefKind::Type))) }) .into_iter() diff --git a/crates/paralegal-policy/src/test_utils.rs b/crates/paralegal-policy/src/test_utils.rs index f5091ea961..71e224aa7e 100644 --- a/crates/paralegal-policy/src/test_utils.rs +++ b/crates/paralegal-policy/src/test_utils.rs @@ -29,7 +29,11 @@ pub fn get_callsite_or_datasink_node<'a>( .unwrap() } -pub fn get_callsite_node<'a>(ctx: &'a RootContext, controller: Endpoint, name: &'a str) -> NodeCluster { +pub fn get_callsite_node<'a>( + ctx: &'a RootContext, + controller: Endpoint, + name: &'a str, +) -> NodeCluster { let name = Identifier::new_intern(name); let ctrl = &ctx.desc().controllers[&controller]; let inner = ctrl diff --git a/crates/paralegal-policy/tests/helpers/mod.rs b/crates/paralegal-policy/tests/helpers/mod.rs index 782b963575..b3eba63a7f 100644 --- a/crates/paralegal-policy/tests/helpers/mod.rs +++ b/crates/paralegal-policy/tests/helpers/mod.rs @@ -11,7 +11,7 @@ use std::{ use anyhow::anyhow; pub use anyhow::{ensure, Result}; -use paralegal_policy::{RootContext, GraphLocation}; +use paralegal_policy::{GraphLocation, RootContext}; lazy_static::lazy_static! { static ref TOOL_BUILT: PathBuf = { diff --git a/guide/deletion-policy/Cargo.lock b/guide/deletion-policy/Cargo.lock index 8487126b5e..b7707e8acb 100644 --- a/guide/deletion-policy/Cargo.lock +++ b/guide/deletion-policy/Cargo.lock @@ -434,6 +434,7 @@ name = "paralegal-policy" version = "0.1.0" dependencies = [ "anyhow", + "autocfg", "bitvec", "colored 1.9.4", "indexical", diff --git a/guide/deletion-policy/src/main.rs b/guide/deletion-policy/src/main.rs index 02a112e244..59b6410dfa 100644 --- a/guide/deletion-policy/src/main.rs +++ b/guide/deletion-policy/src/main.rs @@ -1,10 +1,10 @@ use anyhow::Result; use paralegal_policy::{ - assert_error, paralegal_spdg::traverse::EdgeSelection, Context, Marker, NodeExt, + assert_error, paralegal_spdg::traverse::EdgeSelection, Marker, NodeExt, RootContext, }; use std::sync::Arc; -fn dummy_policy(_ctx: Arc) -> Result<()> { +fn dummy_policy(_ctx: Arc) -> Result<()> { println!("Graph loaded."); Ok(()) } @@ -20,7 +20,7 @@ fn main() -> Result<()> { } #[allow(dead_code)] -fn deletion_policy(ctx: Arc) -> Result<()> { +fn deletion_policy(ctx: Arc) -> Result<()> { let user_data_types = ctx.marked_type(Marker::new_intern("user_data")); let found = ctx.all_controllers().any(|(deleter_id, _ignored)| {