Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ytanimura committed Sep 18, 2024
1 parent 5411073 commit 7d2e11b
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 52 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"espr",
"espr-derive",
Expand Down
8 changes: 4 additions & 4 deletions espr/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ pub trait Component: Sized {
}
}

#[macro_export(local_inner_macro)]
#[macro_export(local_inner_macros)]
macro_rules! derive_ast_component {
($component:ty, $parser:path) => {
impl crate::ast::Component for $component {
impl $crate::ast::Component for $component {
fn parse(
input: &str,
) -> Result<(Self, Vec<crate::ast::Remark>), crate::ast::TokenizeFailed> {
) -> Result<(Self, Vec<$crate::ast::Remark>), $crate::ast::TokenizeFailed> {
use nom::Finish;
let input = input.trim();
let (_input, parsed) = $parser(input)
.finish()
.map_err(|err| crate::ast::TokenizeFailed::new(input, err))?;
.map_err(|err| $crate::ast::TokenizeFailed::new(input, err))?;
Ok(parsed)
}
}
Expand Down
1 change: 0 additions & 1 deletion espr/src/codegen/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ mod simple_type;
mod type_decl;
mod type_ref;

pub use entity::*;
pub use format::rustfmt;
pub use schema::*;
5 changes: 1 addition & 4 deletions espr/src/codegen/rust/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ impl Schema {
let name = format_ident!("{}", self.name);
let types = &self.types;
let entities = &self.entities;
let type_decls = self.types.iter().filter(|e| match e {
TypeDecl::Enumeration(_) => false,
_ => true,
});
let type_decls = self.types.iter().filter(|e| !matches!(e, TypeDecl::Enumeration(_)));
let entity_types: Vec<_> = entities
.iter()
.map(|e| format_ident!("{}", e.name.to_pascal_case()))
Expand Down
11 changes: 5 additions & 6 deletions espr/src/ir/complex_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ pub struct PartialComplexEntity {

impl PartialOrd for PartialComplexEntity {
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
match PartialOrd::partial_cmp(&self.indices.len(), &rhs.indices.len()) {
Some(Ordering::Equal) => PartialOrd::partial_cmp(&self.indices, &rhs.indices),
a @ Some(Ordering::Less) | a @ Some(Ordering::Greater) => a,
None => unreachable!(),
}
Some(self.cmp(rhs))
}
}

impl Ord for PartialComplexEntity {
fn cmp(&self, rhs: &Self) -> Ordering {
self.partial_cmp(rhs).unwrap()
match Ord::cmp(&self.indices.len(), &rhs.indices.len()) {
Ordering::Equal => Ord::cmp(&self.indices, &rhs.indices),
a @ Ordering::Less | a @ Ordering::Greater => a,
}
}
}

Expand Down
8 changes: 1 addition & 7 deletions espr/src/ir/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ impl PartialOrd for Scope {
return None;
}
}
if self.0.len() == other.0.len() {
Some(cmp::Ordering::Equal)
} else if self.0.len() > other.0.len() {
Some(cmp::Ordering::Less)
} else {
Some(cmp::Ordering::Greater)
}
Some(other.0.len().cmp(&self.0.len()))
}
}

Expand Down
2 changes: 2 additions & 0 deletions espr/src/parser/basis.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::manual_is_ascii_check)]

use super::{combinator::RawParseResult, reserved::is_reserved};
use nom::{branch::*, character::complete::*, multi::*, sequence::*, Parser};

Expand Down
1 change: 1 addition & 0 deletions espr/src/parser/entity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod attribute;
mod derive;
mod domain;
#[allow(clippy::module_inception)]
mod entity;
mod inverse;
mod unique;
Expand Down
2 changes: 1 addition & 1 deletion espr/src/parser/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn procedure_decl(input: &str) -> ParseResult<Procedure> {
/// `)` \] `;` .
pub fn procedure_head(input: &str) -> ParseResult<(String, Vec<FormalParameter>)> {
let param = tuple((opt(tag("VAR")), formal_parameter)).map(|(var, mut params)| {
for mut param in &mut params {
for param in &mut params {
param.is_variable = var.is_some();
}
params
Expand Down
2 changes: 1 addition & 1 deletion ruststep-derive/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn as_holder_path(input: &syn::Type) -> syn::Type {
.clone()
.try_into()
.expect_or_abort("as_holder! only accepts espr-generated type");
ft.as_holder().into()
ft.into_holder().into()
}

pub fn as_visitor_ident(input: &syn::Ident) -> syn::Ident {
Expand Down
2 changes: 1 addition & 1 deletion ruststep-derive/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl FieldEntries {
}),
FieldType::Boxed(_) => abort_call_site!("Unexpected Box<T>"),
}
holder_types.push(ft.as_holder().as_place_holder().into());
holder_types.push(ft.into_holder().into_place_holder().into());
} else {
into_owned.push(quote! { #ident });
holder_types.push(ft.into());
Expand Down
46 changes: 23 additions & 23 deletions ruststep-derive/src/field_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ pub enum FieldType {
}

impl FieldType {
pub fn as_holder(self) -> Self {
pub fn into_holder(self) -> Self {
match self {
FieldType::Path(path) => {
let syn::Path {
leading_colon,
mut segments,
} = path;
let mut last_seg = segments.last_mut().unwrap();
let last_seg = segments.last_mut().unwrap();
match &mut last_seg.arguments {
syn::PathArguments::None => {
last_seg.ident = as_holder_ident(&last_seg.ident);
Expand All @@ -37,37 +37,37 @@ impl FieldType {
})
}
FieldType::Optional(ty) => {
let holder = ty.as_holder();
let holder = ty.into_holder();
FieldType::Optional(Box::new(holder))
}
FieldType::List(ty) => {
let holder = ty.as_holder();
let holder = ty.into_holder();
FieldType::List(Box::new(holder))
}
FieldType::Boxed(ty) => {
let holder = ty.as_holder();
let holder = ty.into_holder();
FieldType::Boxed(Box::new(holder))
}
}
}

pub fn as_place_holder(self) -> Self {
pub fn into_place_holder(self) -> Self {
let ruststep = ruststep_crate();
match self {
FieldType::Path(path) => {
let path = syn::parse_quote! { #ruststep::tables::PlaceHolder<#path> };
FieldType::Path(path)
}
FieldType::Optional(ty) => {
let place_holder = ty.as_place_holder();
let place_holder = ty.into_place_holder();
FieldType::Optional(Box::new(place_holder))
}
FieldType::List(ty) => {
let place_holder = ty.as_place_holder();
let place_holder = ty.into_place_holder();
FieldType::List(Box::new(place_holder))
}
FieldType::Boxed(ty) => {
let place_holder = ty.as_place_holder();
let place_holder = ty.into_place_holder();
FieldType::Boxed(Box::new(place_holder))
}
}
Expand All @@ -77,18 +77,18 @@ impl FieldType {
#[derive(Debug, Clone)]
pub struct UnsupportedTypeError {}

impl Into<Diagnostic> for UnsupportedTypeError {
fn into(self) -> Diagnostic {
Diagnostic::new(
impl From<UnsupportedTypeError> for Diagnostic {
fn from(_: UnsupportedTypeError) -> Self {
Self::new(
Level::Error,
"Unsupported Type for ruststep and espr".to_string(),
)
}
}

impl Into<syn::Type> for FieldType {
fn into(self) -> syn::Type {
let path = match self {
impl From<FieldType> for syn::Type {
fn from(field_type: FieldType) -> Self {
let path = match field_type {
FieldType::Path(path) => path,
FieldType::Optional(ty) => {
let ty: syn::Type = (*ty).into();
Expand Down Expand Up @@ -181,25 +181,25 @@ mod tests {
fn as_holder() {
let ty: syn::Type = syn::parse_str("T").unwrap();
let f: FieldType = ty.try_into().unwrap();
let holder = f.as_holder();
let holder = f.into_holder();
let ans: syn::Type = syn::parse_str("THolder").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(holder), ans);

let ty: syn::Type = syn::parse_str("Option<T>").unwrap();
let f: FieldType = ty.try_into().unwrap();
let holder = f.as_holder();
let holder = f.into_holder();
let ans: syn::Type = syn::parse_str("Option<THolder>").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(holder), ans);

let ty: syn::Type = syn::parse_str("Vec<T>").unwrap();
let f: FieldType = ty.try_into().unwrap();
let holder = f.as_holder();
let holder = f.into_holder();
let ans: syn::Type = syn::parse_str("Vec<THolder>").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(holder), ans);

let ty: syn::Type = syn::parse_str("Option<Vec<T>>").unwrap();
let f: FieldType = ty.try_into().unwrap();
let holder = f.as_holder();
let holder = f.into_holder();
let ans: syn::Type = syn::parse_str("Option<Vec<THolder>>").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(holder), ans);
}
Expand All @@ -208,27 +208,27 @@ mod tests {
fn as_place_holder() {
let ty: syn::Type = syn::parse_str("T").unwrap();
let f: FieldType = ty.try_into().unwrap();
let place_holder = f.as_holder().as_place_holder();
let place_holder = f.into_holder().into_place_holder();
let ans: syn::Type = syn::parse_str("::ruststep::tables::PlaceHolder<THolder>").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(place_holder), ans);

let ty: syn::Type = syn::parse_str("Option<T>").unwrap();
let f: FieldType = ty.try_into().unwrap();
let place_holder = f.as_holder().as_place_holder();
let place_holder = f.into_holder().into_place_holder();
let ans: syn::Type =
syn::parse_str("Option<::ruststep::tables::PlaceHolder<THolder>>").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(place_holder), ans);

let ty: syn::Type = syn::parse_str("Vec<T>").unwrap();
let f: FieldType = ty.try_into().unwrap();
let place_holder = f.as_holder().as_place_holder();
let place_holder = f.into_holder().into_place_holder();
let ans: syn::Type =
syn::parse_str("Vec<::ruststep::tables::PlaceHolder<THolder>>").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(place_holder), ans);

let ty: syn::Type = syn::parse_str("Option<Vec<T>>").unwrap();
let f: FieldType = ty.try_into().unwrap();
let place_holder = f.as_holder().as_place_holder();
let place_holder = f.into_holder().into_place_holder();
let ans: syn::Type =
syn::parse_str("Option<Vec<::ruststep::tables::PlaceHolder<THolder>>>").unwrap();
assert_eq!(<FieldType as Into<syn::Type>>::into(place_holder), ans);
Expand Down
2 changes: 1 addition & 1 deletion ruststep-derive/src/type_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl FieldEntries {
}),
FieldType::Boxed(_) => abort_call_site!("Unexpected Box<T>"),
}
holder_types.push(ft.as_holder().as_place_holder().into());
holder_types.push(ft.into_holder().into_place_holder().into());
} else {
into_owned.push(quote! { self.#index });
holder_types.push(ft.into());
Expand Down
2 changes: 1 addition & 1 deletion ruststep/src/ast/de/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'de, 'record> de::Deserializer<'de> for &'record Record {
{
if name == self.name {
if let Parameter::List(ref parameters) = self.parameter {
return visitor.visit_map(RecordStructDeserializer::new(fields, &parameters));
return visitor.visit_map(RecordStructDeserializer::new(fields, parameters));
}
}
Self::deserialize_any(self, visitor)
Expand Down
2 changes: 1 addition & 1 deletion ruststep/src/ast/de/subsuper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'de, 'record> de::MapAccess<'de> for SubSuperRecordDeserializer<'record> {
let key: K::Value = seed.deserialize(key)?;
Ok(Some(key))
} else {
return Ok(None);
Ok(None)
}
}

Expand Down
2 changes: 2 additions & 0 deletions ruststep/src/parser/basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Parser for basic alphabets defined in the table 1 of ISO-10303-21
#![allow(clippy::manual_is_ascii_check)]

use super::combinator::*;
use nom::{
branch::alt,
Expand Down
2 changes: 1 addition & 1 deletion ruststep/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn insert_record<'de, T: de::Deserialize<'de>>(
id: u64,
record: &Record,
) -> crate::error::Result<()> {
if let Some(_) = table.insert(id, de::Deserialize::deserialize(record)?) {
if table.insert(id, de::Deserialize::deserialize(record)?).is_some() {
Err(Error::DuplicatedEntity(id))
} else {
Ok(())
Expand Down

0 comments on commit 7d2e11b

Please sign in to comment.