clippy pt3

This commit is contained in:
Dustin Carlino 2018-12-08 20:02:21 -08:00
parent f48757c5e7
commit caae9bcc36
13 changed files with 36 additions and 46 deletions

View File

@ -4,10 +4,13 @@
touch `find * | grep '\.rs' | grep -v target | xargs`
# TODO Remove all of these exceptions
# TODO Report issues for some of these false positives
cargo clippy -- \
-A clippy::cyclomatic_complexity \
-A clippy::expect_fun_call \
-A clippy::if_same_then_else \
-A clippy::large_enum_variant \
-A clippy::map_entry \
-A clippy::needless_pass_by_value \
-A clippy::new_ret_no_self \
-A clippy::new_without_default \

View File

@ -60,7 +60,7 @@ impl ColorScheme {
}
pub fn get_modified(&self, name: &str) -> Option<Color> {
self.modified.map.get(name).map(|c| *c)
self.modified.map.get(name).cloned()
}
pub fn reset_modified(&mut self, name: &str, orig: Option<Color>) {

View File

@ -93,7 +93,7 @@ impl ID {
ID::Parcel(id) => map.maybe_get_p(id).map(|p| Pt2D::center(&p.points)),
ID::BusStop(id) => map.maybe_get_bs(id).map(|bs| bs.sidewalk_pos.pt(map)),
ID::Area(id) => map.maybe_get_a(id).map(|a| Pt2D::center(&a.points)),
ID::Trip(id) => sim.get_stats().canonical_pt_per_trip.get(&id).map(|pt| *pt),
ID::Trip(id) => sim.get_stats().canonical_pt_per_trip.get(&id).cloned(),
}
}
}

View File

@ -87,8 +87,7 @@ impl Validator {
impl Plugin for Validator {
fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
// Initialize or advance?
if !self.current_problem.is_some() || ctx.input.key_pressed(Key::N, "see the next problem")
{
if self.current_problem.is_none() || ctx.input.key_pressed(Key::N, "see the next problem") {
// TODO do this in a bg thread or something
self.current_problem = self.gen.next();

View File

@ -30,7 +30,7 @@ impl Hider {
Some(ID::Car(_)) | Some(ID::Pedestrian(_)) | None => {
return false;
}
Some(id) => id.clone(),
Some(id) => id,
};
if input.unimportant_key_pressed(Key::H, DEBUG_EXTRA, &format!("hide {:?}", item)) {
self.items.insert(item);

View File

@ -40,9 +40,9 @@ impl Plugin for ABTestManager {
let ((new_primary, new_primary_plugins), new_secondary) =
launch_test(test, ctx.kml, &ctx.primary.current_flags, &ctx.canvas);
*ctx.primary = new_primary;
ctx.primary_plugins.as_mut().map(|p_plugins| {
if let Some(p_plugins) = ctx.primary_plugins.as_mut() {
**p_plugins = new_primary_plugins;
});
}
*ctx.secondary = Some(new_secondary);
return false;
}

View File

@ -66,8 +66,8 @@ impl Plugin for ColorPicker {
if let Some((m_x, m_y)) = input.get_moved_mouse() {
// TODO argh too much casting
let (start_x, start_y) = get_screen_offset(canvas);
let x = (m_x - (start_x as f64)) / (TILE_DIMS as f64) / 255.0;
let y = (m_y - (start_y as f64)) / (TILE_DIMS as f64) / 255.0;
let x = (m_x - f64::from(start_x)) / f64::from(TILE_DIMS) / 255.0;
let y = (m_y - f64::from(start_y)) / f64::from(TILE_DIMS) / 255.0;
if x >= 0.0 && x <= 1.0 && y >= 0.0 && y <= 1.0 {
cs.override_color(name, get_color(x as f32, y as f32));
}

View File

@ -40,15 +40,13 @@ impl Plugin for EditsManager {
{
if let Some((p, plugins)) = new_primary {
*ctx.primary = p;
ctx.primary_plugins.as_mut().map(|p_plugins| {
if let Some(p_plugins) = ctx.primary_plugins.as_mut() {
**p_plugins = plugins;
});
}
}
false
} else if self.wizard.aborted() {
false
} else {
true
!self.wizard.aborted()
}
}

View File

@ -98,11 +98,11 @@ impl Plugin for TimeTravel {
impl GetDrawAgents for TimeTravel {
fn get_draw_car(&self, id: CarID, _map: &Map) -> Option<DrawCarInput> {
self.get_current_state().cars.get(&id).map(|d| d.clone())
self.get_current_state().cars.get(&id).cloned()
}
fn get_draw_ped(&self, id: PedestrianID, _map: &Map) -> Option<DrawPedestrianInput> {
self.get_current_state().peds.get(&id).map(|d| d.clone())
self.get_current_state().peds.get(&id).cloned()
}
fn get_draw_cars(&self, on: Traversable, _map: &Map) -> Vec<DrawCarInput> {
@ -127,11 +127,7 @@ impl GetDrawAgents for TimeTravel {
}
fn get_all_draw_cars(&self, _map: &Map) -> Vec<DrawCarInput> {
self.get_current_state()
.cars
.values()
.map(|d| d.clone())
.collect()
self.get_current_state().cars.values().cloned().collect()
}
fn get_all_draw_peds(&self, _map: &Map) -> Vec<DrawPedestrianInput> {

View File

@ -461,11 +461,8 @@ impl WalkingSimState {
// Now they'll start walking somewhere
self.peds.get_mut(&id).unwrap().bike_parking = None;
} else {
{
let p = self.peds.get(&id).unwrap();
ready_to_bike
.push((*id, Position::new(p.on.as_lane(), p.dist_along)));
}
let p = &self.peds[&id];
ready_to_bike.push((*id, Position::new(p.on.as_lane(), p.dist_along)));
self.peds.remove(&id);
}
}

View File

@ -84,11 +84,9 @@ impl GUI<Text> for UI {
if input.key_pressed(Key::Escape, "stop defining road") {
self.state = State::Viewing;
} else if let Some(i2) = self.model.mouseover_intersection(cursor) {
if i1 != i2 {
if input.key_pressed(Key::R, "finalize road") {
self.model.create_road(i1, i2);
self.state = State::Viewing;
}
if i1 != i2 && input.key_pressed(Key::R, "finalize road") {
self.model.create_road(i1, i2);
self.state = State::Viewing;
}
}
}
@ -145,21 +143,19 @@ impl GUI<Text> for UI {
} else if input.key_pressed(Key::L, "label side of the road") {
self.state = State::LabelingRoad((r, dir), Wizard::new());
}
} else {
if input.unimportant_key_pressed(Key::Escape, KEY_CATEGORY, "quit") {
process::exit(0);
} else if input.key_pressed(Key::S, "save") {
if self.model.name.is_some() {
self.model.save();
self.model.export();
} else {
self.state = State::SavingModel(Wizard::new());
}
} else if input.key_pressed(Key::I, "create intersection") {
self.model.create_i(cursor);
} else if input.key_pressed(Key::B, "create building") {
self.model.create_b(cursor);
} else if input.unimportant_key_pressed(Key::Escape, KEY_CATEGORY, "quit") {
process::exit(0);
} else if input.key_pressed(Key::S, "save") {
if self.model.name.is_some() {
self.model.save();
self.model.export();
} else {
self.state = State::SavingModel(Wizard::new());
}
} else if input.key_pressed(Key::I, "create intersection") {
self.model.create_i(cursor);
} else if input.key_pressed(Key::B, "create building") {
self.model.create_b(cursor);
}
}
}

View File

@ -269,7 +269,7 @@ impl Model {
}
map.buildings.push(raw_data::Building {
// TODO Duplicate points :(
points: b.polygon().points().into_iter().map(|p| pt(p)).collect(),
points: b.polygon().points().into_iter().map(pt).collect(),
osm_tags,
osm_way_id: idx as i64,
});

View File

@ -4,6 +4,7 @@ use geom::EPSILON_DIST;
use sim::kinematics::{results_of_accel_for_one_tick, Vehicle, EPSILON_SPEED};
use sim::{CarID, Distance, Speed, Tick, VehicleType};
#[allow(clippy::unreadable_literal)]
pub fn run(t: &mut TestRunner) {
// TODO table driven test style?
t.run_fast(