Skip to content

Commit

Permalink
Add UI test to ensure only bare &self can be passed into traverse.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed May 20, 2023
1 parent e309a8e commit 3ee383e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn _test_compile_errors() {
t.compile_fail("tests/ui/invalid_pymethod_names.rs");
t.compile_fail("tests/ui/invalid_pymodule_args.rs");
t.compile_fail("tests/ui/reject_generics.rs");
t.compile_fail("tests/ui/traverse_bare_self.rs");

tests_rust_1_49(&t);
tests_rust_1_56(&t);
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/traverse_bare_self.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use pyo3::prelude::*;
use pyo3::PyVisit;

#[pyclass]
struct TraverseTriesToTakePyRef {}

#[pymethods]
impl TraverseTriesToTakePyRef {
fn __traverse__(slf: PyRef<Self>, visit: PyVisit) {}
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/traverse_bare_self.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> tests/ui/traverse_bare_self.rs:8:6
|
7 | #[pymethods]
| ------------ arguments to this function are incorrect
8 | impl TraverseTriesToTakePyRef {
| ______^
9 | | fn __traverse__(slf: PyRef<Self>, visit: PyVisit) {}
| |___________________^ expected fn pointer, found fn item
|
= note: expected fn pointer `for<'a, 'b> fn(&'a TraverseTriesToTakePyRef, PyVisit<'b>) -> Result<(), PyTraverseError>`
found fn item `for<'a, 'b> fn(pyo3::PyRef<'a, TraverseTriesToTakePyRef>, PyVisit<'b>) {TraverseTriesToTakePyRef::__traverse__}`
note: function defined here
--> src/impl_/pymethods.rs
|
| pub unsafe fn call_traverse_impl<T>(
| ^^^^^^^^^^^^^^^^^^

0 comments on commit 3ee383e

Please sign in to comment.