Closed dtolnay closed 1 month ago
Previously, if you wrote a py_module_initializer! invocation with braces around the body like this:
py_module_initializer!
cpython::py_module_initializer!(cpython_minimal, |_py, _m| { Ok(()) });
then rustc would produce this unused_braces warning and suggestion:
unused_braces
warning: unnecessary braces around block return value --> src/lib.rs:1:60 | 1 | cpython::py_module_initializer!(cpython_minimal, |_py, _m| { Ok(()) }); | ^^ ^^ | = note: `#[warn(unused_braces)]` on by default help: remove these braces | 1 - cpython::py_module_initializer!(cpython_minimal, |_py, _m| { Ok(()) }); 1 + cpython::py_module_initializer!(cpython_minimal, |_py, _m| Ok(())); |
However, applying the suggestion would cause the macro invocation to fail to compile.
error: no rules expected the token `(` --> src/lib.rs:1:62 | 1 | cpython::py_module_initializer!(cpython_minimal, |_py, _m| Ok(())); | ^ no rules expected this token in macro call | note: while trying to match meta-variable `$body:tt` --> $CARGO_HOME/registry/src/index.crates.io-6f17d22bba15001f/cpython-0.7.2/src/lib.rs:352:84 | 352 | ($name: ident, $( $_py2: ident, $_py3: ident, )? |$py_id: ident, $m_id: ident| $body: tt) => { | ^^^^^^^^^
This PR makes py_module_initializer! accept body expressions without the brace.
Previously, if you wrote a
py_module_initializer!
invocation with braces around the body like this:then rustc would produce this
unused_braces
warning and suggestion:However, applying the suggestion would cause the macro invocation to fail to compile.
This PR makes
py_module_initializer!
accept body expressions without the brace.