Skip to content

syn::Result::ok silently discards errors #135

@tamird

Description

@tamird

In my attempt to migrate this crate away from the abandoned proc-macro-error crate I discovered these usages of syn::Result::ok were causing test failures with this diff applied:

diff --git a/crates/test-case-core/src/complex_expr.rs b/crates/test-case-core/src/complex_expr.rs
index e708f2e..2a4334e 100644
--- a/crates/test-case-core/src/complex_expr.rs
+++ b/crates/test-case-core/src/complex_expr.rs
@@ -323,11 +323,11 @@ impl ComplexTestCase {
                         expected_regex: input.parse()?,
                     })
                 } else {
-                    proc_macro_error::abort!(input.span(), "'with-regex' feature is required to use 'matches-regex' keyword");
+                    return Err(input.error("'with-regex' feature is required to use 'matches-regex' keyword"));
                 }
             }
         } else {
-            proc_macro_error::abort!(input.span(), "cannot parse complex expression")
+            return Err(input.error("cannot parse complex expression"));
         })
     }
 }

I realize that these .ok() calls are used in cases where expressions and comments are optional, but it would be better to peek and avoid errors so that these .ok()s can be removed to allow the change above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions