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

unsafe code warn causes: "implementation of an unsafe trait" #4394

Closed
konstin opened this issue Jul 30, 2024 · 1 comment · Fixed by #4396
Closed

unsafe code warn causes: "implementation of an unsafe trait" #4394

konstin opened this issue Jul 30, 2024 · 1 comment · Fixed by #4396
Labels

Comments

@konstin
Copy link
Member

konstin commented Jul 30, 2024

Bug Description

When trying to update to pyo3 0.22 in astral-sh/uv#5590, i get the errors implementation of an unsafe trait and usage of an unsafe block, even though i don't use any unsafe in my code.

pyo3 should place appropriate annotations on generated code

Steps to Reproduce

[package]
name = "pyo3-unsafe"
version = "0.1.0"
edition = "2021"

[lints.rust]
unsafe_code = "warn"

[dependencies]
pyo3 = { version = "0.22.2", features = ["extension-module", "abi3-py37"] }
use std::hash::Hash;

use pyo3::pyclass;

#[derive(Eq, Ord, PartialEq, PartialOrd, Clone)]
#[pyclass(get_all)]
pub struct VersionSpecifier {
    pub(crate) operator: Operator,
    pub(crate) version: Version,
}

#[derive(Eq, Ord, PartialEq, PartialOrd, Debug, Hash, Clone, Copy)]
#[pyo3::pyclass(eq, eq_int)]
pub enum Operator {
    Equal,
}

#[derive(Clone, Eq, PartialEq, PartialOrd, Ord)]
#[pyclass]
pub struct Version;

cargo check:

warning: implementation of an `unsafe` trait
 --> src/lib.rs:8:26
  |
8 |     pub(crate) operator: Operator,
  |                          ^^^^^^^^
  |
  = note: requested on the command line with `-W unsafe-code`

warning: usage of an `unsafe` block
 --> src/lib.rs:8:26
  |
8 |     pub(crate) operator: Operator,
  |                          ^^^^^^^^

warning: implementation of an `unsafe` trait
 --> src/lib.rs:9:25
  |
9 |     pub(crate) version: Version,
  |                         ^^^^^^^

warning: usage of an `unsafe` block
 --> src/lib.rs:9:25
  |
9 |     pub(crate) version: Version,
  |                         ^^^^^^^

warning: 4 warnings emitted

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.80.0 (051478957 2024-07-21)

Your PyO3 version

0.22

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

pyenv opt build

Additional Info

No response

@LilyFoote
Copy link
Contributor

I can replicate this. Looking into a fix.

LilyFoote added a commit to LilyFoote/pyo3 that referenced this issue Jul 30, 2024
LilyFoote added a commit to LilyFoote/pyo3 that referenced this issue Jul 30, 2024
LilyFoote added a commit to LilyFoote/pyo3 that referenced this issue Jul 30, 2024
LilyFoote added a commit to LilyFoote/pyo3 that referenced this issue Jul 30, 2024
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