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

Confusing error message when using #[pyclass] with a struct called Probe #4792

Closed
Tiwalun opened this issue Dec 12, 2024 · 1 comment · Fixed by #4794
Closed

Confusing error message when using #[pyclass] with a struct called Probe #4792

Tiwalun opened this issue Dec 12, 2024 · 1 comment · Fixed by #4794
Labels

Comments

@Tiwalun
Copy link

Tiwalun commented Dec 12, 2024

Bug Description

The following code fails to compile, with a somewhat confusing error message:

use pyo3::prelude::*;

#[pyclass]
struct Probe {}

The error message is:

error[E0782]: expected a type, found a trait
 --> src/lib.rs:4:8
  |
4 | struct Probe {}
  |        ^^^^^
  |
help: you can add the `dyn` keyword if you want a trait object
  |
4 | struct dyn Probe {}
  |        +++

For more information about this error, try `rustc --explain E0782`.
error: could not compile `pyo3-repro` (lib) due to 1 previous error

rust-analyzer suggests that this might be due to the trait Probe here:

pub trait Probe {

I'm not sure if this can be fixed, but it would be nice to at least have a clearer error message to indicate that the struct can't be called Probe.

Steps to Reproduce

Compile the code mentioned above.

Backtrace

No response

Your operating system and version

Ubuntu 24.04

Your Python version (python --version)

Python 3.12.3

Your Rust version (rustc --version)

rustc 1.83.0 (90b35a623 2024-11-26)

Your PyO3 version

0.23.3

How did you install python? Did you use a virtualenv?

apt

Additional Info

This was observed when updating PyO3 from version 0.21 to 0.22, so it seems to have changed in version 0.22.

@Icxolu
Copy link
Contributor

Icxolu commented Dec 12, 2024

Thanks for reporting, should be fixed by #4794.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants