emit compile errors on macros inside `#[pymethods]`

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
This commit is contained in:
David Hewitt 2023-10-02 21:49:19 +01:00
parent f335f42197
commit a1d333a563
4 changed files with 23 additions and 1 deletions

View File

@ -0,0 +1 @@
Emit compile errors instead of ignoring macro invocations inside `#[pymethods]` blocks.

View File

@ -149,7 +149,12 @@ pub fn impl_methods(
}
}
}
_ => (),
syn::ImplItem::Macro(m) => bail_spanned!(
m.span() =>
"macros cannot be used as items in `#[pymethods]` impl blocks\n\
= note: this was previously accepted and ignored"
),
_ => {}
}
}

View File

@ -170,4 +170,13 @@ impl DuplicateMethod {
fn func_b(&self) {}
}
macro_rules! macro_invocation {
() => {};
}
#[pymethods]
impl MyClass {
macro_invocation!();
}
fn main() {}

View File

@ -133,6 +133,13 @@ error: Python objects are shared, so 'self' cannot be moved out of the Python in
144 | fn method_self_by_value(self) {}
| ^^^^
error: macros cannot be used as items in `#[pymethods]` impl blocks
= note: this was previously accepted and ignored
--> tests/ui/invalid_pymethods.rs:179:5
|
179 | macro_invocation!();
| ^^^^^^^^^^^^^^^^
error[E0119]: conflicting implementations of trait `pyo3::impl_::pyclass::PyClassNewTextSignature<TwoNew>` for type `pyo3::impl_::pyclass::PyClassImplCollector<TwoNew>`
--> tests/ui/invalid_pymethods.rs:149:1
|