Skip to content

Commit 64944f8

Browse files
committed
cargo clippy
1 parent 20c9453 commit 64944f8

File tree

10 files changed

+37
-53
lines changed

10 files changed

+37
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct MultipleHandlers<T> {
6262
#[typle(Tuple for 0..=3)]
6363
impl<T> HandleStuff for MultipleHandlers<T>
6464
where
65-
T: Tuple, // `T`` is a tuple with 0 to 3 components.
65+
T: Tuple, // `T` is a tuple with 0 to 3 components.
6666
T<_>: HandleStuff, // All components implement `HandleStuff`.
6767
{
6868
type Output = (typle! {i in .. => T<{i}>::Output});

src/constant.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,22 @@ pub fn evaluate_range(
7777
}
7878
}
7979
Expr::Range(range) => {
80-
let start = range
81-
.start
82-
.as_ref()
83-
.map(|start_expr| {
84-
Bound::Included(
85-
evaluate_usize(start_expr)
86-
.map(Ok)
87-
.unwrap_or_else(|| Err(start_expr.span())),
88-
)
89-
})
90-
.unwrap_or(Bound::Unbounded);
91-
let end = range
92-
.end
93-
.as_ref()
94-
.map(|end_expr| {
95-
let end = evaluate_usize(end_expr)
80+
let start = range.start.as_ref().map_or(Bound::Unbounded, |start_expr| {
81+
Bound::Included(
82+
evaluate_usize(start_expr)
9683
.map(Ok)
97-
.unwrap_or_else(|| Err(end_expr.span()));
98-
match range.limits {
99-
syn::RangeLimits::HalfOpen(_) => Bound::Excluded(end),
100-
syn::RangeLimits::Closed(_) => Bound::Included(end),
101-
}
102-
})
103-
.unwrap_or(Bound::Unbounded);
84+
.unwrap_or_else(|| Err(start_expr.span())),
85+
)
86+
});
87+
let end = range.end.as_ref().map_or(Bound::Unbounded, |end_expr| {
88+
let end = evaluate_usize(end_expr)
89+
.map(Ok)
90+
.unwrap_or_else(|| Err(end_expr.span()));
91+
match range.limits {
92+
syn::RangeLimits::HalfOpen(_) => Bound::Excluded(end),
93+
syn::RangeLimits::Closed(_) => Bound::Included(end),
94+
}
95+
});
10496
return Some((start, end));
10597
}
10698
_ => {}

src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ use crate::TypleMacro;
3030
#[derive(Clone)]
3131
pub enum Typle {
3232
// `Typle<C>`: the name C of the type for all components (concrete or generic)
33-
Specific(Type),
33+
Specific(Box<Type>),
3434
// `Typle`: the invented name for each component
3535
Generic(Rc<Vec<String>>),
3636
}
3737

3838
impl Typle {
3939
pub fn get(&self, i: usize, span: Span) -> Type {
4040
match self {
41-
Typle::Specific(r#type) => r#type.clone(),
41+
Typle::Specific(r#type) => (**r#type).clone(),
4242
Typle::Generic(v) => Type::Path(syn::TypePath {
4343
qself: None,
4444
path: ident_to_path(Ident::new(&v[i], span)),
@@ -222,7 +222,7 @@ impl TypleContext {
222222
)
223223
);
224224
}
225-
result = Some(Typle::Specific(ty.clone()));
225+
result = Some(Typle::Specific(Box::new(ty.clone())));
226226
continue;
227227
}
228228
PathArguments::Parenthesized(arguments) => {

src/context/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl TypleContext {
110110
};
111111
if let Some(tt) = tokens.next() {
112112
abort!(tt, "unexpected token in typle_index");
113-
};
113+
}
114114
let Some((start, end)) = evaluate_range(&for_loop.expr) else {
115115
abort!(for_loop.expr, "expected range");
116116
};

src/context/generic_param.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn handle_type(
8080
bounds: Punctuated::new(),
8181
eq_token: None,
8282
default: None,
83-
}))
83+
}));
8484
}
8585
GenericParam::Const(_) => {
8686
output.push(param.clone());
@@ -95,7 +95,7 @@ fn handle_type(
9595
Type::Reference(type_reference) => {
9696
if let Some(lifetime) = &type_reference.lifetime {
9797
if let Some(param) = param_map.lifetimes.remove(&lifetime.ident) {
98-
output.push(GenericParam::Lifetime(param.clone()))
98+
output.push(GenericParam::Lifetime(param.clone()));
9999
}
100100
}
101101
handle_type(&type_reference.elem, param_map, output);

src/context/pat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl TypleContext {
116116
mut pat: Pat,
117117
) -> Replacements<impl Iterator<Item = syn::Result<Pat>>> {
118118
let mut state = BlockState::default();
119+
#[allow(clippy::single_match)]
119120
match &mut pat {
120121
Pat::Macro(syn::PatMacro { mac, .. }) => {
121122
if let Some(ident) = mac.path.get_ident() {

src/context/shared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl TypleContext {
262262
let ty_segment = ty_path.segments.first().unwrap();
263263
let segment = path.segments.first_mut().unwrap();
264264
*segment = ty_segment.clone();
265-
*qself = ty_qself.clone();
265+
qself.clone_from(ty_qself);
266266
path.leading_colon = ty_path.leading_colon;
267267
}
268268
_ => {

src/context/type.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ impl TypleContext {
127127
(iter.next(), iter.next())
128128
{
129129
let mut state = BlockState::default();
130-
match self.replace_expr(expr, &mut state) {
131-
Ok(_) => {}
132-
Err(e) => return Replacements::Singleton(Err(e)),
130+
if let Err(err) = self.replace_expr(expr, &mut state) {
131+
return Replacements::Singleton(Err(err));
133132
}
134133
if let Some((start, end)) = evaluate_range(expr) {
135134
// T<{..}>

src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@
120120
//! - `T<0>: Clone` - the first component of the tuple implements the `Clone` trait.
121121
//! - `T<{1..=2}>: Clone` - the second and third components implement the `Clone` trait.
122122
//! - `typle!(j in .. => I<{j}>: Iterator<Item=T<{j}>>): Tuple::Bounds` - the most
123-
//! general way to bound components, allowing typle index expressions on both
124-
//! sides of the colon. Note that the suffix `: Tuple::Bounds` is required after
125-
//! the macro, where `Tuple` is the name of the typle trait.
123+
//! general way to bound components, allowing typle index expressions on both
124+
//! sides of the colon. Note that the suffix `: Tuple::Bounds` is required after
125+
//! the macro, where `Tuple` is the name of the typle trait.
126126
//!
127127
//! ```rust
128128
//! # use typle::typle;
@@ -351,12 +351,8 @@
351351
//! T<_>: Extract,
352352
//! {
353353
//! // The output of all previous components plus the state of the current component.
354-
//! S = typle_variant!(
355-
//! curr in ..T::MAX => (
356-
//! typle! {
357-
//! prev in ..curr => T::<{prev}>::Output
358-
//! }
359-
//! ),
354+
//! S = typle_variant!(curr in ..T::MAX =>
355+
//! (typle! {prev in ..curr => T::<{prev}>::Output}),
360356
//! Option<T<{curr}>::State>
361357
//! ),
362358
//! }
@@ -408,8 +404,9 @@
408404
//! # T: Tuple,
409405
//! # T<_>: Extract,
410406
//! # {
411-
//! # S = typle_variant!(i in ..T::MAX =>
412-
//! # (typle!(j in ..i => T::<{j}>::Output)), Option<T<{i}>::State>
407+
//! # S = typle_variant!(curr in ..T::MAX =>
408+
//! # (typle! {prev in ..curr => T::<{prev}>::Output}),
409+
//! # Option<T<{curr}>::State>
413410
//! # ),
414411
//! # }
415412
//! // Relevant traits may need to be implemented for the never type.
@@ -591,7 +588,7 @@
591588
//! }
592589
//! ```
593590
//! - Typle index variables can be shadowed by inner typle index variables
594-
//! but cannot be shadowed by standard variables:
591+
//! but cannot be shadowed by standard variables:
595592
//! ```rust
596593
//! # use typle::typle;
597594
//! # #[typle(Tuple for 1..=1)]
@@ -631,7 +628,6 @@
631628
//! }
632629
//! test_macro((0, 1, 2));
633630
//! ```
634-
//!
635631
636632
mod constant;
637633
mod context;

tests/compile/doc_typle.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ mod tuple {
6262
T: Tuple,
6363
T<_>: Extract,
6464
{
65-
S = typle_variant!(
66-
curr in ..T::MAX => (
67-
typle! {
68-
prev in ..curr => T::<{prev}>::Output
69-
}
70-
),
65+
S = typle_variant!(curr in ..T::MAX =>
66+
(typle! {prev in ..curr => T::<{prev}>::Output}),
7167
Option<T<{curr}>::State>
7268
),
7369
}

0 commit comments

Comments
 (0)