diff --git a/clippy.sh b/clippy.sh index 52c190a16c..05999ad02f 100755 --- a/clippy.sh +++ b/clippy.sh @@ -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 \ diff --git a/editor/src/colors.rs b/editor/src/colors.rs index 27cd7a1768..45201ea34e 100644 --- a/editor/src/colors.rs +++ b/editor/src/colors.rs @@ -60,7 +60,7 @@ impl ColorScheme { } pub fn get_modified(&self, name: &str) -> Option { - self.modified.map.get(name).map(|c| *c) + self.modified.map.get(name).cloned() } pub fn reset_modified(&mut self, name: &str, orig: Option) { diff --git a/editor/src/objects.rs b/editor/src/objects.rs index c640c2b00f..3c3efc78cf 100644 --- a/editor/src/objects.rs +++ b/editor/src/objects.rs @@ -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(), } } } diff --git a/editor/src/plugins/debug/geom_validation.rs b/editor/src/plugins/debug/geom_validation.rs index 87b995dc47..f162752418 100644 --- a/editor/src/plugins/debug/geom_validation.rs +++ b/editor/src/plugins/debug/geom_validation.rs @@ -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(); diff --git a/editor/src/plugins/debug/hider.rs b/editor/src/plugins/debug/hider.rs index be32cc5010..51b8a286ee 100644 --- a/editor/src/plugins/debug/hider.rs +++ b/editor/src/plugins/debug/hider.rs @@ -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); diff --git a/editor/src/plugins/edit/a_b_tests.rs b/editor/src/plugins/edit/a_b_tests.rs index 853f0ec706..486074f65c 100644 --- a/editor/src/plugins/edit/a_b_tests.rs +++ b/editor/src/plugins/edit/a_b_tests.rs @@ -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; } diff --git a/editor/src/plugins/edit/color_picker.rs b/editor/src/plugins/edit/color_picker.rs index b452da5a42..19deb957d3 100644 --- a/editor/src/plugins/edit/color_picker.rs +++ b/editor/src/plugins/edit/color_picker.rs @@ -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)); } diff --git a/editor/src/plugins/edit/map_edits.rs b/editor/src/plugins/edit/map_edits.rs index 005061c5eb..89289e5543 100644 --- a/editor/src/plugins/edit/map_edits.rs +++ b/editor/src/plugins/edit/map_edits.rs @@ -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() } } diff --git a/editor/src/plugins/time_travel.rs b/editor/src/plugins/time_travel.rs index d517552ce3..b63e633390 100644 --- a/editor/src/plugins/time_travel.rs +++ b/editor/src/plugins/time_travel.rs @@ -98,11 +98,11 @@ impl Plugin for TimeTravel { impl GetDrawAgents for TimeTravel { fn get_draw_car(&self, id: CarID, _map: &Map) -> Option { - 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 { - 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 { @@ -127,11 +127,7 @@ impl GetDrawAgents for TimeTravel { } fn get_all_draw_cars(&self, _map: &Map) -> Vec { - 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 { diff --git a/sim/src/walking.rs b/sim/src/walking.rs index 70badf207b..145b96e20e 100644 --- a/sim/src/walking.rs +++ b/sim/src/walking.rs @@ -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); } } diff --git a/synthetic/src/main.rs b/synthetic/src/main.rs index b219c46ef5..cb469147ea 100644 --- a/synthetic/src/main.rs +++ b/synthetic/src/main.rs @@ -84,11 +84,9 @@ impl GUI 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 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); } } } diff --git a/synthetic/src/model.rs b/synthetic/src/model.rs index baba967207..406da3af43 100644 --- a/synthetic/src/model.rs +++ b/synthetic/src/model.rs @@ -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, }); diff --git a/tests/src/physics.rs b/tests/src/physics.rs index cfe989eea3..7128cdaf3c 100644 --- a/tests/src/physics.rs +++ b/tests/src/physics.rs @@ -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(