Skip to content

Commit 27a6e6d

Browse files
committed
Fix formattings
1 parent 4fff21b commit 27a6e6d

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

macros/src/item_impl.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use std::collections::HashSet;
22

3-
use PathArguments::AngleBracketed;
43
use proc_macro2::TokenStream;
54
use quote::{quote, quote_spanned, ToTokens};
6-
use syn::{AngleBracketedGenericArguments, Binding, GenericArgument, ImplItem, ItemImpl, Path, PathArguments};
75
use syn::punctuated::Punctuated;
86
use syn::spanned::Spanned;
97
use syn::Token;
8+
use syn::{
9+
AngleBracketedGenericArguments, Binding, GenericArgument, ImplItem, ItemImpl, Path,
10+
PathArguments,
11+
};
12+
use PathArguments::AngleBracketed;
1013

1114
use crate::args::Flag;
1215
use crate::gen_caster::generate_caster;
@@ -19,7 +22,6 @@ pub fn process(flags: &HashSet<Flag>, input: ItemImpl) -> TokenStream {
1922
..
2023
} = input;
2124

22-
2325
let generated = match trait_ {
2426
None => quote_spanned! {
2527
self_ty.span() => compile_error!("#[cast_to] should only be on an impl of a trait");
@@ -42,16 +44,20 @@ pub fn process(flags: &HashSet<Flag>, input: ItemImpl) -> TokenStream {
4244
}
4345

4446
fn fully_bound_trait(path: &Path, items: &Vec<ImplItem>) -> impl ToTokens {
45-
let bindings = items.iter()
46-
.filter_map(|item| if let ImplItem::Type(assoc_ty) = item {
47-
Some(GenericArgument::Binding(Binding {
48-
ident: assoc_ty.ident.to_owned(),
49-
eq_token: Default::default(),
50-
ty: assoc_ty.ty.to_owned(),
51-
}))
52-
} else {
53-
None
54-
}).collect::<Punctuated::<_, Token![,]>>();
47+
let bindings = items
48+
.iter()
49+
.filter_map(|item| {
50+
if let ImplItem::Type(assoc_ty) = item {
51+
Some(GenericArgument::Binding(Binding {
52+
ident: assoc_ty.ident.to_owned(),
53+
eq_token: Default::default(),
54+
ty: assoc_ty.ty.to_owned(),
55+
}))
56+
} else {
57+
None
58+
}
59+
})
60+
.collect::<Punctuated<_, Token![,]>>();
5561

5662
let mut path = path.clone();
5763

@@ -61,16 +67,17 @@ fn fully_bound_trait(path: &Path, items: &Vec<ImplItem>) -> impl ToTokens {
6167

6268
if let Some(last) = path.segments.last_mut() {
6369
match &mut last.arguments {
64-
PathArguments::None => last.arguments = AngleBracketed(AngleBracketedGenericArguments {
65-
colon2_token: None,
66-
lt_token: Default::default(),
67-
args: bindings,
68-
gt_token: Default::default(),
69-
}),
70+
PathArguments::None => {
71+
last.arguments = AngleBracketed(AngleBracketedGenericArguments {
72+
colon2_token: None,
73+
lt_token: Default::default(),
74+
args: bindings,
75+
gt_token: Default::default(),
76+
})
77+
}
7078
AngleBracketed(args) => args.args.extend(bindings),
7179
_ => {}
7280
}
7381
}
7482
path
7583
}
76-

tests/on-trait-impl-assoc-type1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22

3-
use intertrait::*;
43
use intertrait::cast::*;
4+
use intertrait::*;
55

66
struct I32Data(i32);
77

@@ -28,6 +28,6 @@ impl Source for I32Data {}
2828
fn test_cast_to_on_trait_impl_with_assoc_type1() {
2929
let data = I32Data(100);
3030
let source: &dyn Source = &data;
31-
let producer = source.cast::<dyn Producer<Output=i32>>();
31+
let producer = source.cast::<dyn Producer<Output = i32>>();
3232
assert_eq!(producer.unwrap().produce(), data.0);
3333
}

tests/on-trait-impl-assoc-type2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22

3-
use intertrait::*;
43
use intertrait::cast::*;
4+
use intertrait::*;
55

66
struct Data;
77

@@ -30,6 +30,6 @@ impl Source for Data {}
3030
fn test_cast_to_on_trait_impl_with_assoc_type2() {
3131
let data = Data;
3232
let source: &dyn Source = &data;
33-
let concat = source.cast::<dyn Concat<I1=i32, I2=&'static str>>();
33+
let concat = source.cast::<dyn Concat<I1 = i32, I2 = &'static str>>();
3434
assert_eq!(concat.unwrap().concat(101, "hello"), "Data: 101 - hello");
3535
}

tests/on-trait-impl-assoc-type3.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22

3-
use intertrait::*;
43
use intertrait::cast::*;
4+
use intertrait::*;
55

66
struct Data;
77

@@ -30,6 +30,9 @@ impl Source for Data {}
3030
fn test_cast_to_on_trait_impl_with_assoc_type3() {
3131
let data = Data;
3232
let source: &dyn Source = &data;
33-
let concat = source.cast::<dyn Concat<String, I1=i32, I2=&'static str>>();
34-
assert_eq!(concat.unwrap().concat("Data".to_owned(), 101, "hello"), "Data: 101 - hello");
33+
let concat = source.cast::<dyn Concat<String, I1 = i32, I2 = &'static str>>();
34+
assert_eq!(
35+
concat.unwrap().concat("Data".to_owned(), 101, "hello"),
36+
"Data: 101 - hello"
37+
);
3538
}

0 commit comments

Comments
 (0)