Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some lints #1421

Merged
merged 16 commits into from
Dec 6, 2022
Merged
8 changes: 4 additions & 4 deletions crates/fj-app/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ enum ModelPathSource {
impl ModelPathSource {
fn path(&self) -> &Path {
match self {
ModelPathSource::Args(path) => path,
ModelPathSource::Config(path) => path,
Self::Args(path) => path,
Self::Config(path) => path,
}
}
}
Expand All @@ -99,10 +99,10 @@ fn load_error_context_inner(
)?;
match model_path {
ModelPathSource::Args(_) => {
write!(error, "\n- Passed via command-line argument")?
write!(error, "\n- Passed via command-line argument")?;
}
ModelPathSource::Config(_) => {
write!(error, "\n- Specified as default model in configuration")?
write!(error, "\n- Specified as default model in configuration")?;
}
}
write!(error, "\n- Path of model: {}", path.display())?;
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-export/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn export(mesh: &Mesh<Point<3>>, path: &Path) -> Result<(), Error> {
}

fn export_3mf(mesh: &Mesh<Point<3>>, path: &Path) -> Result<(), Error> {
let vertices = mesh.vertices().map(|vertex| vertex.into()).collect();
let vertices = mesh.vertices().map(Into::into).collect();

let indices: Vec<_> = mesh.indices().collect();
let triangles = indices
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-host/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Evaluator {
let (trigger_tx, trigger_rx) = crossbeam_channel::bounded(0);

thread::spawn(move || {
while let Ok(TriggerEvaluation) = trigger_rx.recv() {
while matches!(trigger_rx.recv(), Ok(TriggerEvaluation)) {
if let Err(SendError(_)) =
event_tx.send(ModelEvent::ChangeDetected)
{
Expand Down Expand Up @@ -49,8 +49,8 @@ impl Evaluator {
});

Self {
event_rx,
trigger_tx,
event_rx,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Host {
pub fn from_model(model: Model) -> Result<Self, Error> {
let watch_path = model.watch_path();
let evaluator = Evaluator::from_model(model);
let watcher = Watcher::watch_model(&watch_path, &evaluator)?;
let watcher = Watcher::watch_model(watch_path, &evaluator)?;

Ok(Self {
evaluator,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-host/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'a> fj::models::Host for Host<'a> {

impl<'a> fj::models::Context for Host<'a> {
fn get_argument(&self, name: &str) -> Option<&str> {
self.args.get(name).map(|s| s.as_str())
self.args.get(name).map(String::as_str)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-host/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ struct Unix;

impl Platform for Windows {
fn model_lib_file_name(&self, name: &str) -> String {
format!("{}.dll", name)
format!("{name}.dll")
}
}

impl Platform for Macos {
fn model_lib_file_name(&self, name: &str) -> String {
format!("lib{}.dylib", name)
format!("lib{name}.dylib")
}
}

impl Platform for Unix {
fn model_lib_file_name(&self, name: &str) -> String {
format!("lib{}.so", name)
format!("lib{name}.so")
}
}

Expand Down
16 changes: 5 additions & 11 deletions crates/fj-host/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@ impl Watcher {
// Various acceptable ModifyKind kinds. Varies across platforms
// (e.g. MacOs vs. Windows10)
if let notify::EventKind::Modify(
notify::event::ModifyKind::Any,
)
| notify::EventKind::Modify(
notify::event::ModifyKind::Data(
notify::event::DataChange::Any,
),
)
| notify::EventKind::Modify(
notify::event::ModifyKind::Data(
notify::event::DataChange::Content,
notify::event::ModifyKind::Any
| notify::event::ModifyKind::Data(
notify::event::DataChange::Any
| notify::event::DataChange::Content,
),
) = event.kind
{
Expand Down Expand Up @@ -86,7 +80,7 @@ impl Watcher {
thread::spawn(move || {
watch_tx_2
.send(TriggerEvaluation)
.expect("Channel is disconnected")
.expect("Channel is disconnected");
});

Ok(Self {
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-interop/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ impl Mesh<Point<3>> {
impl<V> Default for Mesh<V> {
fn default() -> Self {
Self {
vertices: Default::default(),
indices: Default::default(),
indices_by_vertex: Default::default(),
triangles: Default::default(),
vertices: Vec::default(),
indices: Vec::default(),
indices_by_vertex: HashMap::default(),
triangles: Vec::default(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl CurveFaceIntersection {
.map(|&[start, end]| CurveFaceIntersectionInterval { start, end })
.collect();

CurveFaceIntersection { intervals }
Self { intervals }
}

/// Merge this intersection list with another
Expand Down Expand Up @@ -143,7 +143,7 @@ where
{
fn from(interval: [P; 2]) -> Self {
let [start, end] = interval.map(Into::into);
CurveFaceIntersectionInterval { start, end }
Self { start, end }
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Sweep for (Handle<Vertex>, Handle<Surface>) {
}

impl Sweep for Handle<GlobalVertex> {
type Swept = (Handle<GlobalEdge>, [Handle<GlobalVertex>; 2]);
type Swept = (Handle<GlobalEdge>, [Self; 2]);

fn sweep_with_cache(
self,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/transform/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl TransformObject for FaceSet {
objects: &mut Service<Objects>,
cache: &mut TransformCache,
) -> Self {
let mut faces = FaceSet::new();
let mut faces = Self::new();
faces.extend(
self.into_iter().map(|face| {
face.transform_with_cache(transform, objects, cache)
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/transform/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ impl TransformObject for Shell {
face.transform_with_cache(transform, objects, cache)
});

Shell::new(faces)
Self::new(faces)
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/transform/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ impl TransformObject for Sketch {
face.transform_with_cache(transform, objects, cache)
});

Sketch::new(faces)
Self::new(faces)
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/transform/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ impl TransformObject for Solid {
.cloned()
.map(|shell| shell.transform_with_cache(transform, objects, cache));

Solid::new(shells)
Self::new(shells)
}
}
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/algorithms/triangulate/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::algorithms::intersect::{
ray_segment::RaySegmentIntersection, HorizontalRayToTheRight, Intersect,
};

#[derive(Default)]
pub struct Polygon {
exterior: PolyChain<2>,
interiors: Vec<PolyChain<2>>,
Expand All @@ -13,10 +14,7 @@ pub struct Polygon {
impl Polygon {
/// Construct an instance of `Polygon`
pub fn new() -> Self {
Self {
exterior: PolyChain::new(),
interiors: Vec::new(),
}
Self::default()
}

pub fn with_exterior(mut self, exterior: impl Into<PolyChain<2>>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl GlobalVertexBuilder for PartialGlobalVertex {
surface: &SurfaceGeometry,
position: impl Into<Point<2>>,
) -> Self {
PartialGlobalVertex {
Self {
position: Some(surface.point_from_surface_coords(position)),
}
}
Expand Down
10 changes: 2 additions & 8 deletions crates/fj-kernel/src/geometry/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ impl SurfacePath {
pub fn circle_from_radius(radius: impl Into<Scalar>) -> Self {
let radius = radius.into();

SurfacePath::Circle(Circle::from_center_and_radius(
Point::origin(),
radius,
))
Self::Circle(Circle::from_center_and_radius(Point::origin(), radius))
}

/// Construct a line from two points
Expand Down Expand Up @@ -101,10 +98,7 @@ impl GlobalPath {
pub fn circle_from_radius(radius: impl Into<Scalar>) -> Self {
let radius = radius.into();

GlobalPath::Circle(Circle::from_center_and_radius(
Point::origin(),
radius,
))
Self::Circle(Circle::from_center_and_radius(Point::origin(), radius))
}

/// Construct a line from two points
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ where
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> {
let mut objects = Vec::new();

for object in self.into_iter() {
for object in self {
objects.push(object as &dyn ObjectIters);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/full/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Get<GlobalCurve> for HalfEdge {
impl fmt::Display for HalfEdge {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let [a, b] = self.vertices().clone().map(|vertex| vertex.position());
write!(f, "edge from {:?} to {:?}", a, b)?;
write!(f, "edge from {a:?} to {b:?}")?;
write!(f, " on {:?}", self.curve().global_form())?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/full/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl FaceSet {

impl Extend<Handle<Face>> for FaceSet {
fn extend<T: IntoIterator<Item = Handle<Face>>>(&mut self, iter: T) {
self.inner.extend(iter)
self.inner.extend(iter);
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ impl MaybePartial<Curve> {
/// Access the path
pub fn path(&self) -> Option<SurfacePath> {
match self {
MaybePartial::Full(full) => Some(full.path()),
MaybePartial::Partial(partial) => partial.path,
Self::Full(full) => Some(full.path()),
Self::Partial(partial) => partial.path,
}
}

/// Access the surface
pub fn surface(&self) -> Option<Handle<Surface>> {
match self {
MaybePartial::Full(full) => Some(full.surface().clone()),
MaybePartial::Partial(partial) => partial.surface.clone(),
Self::Full(full) => Some(full.surface().clone()),
Self::Partial(partial) => partial.surface.clone(),
}
}

Expand Down
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/partial/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ where
}

// We know that `self != other`, or we wouldn't have made it here.
if self.is_some() && other.is_some() {
panic!("Can't merge two `Option`s that are both `Some`")
}
assert!(
self.is_none() || other.is_none(),
"Can't merge two `Option`s that are both `Some`"
);

self.xor(other)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/partial/objects/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl PartialSurfaceVertex {
&surface.geometry(),
position,
),
)
);
}
let global_form = self.global_form.into_full(objects);

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/services/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ impl ServiceObjectsExt for Service<Objects> {
{
self.execute(InsertObject {
object: (handle, object).into(),
})
});
}
}
4 changes: 1 addition & 3 deletions crates/fj-kernel/src/storage/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ impl<T> Block<T> {
pub fn insert(&mut self, index: ObjectIndex, object: T) {
let slot = &mut self.objects[index.0];

if slot.is_some() {
panic!("Attempting to overwrite object in store")
}
assert!(slot.is_none(), "Attempting to overwrite object in store");

*slot = Some(object);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/storage/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where
T: Hash,
{
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.deref().hash(state)
self.deref().hash(state);
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ impl<T> Hash for HandleWrapper<T> {
return;
}

self.0.id().hash(state)
self.0.id().hash(state);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/storage/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ mod tests {
store.insert(b.clone(), 1);

let objects = store.iter().collect::<Vec<_>>();
assert_eq!(objects, [a, b])
assert_eq!(objects, [a, b]);
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/validate/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl HalfEdgeValidationError {
let front_curve = half_edge.front().curve();

if back_curve.id() != front_curve.id() {
return Err(HalfEdgeValidationError::CurveMismatch {
return Err(Self::CurveMismatch {
back_curve: back_curve.clone(),
front_curve: front_curve.clone(),
});
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/validate/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl VertexValidationError {
let surface_form_surface = vertex.surface_form().surface();

if curve_surface.id() != surface_form_surface.id() {
return Err(VertexValidationError::SurfaceMismatch {
return Err(Self::SurfaceMismatch {
curve_surface: curve_surface.clone(),
surface_form_surface: surface_form_surface.clone(),
});
Expand All @@ -113,7 +113,7 @@ impl VertexValidationError {
let distance = curve_position_as_surface.distance_to(&surface_position);

if distance > config.identical_max_distance {
return Err(VertexValidationError::PositionMismatch {
return Err(Self::PositionMismatch {
vertex: vertex.clone(),
surface_vertex: vertex.surface_form().clone_object(),
curve_position_as_surface,
Expand Down
Loading