Skip to content

Commit 95a1626

Browse files
committed
Remove TryInto support from gix_macros::momo
Part of the reason is that `impl TryInto` isn't as common as `AsRef`, `AsMut` or `Into`, but also because its error handling logic is much harder to parse and replace in the inner function. Signed-off-by: Jiahao XU <[email protected]>
1 parent e760225 commit 95a1626

File tree

1 file changed

+0
-33
lines changed

1 file changed

+0
-33
lines changed

gix-macros/src/lib.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use syn::{fold::Fold, punctuated::Punctuated, spanned::Spanned, *};
88
// All conversions we support. Check references to this type for an idea how to add more.
99
enum Conversion<'a> {
1010
Into(&'a Type),
11-
TryInto(&'a Type),
1211
AsRef(&'a Type),
1312
AsMut(&'a Type),
1413
}
@@ -17,7 +16,6 @@ impl<'a> Conversion<'a> {
1716
fn target_type(&self) -> Type {
1817
match *self {
1918
Conversion::Into(ty) => ty.clone(),
20-
Conversion::TryInto(ty) => ty.clone(),
2119
Conversion::AsRef(ty) => parse_quote!(&#ty),
2220
Conversion::AsMut(ty) => parse_quote!(&mut #ty),
2321
}
@@ -26,7 +24,6 @@ impl<'a> Conversion<'a> {
2624
fn conversion_expr(&self, i: Ident) -> Expr {
2725
match *self {
2826
Conversion::Into(_) => parse_quote!(#i.into()),
29-
Conversion::TryInto(_) => parse_quote!(#i.try_into()?),
3027
Conversion::AsRef(_) => parse_quote!(#i.as_ref()),
3128
Conversion::AsMut(_) => parse_quote!(#i.as_mut()),
3229
}
@@ -52,8 +49,6 @@ fn parse_bounds(bounds: &Punctuated<TypeParamBound, Token![+]>) -> Option<Conver
5249
if let GenericArgument::Type(ref arg_ty) = gen_args.args.first().unwrap() {
5350
if seg.ident == "Into" {
5451
return Some(Conversion::Into(arg_ty));
55-
} else if seg.ident == "TryInto" {
56-
return Some(Conversion::TryInto(arg_ty));
5752
} else if seg.ident == "AsRef" {
5853
return Some(Conversion::AsRef(arg_ty));
5954
} else if seg.ident == "AsMut" {
@@ -145,7 +140,6 @@ fn convert<'a>(
145140
let mut argtypes = Punctuated::new();
146141
let mut conversions = Conversions {
147142
intos: Vec::new(),
148-
try_intos: Vec::new(),
149143
as_refs: Vec::new(),
150144
as_muts: Vec::new(),
151145
};
@@ -205,7 +199,6 @@ fn convert<'a>(
205199

206200
struct Conversions {
207201
intos: Vec<Ident>,
208-
try_intos: Vec<Ident>,
209202
as_refs: Vec<Ident>,
210203
as_muts: Vec<Ident>,
211204
}
@@ -214,7 +207,6 @@ impl Conversions {
214207
fn add(&mut self, ident: Ident, conv: Conversion) {
215208
match conv {
216209
Conversion::Into(_) => self.intos.push(ident),
217-
Conversion::TryInto(_) => self.try_intos.push(ident),
218210
Conversion::AsRef(_) => self.as_refs.push(ident),
219211
Conversion::AsMut(_) => self.as_muts.push(ident),
220212
}
@@ -238,7 +230,6 @@ impl Fold for Conversions {
238230
match expr {
239231
Expr::MethodCall(mc) if mc.args.is_empty() => match &*mc.method.to_string() {
240232
"into" if has_conversion(&self.intos, &mc.receiver) => *mc.receiver,
241-
"try_into" if has_conversion(&self.try_intos, &mc.receiver) => *mc.receiver,
242233

243234
"as_ref" if has_conversion(&self.as_refs, &mc.receiver) => *mc.receiver,
244235
"as_mut" if has_conversion(&self.as_muts, &mc.receiver) => *mc.receiver,
@@ -251,7 +242,6 @@ impl Fold for Conversions {
251242
..
252243
}) if segments.len() == 2 => match (&*segments[0].ident.to_string(), &*segments[1].ident.to_string()) {
253244
("Into", "into") if has_conversion(&self.intos, &call.args[0]) => call.args[0].clone(),
254-
("TryInto", "try_into") if has_conversion(&self.try_intos, &call.args[0]) => call.args[0].clone(),
255245

256246
("AsRef", "as_ref") if matches!(&call.args[0], Expr::Reference(ExprReference { expr, mutability: None, .. }) if has_conversion(&self.as_refs, expr)) => {
257247
if let Expr::Reference(ExprReference { expr, .. }) = &call.args[0] {
@@ -272,29 +262,6 @@ impl Fold for Conversions {
272262
},
273263
_ => syn::fold::fold_expr(self, Expr::Call(call)),
274264
},
275-
Expr::Try(expr_try) => match &*expr_try.expr {
276-
Expr::MethodCall(mc)
277-
if mc.args.is_empty()
278-
&& mc.method == "try_into"
279-
&& has_conversion(&self.try_intos, &mc.receiver) =>
280-
{
281-
(*mc.receiver).clone()
282-
}
283-
Expr::Call(call) if call.args.len() == 1 => match &*call.func {
284-
Expr::Path(ExprPath {
285-
path: Path { segments, .. },
286-
..
287-
}) if segments.len() == 2
288-
&& segments[0].ident == "TryInto"
289-
&& segments[1].ident == "try_into"
290-
&& has_conversion(&self.try_intos, &call.args[0]) =>
291-
{
292-
call.args[0].clone()
293-
}
294-
_ => syn::fold::fold_expr(self, Expr::Try(expr_try)),
295-
},
296-
_ => syn::fold::fold_expr(self, Expr::Try(expr_try)),
297-
},
298265
_ => syn::fold::fold_expr(self, expr),
299266
}
300267
}

0 commit comments

Comments
 (0)