@@ -11,15 +11,14 @@ pub(crate) fn inner(code: proc_macro2::TokenStream) -> proc_macro2::TokenStream
11
11
12
12
if let Item :: Fn ( item_fn) = fn_item {
13
13
let ty_conversions = parse_generics ( & item_fn. sig ) ;
14
- // TODO: uncomment and see it fail in places where it should actually succeed.
15
- // if ty_conversions.is_empty() {
16
- // return Error::new(
17
- // item_fn.span(),
18
- // "Couldn't apply a single conversion - momo is ineffective here",
19
- // )
20
- // .to_compile_error();
21
- // }
22
- let ( argtypes, argexprs, has_self) = convert ( & item_fn. sig . inputs , & ty_conversions) ;
14
+ let ( has_conversion_in_effect, argtypes, argexprs, has_self) = convert ( & item_fn. sig . inputs , & ty_conversions) ;
15
+ if !has_conversion_in_effect {
16
+ return Error :: new (
17
+ proc_macro2:: Span :: call_site ( ) ,
18
+ "Couldn't apply a single conversion - momo is ineffective here" ,
19
+ )
20
+ . to_compile_error ( ) ;
21
+ }
23
22
24
23
let uses_self = has_self
25
24
|| item_fn. sig . inputs . iter ( ) . any ( has_self_type)
@@ -171,7 +170,8 @@ fn parse_generics(decl: &Signature) -> HashMap<Ident, Conversion<'_>> {
171
170
fn convert < ' a > (
172
171
inputs : & ' a Punctuated < FnArg , Token ! [ , ] > ,
173
172
ty_conversions : & HashMap < Ident , Conversion < ' a > > ,
174
- ) -> ( Punctuated < FnArg , Token ! [ , ] > , Punctuated < Expr , Token ! [ , ] > , bool ) {
173
+ ) -> ( bool , Punctuated < FnArg , Token ! [ , ] > , Punctuated < Expr , Token ! [ , ] > , bool ) {
174
+ let mut has_conversion_in_effect = false ;
175
175
let mut argtypes = Punctuated :: new ( ) ;
176
176
let mut argexprs = Punctuated :: new ( ) ;
177
177
let mut has_self = false ;
@@ -210,6 +210,7 @@ fn convert<'a>(
210
210
match * pat_type. ty {
211
211
Type :: ImplTrait ( TypeImplTrait { ref bounds, .. } ) => {
212
212
if let Some ( conv) = parse_bounds ( bounds) {
213
+ has_conversion_in_effect = true ;
213
214
argexprs. push ( conv. conversion_expr ( ident) ) ;
214
215
if let Conversion :: AsMut ( _) = conv {
215
216
pat_ident. mutability = Some ( Default :: default ( ) ) ;
@@ -220,6 +221,7 @@ fn convert<'a>(
220
221
}
221
222
Type :: Path ( ..) => {
222
223
if let Some ( conv) = parse_bounded_type ( & pat_type. ty ) . and_then ( |ident| ty_conversions. get ( & ident) ) {
224
+ has_conversion_in_effect = true ;
223
225
argexprs. push ( conv. conversion_expr ( ident) ) ;
224
226
if let Conversion :: AsMut ( _) = conv {
225
227
pat_ident. mutability = Some ( Default :: default ( ) ) ;
@@ -237,7 +239,7 @@ fn convert<'a>(
237
239
argtypes. push ( FnArg :: Typed ( pat_type) ) ;
238
240
}
239
241
} ) ;
240
- ( argtypes, argexprs, has_self)
242
+ ( has_conversion_in_effect , argtypes, argexprs, has_self)
241
243
}
242
244
243
245
fn contains_self_type_path ( path : & Path ) -> bool {
0 commit comments