Skip to content
Snippets Groups Projects
Verified Commit df66db26 authored by Vincent Lafeychine's avatar Vincent Lafeychine
Browse files

clippy: Fix items_after_statements

parent 2d4cac2f
No related branches found
No related tags found
1 merge request!44Fix most of `clippy::pedantic`
......@@ -32,7 +32,6 @@ rustflags = [
"-Aclippy::string_lit_as_bytes",
# clippy::pedantic
"-Aclippy::items_after_statements",
"-Aclippy::manual_let_else",
"-Aclippy::manual_string_new",
"-Aclippy::map_unwrap_or",
......
......@@ -94,32 +94,34 @@ impl<'b, 'tcx> Visitor<'tcx> for AccessCollector<'b, 'tcx> {
context: mir::visit::PlaceContext,
location: mir::Location,
) {
use rustc_middle::mir::visit::PlaceContext::*;
// TODO: using `location`, skip the places that are used for typechecking
// because that part of the generated code contains closures.
if self.body.contains(&location.block) && context.is_use() {
trace!("visit_place(place={:?}, context={:?}, location={:?})", place, context, location);
use rustc_middle::mir::visit::PlaceContext::*;
let access_kind = match context {
MutatingUse(mir::visit::MutatingUseContext::Store) => PlaceAccessKind::Store,
MutatingUse(mir::visit::MutatingUseContext::Call) => PlaceAccessKind::Store,
MutatingUse(mir::visit::MutatingUseContext::Borrow) => PlaceAccessKind::MutableBorrow,
MutatingUse(mir::visit::MutatingUseContext::Drop) => PlaceAccessKind::Move,
NonMutatingUse(mir::visit::NonMutatingUseContext::Copy) => PlaceAccessKind::Read,
NonMutatingUse(mir::visit::NonMutatingUseContext::Move) => PlaceAccessKind::Move,
NonMutatingUse(mir::visit::NonMutatingUseContext::Inspect) => PlaceAccessKind::Read,
NonMutatingUse(mir::visit::NonMutatingUseContext::SharedBorrow) => {
PlaceAccessKind::SharedBorrow
},
NonUse(_) => unreachable!(),
x => unimplemented!("{:?}", x),
};
let access = PlaceAccess {
location,
place: *place,
kind: access_kind,
};
self.accessed_places.push(access);
if !(self.body.contains(&location.block) && context.is_use()) {
return;
}
trace!("visit_place(place={:?}, context={:?}, location={:?})", place, context, location);
let access_kind = match context {
MutatingUse(mir::visit::MutatingUseContext::Store) => PlaceAccessKind::Store,
MutatingUse(mir::visit::MutatingUseContext::Call) => PlaceAccessKind::Store,
MutatingUse(mir::visit::MutatingUseContext::Borrow) => PlaceAccessKind::MutableBorrow,
MutatingUse(mir::visit::MutatingUseContext::Drop) => PlaceAccessKind::Move,
NonMutatingUse(mir::visit::NonMutatingUseContext::Copy) => PlaceAccessKind::Read,
NonMutatingUse(mir::visit::NonMutatingUseContext::Move) => PlaceAccessKind::Move,
NonMutatingUse(mir::visit::NonMutatingUseContext::Inspect) => PlaceAccessKind::Read,
NonMutatingUse(mir::visit::NonMutatingUseContext::SharedBorrow) => PlaceAccessKind::SharedBorrow,
NonUse(_) => unreachable!(),
x => unimplemented!("{:?}", x),
};
self.accessed_places.push(PlaceAccess {
location,
place: *place,
kind: access_kind,
});
}
}
......@@ -130,12 +132,6 @@ fn order_basic_blocks(
back_edges: &HashSet<(BasicBlockIndex, BasicBlockIndex)>,
loop_depth: &dyn Fn(BasicBlockIndex) -> usize,
) -> Vec<BasicBlockIndex> {
let basic_blocks = &mir.basic_blocks;
let mut sorted_blocks = Vec::new();
let mut permanent_mark = IndexVec::<BasicBlockIndex, bool>::from_elem_n(false, basic_blocks.len());
let mut temporary_mark = permanent_mark.clone();
#[allow(clippy::too_many_arguments)]
fn visit(
real_edges: &RealEdges,
back_edges: &HashSet<(BasicBlockIndex, BasicBlockIndex)>,
......@@ -180,6 +176,11 @@ fn order_basic_blocks(
sorted_blocks.push(current);
}
let basic_blocks = &mir.basic_blocks;
let mut sorted_blocks = Vec::new();
let mut permanent_mark = IndexVec::<BasicBlockIndex, bool>::from_elem_n(false, basic_blocks.len());
let mut temporary_mark = permanent_mark.clone();
while let Some(index) = permanent_mark.iter().position(|x| !*x) {
let index = BasicBlockIndex::new(index);
visit(
......@@ -192,6 +193,7 @@ fn order_basic_blocks(
&mut temporary_mark,
);
}
sorted_blocks.reverse();
sorted_blocks
}
......
......@@ -5,6 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::io::Write;
use std::path::PathBuf;
use log::{debug, trace};
......@@ -203,11 +204,11 @@ pub fn graphviz<'tcx>(
let borrowck_out_facts = &info.borrowck_out_facts;
//let borrowck_out_facts = Output::compute(&borrowck_in_facts, Algorithm::Naive, true);
use std::io::Write;
let graph_path = config::log_dir()
.join("nll-facts")
.join(def_path.to_filename_friendly_no_crate())
.join("polonius.dot");
let graph_file = std::fs::File::create(graph_path).expect("Unable to create file");
let mut graph = std::io::BufWriter::new(graph_file);
......
......@@ -607,7 +607,6 @@ pub fn collapse<'tcx>(
places: &mut FxHashSet<mir::Place<'tcx>>,
guide_place: &mir::Place<'tcx>,
) {
let guide_place = *guide_place;
fn recurse<'tcx>(
mir: &mir::Body<'tcx>,
tcx: TyCtxt<'tcx>,
......@@ -615,19 +614,24 @@ pub fn collapse<'tcx>(
current_place: mir::Place<'tcx>,
guide_place: mir::Place<'tcx>,
) {
if current_place != guide_place {
let (new_current_place, mut expansion) = expand_one_level(mir, tcx, current_place, guide_place);
recurse(mir, tcx, places, new_current_place, guide_place);
expansion.push(new_current_place);
if expansion.iter().all(|place| places.contains(place)) {
for place in expansion {
places.remove(&place);
}
places.insert(current_place);
if current_place == guide_place {
return;
}
let (new_current_place, mut expansion) = expand_one_level(mir, tcx, current_place, guide_place);
recurse(mir, tcx, places, new_current_place, guide_place);
expansion.push(new_current_place);
if expansion.iter().all(|place| places.contains(place)) {
for place in expansion {
places.remove(&place);
}
places.insert(current_place);
}
}
recurse(mir, tcx, places, guide_place.local.into(), guide_place);
recurse(mir, tcx, places, guide_place.local.into(), *guide_place);
}
#[derive(Debug)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment