Skip to content

Commit

Permalink
Clippy is such a pedant
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Jan 1, 2025
1 parent 24950f1 commit ff81ab7
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 44 deletions.
21 changes: 7 additions & 14 deletions crates/aquascope/src/analysis/boundaries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ fn select_candidate_location<'tcx>(

let others = subtract_from();
// Remove all candidates present in the subtraction set.
let candidates = candidates.into_iter().filter(|t| !others.contains(t));
let candidates = candidates.iter().filter(|t| !others.contains(t));

// From the list of local places sorted by similarity to the given `HirId`,
// pick the first one that matches the base local.
Expand Down Expand Up @@ -638,7 +638,7 @@ fn paths_at_hir_id<'tcx>(
}

Rvalue::Aggregate(_, fields) => {
fields.iter().flat_map(|op| maybe_in_op(tcx, body, loc, op)).collect()
fields.iter().filter_map(|op| maybe_in_op(tcx, body, loc, op)).collect()
}

// Unimplemented cases, ignore nested information for now.
Expand Down Expand Up @@ -715,9 +715,9 @@ fn paths_at_hir_id<'tcx>(
Some(mir_locations)
}

fn path_to_perm_boundary<'tcx>(
fn path_to_perm_boundary(
path_boundary: PathBoundary,
analysis: &AquascopeAnalysis<'tcx>,
analysis: &AquascopeAnalysis<'_>,
) -> Option<PermissionsBoundary> {
let ctxt = &analysis.permissions;
let ir_mapper = &analysis.ir_mapper;
Expand Down Expand Up @@ -811,8 +811,8 @@ fn path_to_perm_boundary<'tcx>(
}

#[allow(clippy::module_name_repetitions)]
pub fn compute_permission_boundaries<'tcx>(
analysis: &AquascopeAnalysis<'tcx>,
pub fn compute_permission_boundaries(
analysis: &AquascopeAnalysis<'_>,
) -> Result<Vec<PermissionsBoundary>> {
let ctxt = &analysis.permissions;

Expand All @@ -829,7 +829,7 @@ pub fn compute_permission_boundaries<'tcx>(

let boundaries = path_use_points
.filter(|pb| {
first_error_span_opt.map_or(true, |error_span| {
first_error_span_opt.is_none_or(|error_span| {
pb.expecting_flow.is_some() || {
let error_range =
ByteRange::from_span(error_span, ctxt.tcx.sess.source_map())
Expand Down Expand Up @@ -863,13 +863,6 @@ mod test {

#[test]
fn fuzzy_search_2() {
let search = "a + b + c";
let haystack = vec![("x", 0), ("y", 1), ("z", 2)];
assert_eq!(None, fuzzy_match(search, haystack));
}

#[test]
fn fuzzy_search_3() {
let search = "y[..a]";
let haystack = vec![("x", 0), ("y", 1), ("z", 2)];
assert_eq!(Some(1), fuzzy_match(search, haystack));
Expand Down
6 changes: 3 additions & 3 deletions crates/aquascope/src/analysis/boundaries/path_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct HirExprScraper<'tcx> {
unsupported_feature: Option<(Span, String)>,
}

impl<'tcx> HirExprScraper<'tcx> {
impl HirExprScraper<'_> {
fn get_adjusted_permissions(&self, expr: &Expr) -> ExpectedPermissions {
let ty_adj = self.typeck_res.expr_ty_adjusted(expr);
let adjs = self.typeck_res.expr_adjustments(expr);
Expand Down Expand Up @@ -255,8 +255,8 @@ impl<'tcx> Visitor<'tcx> for HirExprScraper<'tcx> {
}
}

pub(super) fn get_path_boundaries<'tcx>(
ctxt: &PermissionsCtxt<'tcx>,
pub(super) fn get_path_boundaries(
ctxt: &PermissionsCtxt<'_>,
) -> Result<Vec<PathBoundary>> {
let tcx = ctxt.tcx;
let body_id = ctxt.body_id;
Expand Down
4 changes: 2 additions & 2 deletions crates/aquascope/src/analysis/ir_mapper/body_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl StartNode for CleanedBody<'_> {
}
}

impl<'tcx> Successors for CleanedBody<'tcx> {
impl Successors for CleanedBody<'_> {
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
<BasicBlocks as Successors>::successors(&self.0.basic_blocks, node)
.filter(|bb| {
Expand All @@ -124,7 +124,7 @@ impl<'tcx> Successors for CleanedBody<'tcx> {
}
}

impl<'tcx> Predecessors for CleanedBody<'tcx> {
impl Predecessors for CleanedBody<'_> {
fn predecessors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
<BasicBlocks as Predecessors>::predecessors(&self.0.basic_blocks, node)
.filter(|bb| CleanedBody::keep_block(&self.0.basic_blocks[*bb]))
Expand Down
1 change: 0 additions & 1 deletion crates/aquascope/src/analysis/ir_mapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl<'tcx> IRMapper<'tcx> {
)
}

// TODO(gavin): fixme or deleteme
pub fn local_assigned_place(
&self,
local: &hir::LetStmt,
Expand Down
4 changes: 1 addition & 3 deletions crates/aquascope/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ impl<'tcx> AquascopeAnalysis<'tcx> {
// strictly after the initial action.
// Also, if the move point was removed for not being visible then
// we can just ignore computing the highlighted ranges as well.
let Some(lo) = move_points.get(&move_key).map(|s| s.lo()) else {
return None;
};
let lo = move_points.get(&move_key).map(|s| s.lo())?;

let points = self
.points_to_spans(
Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/analysis/permissions/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<'tcx> PermissionsCtxt<'tcx> {
.polonius_output
.var_live_on_entry
.get(&point)
.map_or(false, |live_vars| live_vars.contains(&var))
.is_some_and(|live_vars| live_vars.contains(&var))
}

/// On use would the given path be copied?
Expand Down
7 changes: 2 additions & 5 deletions crates/aquascope/src/analysis/permissions/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ use rustc_borrowck::consumers::{
};
use rustc_data_structures::{
fx::FxHashSet as HashSet,
graph::{
depth_first_search, scc::Sccs, vec_graph::VecGraph, DirectedGraph,
Successors,
},
graph::{depth_first_search, scc::Sccs, vec_graph::VecGraph, Successors},
transitive_relation::{TransitiveRelation, TransitiveRelationBuilder},
};
use rustc_index::{bit_set::ChunkedBitSet, Idx};
Expand Down Expand Up @@ -280,7 +277,7 @@ fn count_nodes<T: Idx>(tups: &[(T, T)]) -> usize {
/// The return closure answers queries of the form "for (v, s) did `s` flow to v?"
fn flow_from_sources<T>(
sources: impl Iterator<Item = T>,
graph: impl DirectedGraph<Node = T> + Successors,
graph: impl Successors<Node = T>,
) -> TransitiveRelation<T>
where
T: Idx,
Expand Down
6 changes: 3 additions & 3 deletions crates/aquascope/src/analysis/permissions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ impl PermissionsData {
/// Otherwise, see `permissions_ignore_liveness`. (You may want to ignore liveness
/// when you know a variable is being used, and should therefore be live.)
pub fn permissions(&self) -> Permissions {
if !self.is_live {
Permissions::bottom()
} else {
if self.is_live {
self.permissions_ignore_liveness()
} else {
Permissions::bottom()
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/aquascope/src/analysis/permissions/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ pub fn compute<'tcx>(
let typing_env = TypingEnv::post_analysis(tcx, def_id);

// This should always be true for the current analysis of aquascope
let locals_are_invalidated_at_exit = def_id.as_local().map_or(false, |did| {
tcx.hir().body_owner_kind(did).is_fn_or_closure()
});
let locals_are_invalidated_at_exit = def_id
.as_local()
.is_some_and(|did| tcx.hir().body_owner_kind(did).is_fn_or_closure());

let mut ctxt = PermissionsCtxt {
tcx,
Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/analysis/permissions/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<C> DebugWithContext<C> for PermissionsDomain<'_> {
old
.0
.get(place)
.map_or(true, |permd| permd.permissions() == perms)
.is_none_or(|permd| permd.permissions() == perms)
});

if old == self || no_perm_changes {
Expand Down
5 changes: 4 additions & 1 deletion crates/aquascope/src/analysis/stepper/hir_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,6 @@ fn punch_card() -> impl std::fmt::Debug {
);

test_valid_segmented_mir!(
panics_with "invalid smir" =>
weird_exprs_i_yield,
r#"
#![feature(generators)]
Expand Down Expand Up @@ -1193,7 +1192,11 @@ fn bathroom_stall() {
"#
);

// TODO(gavin) what changed in MIR output that causes the
// dominator analysis to fail...
// Real error message "no open collection dominates bb6[3]"
test_valid_segmented_mir!(
panics_with "internal error" =>
weird_exprs_closure_matching,
r#"
fn closure_matching() {
Expand Down
4 changes: 2 additions & 2 deletions crates/aquascope/src/analysis/stepper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ impl MirSegment {
// ----------
// Main entry

pub fn compute_permission_steps<'tcx>(
analysis: &AquascopeAnalysis<'tcx>,
pub fn compute_permission_steps(
analysis: &AquascopeAnalysis<'_>,
) -> Result<Vec<PermissionsLineDisplay>> {
let mode = INCLUDE_MODE.copied().unwrap_or(PermIncludeMode::Changes);
let ctxt = &analysis.permissions;
Expand Down
6 changes: 6 additions & 0 deletions crates/aquascope/src/analysis/stepper/segmented_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,16 @@ impl<'a, 'tcx: 'a> SegmentedMirBuilder<'a, 'tcx> {
.filter(|&to| mapper.dominates(root, to))
.collect::<HashSet<_>>();

log::debug!("Reachable from root: {reachable:?}");

// Find the blocks that is the _most_ post-dominating,
// this is a point that must post-dominate everything else.
let most_post_dominating = reachable
.iter()
.find(|&can| reachable.iter().all(|&n| mapper.post_dominates(*can, n)))?;

log::debug!("Most post-dominating: {most_post_dominating:?}");

// If a block dominates the "most post-dominator" that means that this
// block also post-dominates all branches that occur after the root.
// We exclude the (1) root itself, and (2) any false edges. False edges
Expand All @@ -495,6 +499,8 @@ impl<'a, 'tcx: 'a> SegmentedMirBuilder<'a, 'tcx> {
})
.collect::<Vec<_>>();

log::debug!("Candidate least-dominating: {candidate_leasts:?}");

// The least post-dominator dominates all the other post-dominators.
candidate_leasts
.iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_span::Span;

thread_local! {
static BODY_DIAGNOSTICS: RefCell<Vec<DiagnosticInfo>> = RefCell::new(Vec::default());
static CURRENT_BODY: RefCell<Option<LocalDefId>> = RefCell::new(None);
static CURRENT_BODY: RefCell<Option<LocalDefId>> = const { RefCell::new(None) };
}

#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions crates/aquascope/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ impl rustc_driver::Callbacks for InterpretCallbacks {
}
}

fn after_analysis<'tcx>(
fn after_analysis(
&mut self,
_compiler: &rustc_interface::interface::Compiler,
tcx: TyCtxt<'tcx>,
tcx: TyCtxt<'_>,
) -> rustc_driver::Compilation {
self.result = Some(interpret(tcx));
rustc_driver::Compilation::Stop
Expand Down
4 changes: 2 additions & 2 deletions crates/aquascope_front/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ impl<A: AquascopeAnalysis> rustc_driver::Callbacks for AquascopeCallbacks<A> {
config.override_queries = Some(borrowck_facts::override_queries);
}

fn after_expansion<'tcx>(
fn after_expansion(
&mut self,
_compiler: &rustc_interface::interface::Compiler,
tcx: TyCtxt<'tcx>,
tcx: TyCtxt<'_>,
) -> rustc_driver::Compilation {
// Setting up error tracking happens here. Within rustc callbacks
// seem to be set up *after* `config` is called.
Expand Down
1 change: 1 addition & 0 deletions crates/mdbook-aquascope/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl<K: Hash, V: Serialize + DeserializeOwned> Cache<K, V> {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(CACHE_PATH)?;
let cache = if cache_file.metadata()?.len() == 0 {
HashMap::new()
Expand Down

0 comments on commit ff81ab7

Please sign in to comment.