Skip to content

Commit

Permalink
Nightly formatting
Browse files Browse the repository at this point in the history
Signed-off-by: benhhack <[email protected]>
  • Loading branch information
benhhack committed Oct 10, 2023
1 parent 69aea73 commit 18345dd
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 35 deletions.
6 changes: 3 additions & 3 deletions core/src/smartcontracts/isi/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,11 @@ pub mod isi {
/// Asset-related query implementations.
pub mod query {
use eyre::{Result, WrapErr as _};

use iroha_data_model::{
asset::{Asset, AssetDefinition},
query::{asset::FindAssetDefinitionById, error::QueryExecutionFail as Error, MetadataValue},
query::{
asset::FindAssetDefinitionById, error::QueryExecutionFail as Error, MetadataValue,
},
};

use super::*;
Expand Down Expand Up @@ -699,5 +700,4 @@ pub mod query {
.map(Into::into)
}
}

}
15 changes: 12 additions & 3 deletions data_model/derive/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,27 @@ enum EventVariant {
impl FromVariant for EventVariant {
fn from_variant(variant: &Variant) -> darling::Result<Self> {
let syn2::Fields::Unnamed(fields) = &variant.fields else {
return Err(darling::Error::custom("Expected an enum with unnamed fields").with_span(&variant.fields));
return Err(
darling::Error::custom("Expected an enum with unnamed fields")
.with_span(&variant.fields),
);
};
// note: actually, we have only one field in the event variants
// this is not enforced by this macro, but by `IntoSchema`
let Some(first_field_ty) = fields.unnamed.first().map(|v| &v.ty) else {
return Err(darling::Error::custom("Expected at least one field").with_span(&fields));
};
let syn2::Type::Path(path) = first_field_ty else {
return Err(darling::Error::custom("Only identifiers supported as event types").with_span(first_field_ty));
return Err(
darling::Error::custom("Only identifiers supported as event types")
.with_span(first_field_ty),
);
};
let Some(first_field_ty_name) = path.path.get_ident() else {
return Err(darling::Error::custom("Only identifiers supported as event types").with_span(first_field_ty));
return Err(
darling::Error::custom("Only identifiers supported as event types")
.with_span(first_field_ty),
);
};

// What clippy suggests is much less readable in this case
Expand Down
4 changes: 3 additions & 1 deletion data_model/derive/src/has_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ impl FromDeriveInput for HasOriginEnum {
let ident = input.ident.clone();
let generics = input.generics.clone();

let Some(variants) = darling::ast::Data::<HasOriginVariant, ()>::try_from(&input.data)?.take_enum() else {
let Some(variants) =
darling::ast::Data::<HasOriginVariant, ()>::try_from(&input.data)?.take_enum()
else {
return Err(darling::Error::custom("Expected enum"));
};

Expand Down
2 changes: 1 addition & 1 deletion data_model/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ pub fn has_origin_derive(input: TokenStream) -> TokenStream {
let mut emitter = Emitter::new();

let Some(input) = emitter.handle(syn2::parse2(input)) else {
return emitter.finish_token_stream()
return emitter.finish_token_stream();
};

let result = has_origin::impl_has_origin(&mut emitter, &input);
Expand Down
10 changes: 6 additions & 4 deletions ffi/derive/src/attr_parse/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ impl FromAttributes for DeriveAttrs {

for attr in attrs {
if attr.path().is_ident("derive") {
let Some(list) = accumulator.handle(attr.meta.require_list().map_err(Into::into)) else {
continue
let Some(list) = accumulator.handle(attr.meta.require_list().map_err(Into::into))
else {
continue;
};
let Some(paths) = accumulator.handle(
list.parse_args_with(Punctuated::<syn2::Path, Token![,]>::parse_terminated).map_err(Into::into)
list.parse_args_with(Punctuated::<syn2::Path, Token![,]>::parse_terminated)
.map_err(Into::into),
) else {
continue
continue;
};

for path in paths {
Expand Down
15 changes: 11 additions & 4 deletions ffi/derive/src/attr_parse/getset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,17 @@ impl GetSetRawFieldAttr {
// iroha doesn't use the latter form, so it is not supported by `iroha_ffi_derive`
if attr.path().is_ident("getset") {
let Some(list) = accumulator.handle(attr.meta.require_list().map_err(Into::into))
else { continue };
let Some(tokens): Option<Punctuated<SpannedGetSetAttrToken, Token![,]>>
= accumulator.handle(list.parse_args_with(Punctuated::parse_terminated).map_err(Into::into))
else { continue };
else {
continue;
};
let Some(tokens): Option<Punctuated<SpannedGetSetAttrToken, Token![,]>> =
accumulator.handle(
list.parse_args_with(Punctuated::parse_terminated)
.map_err(Into::into),
)
else {
continue;
};

for token in tokens {
match token.token {
Expand Down
2 changes: 1 addition & 1 deletion ffi/derive/src/attr_parse/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl FromAttributes for Repr {
),
Meta::List(list) => {
let Some(tokens) = accumulator.handle(
syn2::parse2::<ReprTokens>(list.tokens.clone()).map_err(Into::into)
syn2::parse2::<ReprTokens>(list.tokens.clone()).map_err(Into::into),
) else {
continue;
};
Expand Down
49 changes: 32 additions & 17 deletions ffi/derive/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl syn2::parse::Parse for SpannedFfiTypeToken {
fn parse(input: ParseStream) -> syn2::Result<Self> {
let (span, token) = input.step(|cursor| {
let Some((token, after_token)) = cursor.ident() else {
return Err(cursor.error("expected ffi type kind"))
return Err(cursor.error("expected ffi type kind"));
};

let mut span = token.span();
Expand All @@ -56,26 +56,35 @@ impl syn2::parse::Parse for SpannedFfiTypeToken {
"opaque" => Ok(((span, FfiTypeToken::Opaque), after_token)),
"local" => Ok(((span, FfiTypeToken::Local), after_token)),
"unsafe" => {
let Some((inside_of_group, group_span, after_group)) = after_token.group(Delimiter::Brace) else {
return Err(cursor.error("expected `{ ... }` after `unsafe`"))
let Some((inside_of_group, group_span, after_group)) =
after_token.group(Delimiter::Brace)
else {
return Err(cursor.error("expected `{ ... }` after `unsafe`"));
};
span = span.join(group_span.span()).unwrap_or(span);

let Some((token, after_token)) = inside_of_group.ident() else {
return Err(cursor.error("expected ffi type kind"))
return Err(cursor.error("expected ffi type kind"));
};
if !after_token.eof() {
return Err(cursor.error("`unsafe { ... }` should only contain one identifier inside"))
return Err(cursor
.error("`unsafe { ... }` should only contain one identifier inside"));
}

let token = token.to_string();
match token.as_str() {
"robust" => Ok(((span, FfiTypeToken::UnsafeRobust), after_group)),
"non_owning" => Ok(((span, FfiTypeToken::UnsafeNonOwning), after_group)),
other => Err(syn2::Error::new(token.span(), format!("unknown unsafe ffi type kind: {}", other))),
other => Err(syn2::Error::new(
token.span(),
format!("unknown unsafe ffi type kind: {}", other),
)),
}
}
other => Err(syn2::Error::new(span, format!("unknown unsafe ffi type kind: {}", other))),
other => Err(syn2::Error::new(
span,
format!("unknown unsafe ffi type kind: {}", other),
)),
}
})?;

Expand Down Expand Up @@ -581,12 +590,10 @@ fn derive_ffi_type_for_data_carrying_enum(
let mut non_local_where_clause = where_clause.unwrap().clone();

for variant in variants {
let Some(ty) = variant_mapper(
emitter, variant,
|| None,
|field| Some(field.ty.clone())
) else {
continue
let Some(ty) =
variant_mapper(emitter, variant, || None, |field| Some(field.ty.clone()))
else {
continue;
};

non_local_where_clause.predicates.push(
Expand Down Expand Up @@ -872,14 +879,22 @@ fn get_enum_repr_type(
// it's an error to use an `#[derive(FfiType)]` on them
// but we still want to generate a reasonable error message, so we check for it here
if !is_empty {
emit!(emitter, enum_name, "Enum representation is not specified. Try adding `#[repr(u32)]` or similar");
emit!(
emitter,
enum_name,
"Enum representation is not specified. Try adding `#[repr(u32)]` or similar"
);
}
return syn2::parse_quote! {u32}
return syn2::parse_quote! {u32};
};

let ReprKind::Primitive(primitive) = &*kind else {
emit!(emitter, &kind.span(), "Enum should have a primitive representation (like `#[repr(u32)]`)");
return syn2::parse_quote! {u32}
emit!(
emitter,
&kind.span(),
"Enum should have a primitive representation (like `#[repr(u32)]`)"
);
return syn2::parse_quote! {u32};
};

match primitive {
Expand Down
3 changes: 2 additions & 1 deletion smart_contract/validator/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,8 @@ pub mod asset_definition {
asset_definition_id: &AssetDefinitionId,
authority: &AccountId,
) -> Result<bool> {
let asset_definition = FindAssetDefinitionById::new(asset_definition_id.clone()).execute()?;
let asset_definition =
FindAssetDefinitionById::new(asset_definition_id.clone()).execute()?;
Ok(asset_definition.owned_by() == authority)
}

Expand Down

0 comments on commit 18345dd

Please sign in to comment.