Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support applying unused_braces rustc suggestion in py_module_initializer #297

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

dtolnay
Copy link
Contributor

@dtolnay dtolnay commented Jul 30, 2024

Previously, if you wrote a py_module_initializer! invocation with braces around the body like this:

cpython::py_module_initializer!(cpython_minimal, |_py, _m| { Ok(()) });

then rustc would produce this unused_braces warning and suggestion:

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.

@markbt markbt merged commit a60f149 into dgrunwald:master Aug 14, 2024
36 checks passed
@dtolnay dtolnay deleted the body branch August 14, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants