Skip to content

Commit

Permalink
Use empty structs instead of empty enums for opaque types.
Browse files Browse the repository at this point in the history
Empty enums are uninhabited types and can cause issues like rust-lang/rust#74840

This fixes the compiler warning: static of uninhabited type
  • Loading branch information
dgrunwald committed Feb 17, 2021
1 parent 40c815e commit 06e6109
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion python27-sys/src/dictobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libc::{c_char, c_int};
use crate::object::*;
use crate::pyport::Py_ssize_t;

//pub enum PyDictObject { /* representation hidden */ }
//#[repr(C)] pub struct PyDictObject { /* representation hidden */ }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion python27-sys/src/longobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_
use crate::object::*;
use crate::pyport::Py_ssize_t;

//enum PyLongObject { /* representation hidden */ }
//#[repr(C)] struct PyLongObject { /* representation hidden */ }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion python27-sys/src/pyarena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libc::{c_int, c_void, size_t};
use crate::object::PyObject;

#[allow(missing_copy_implementations)]
pub enum PyArena {}
#[repr(C)] pub struct PyArena { _private: [u8; 0] }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion python27-sys/src/pystate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libc::{c_int, c_long};
use crate::frameobject::PyFrameObject;
use crate::object::PyObject;

pub enum PyInterpreterState {}
#[repr(C)] pub struct PyInterpreterState { _private: [u8; 0] }

pub type Py_tracefunc = unsafe extern "C" fn(
arg1: *mut PyObject,
Expand Down
8 changes: 5 additions & 3 deletions python27-sys/src/pythonrun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ pub struct PyCompilerFlags {
}

#[allow(missing_copy_implementations)]
pub enum Struct__mod {}
#[repr(C)] pub struct Struct__mod { _private: [u8; 0] }

#[allow(missing_copy_implementations)]
pub enum Struct__node {}
#[repr(C)] pub struct Struct__node { _private: [u8; 0] }

#[allow(missing_copy_implementations)]
pub enum Struct_symtable {}
#[repr(C)] pub struct Struct_symtable { _private: [u8; 0] }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion python27-sys/src/setobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libc::c_int;
use crate::object::*;
use crate::pyport::Py_ssize_t;

//enum PySetObject { /* representation hidden */ }
//#[repr(C)] pub struct PySetObject { _private: [u8; 0] }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion python3-sys/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::object::*;
use crate::pyport::Py_ssize_t;

#[cfg(Py_3_8)]
pub enum _PyOpcache {}
#[repr(C)]
pub struct _PyOpcache { _private: [u8; 0] }

#[repr(C)]
#[derive(Copy)]
Expand Down
3 changes: 2 additions & 1 deletion python3-sys/src/frameobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub struct PyTryBlock {
}

#[cfg(Py_LIMITED_API)]
pub enum PyFrameObject {}
#[repr(C)]
pub struct PyFrameObject { _private: [u8; 0] }

#[cfg(not(Py_LIMITED_API))]
#[repr(C)]
Expand Down
3 changes: 2 additions & 1 deletion python3-sys/src/longobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_
use crate::object::*;
use crate::pyport::Py_ssize_t;

pub enum PyLongObject {}
#[repr(C)]
pub struct PyLongObject { _private: [u8; 0] }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion python3-sys/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ pub type vectorcallfunc = unsafe extern "C" fn(
) -> *mut crate::object::PyObject;

#[cfg(Py_LIMITED_API)]
pub enum PyTypeObject {}
#[repr(C)]
pub struct PyTypeObject { _private: [u8; 0] }

#[cfg(not(Py_LIMITED_API))]
mod typeobject {
Expand Down
3 changes: 2 additions & 1 deletion python3-sys/src/pyarena.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub enum PyArena {}
#[repr(C)]
pub struct PyArena { _private: [u8; 0] }
7 changes: 5 additions & 2 deletions python3-sys/src/pystate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ use crate::object::PyObject;
#[cfg(Py_3_6)]
pub const MAX_CO_EXTRA_USERS: libc::c_int = 255;

pub enum PyInterpreterState {}
pub enum PyThreadState {}
#[repr(C)]
pub struct PyInterpreterState { _private: [u8; 0] }

#[repr(C)]
pub struct PyThreadState { _private: [u8; 0] }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
11 changes: 8 additions & 3 deletions python3-sys/src/pythonrun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub struct PyCompilerFlags {
}

#[cfg(not(Py_LIMITED_API))]
pub enum _mod {}
#[repr(C)]
pub struct _mod { _private: [u8; 0] }


#[cfg(not(Py_LIMITED_API))]
#[cfg_attr(windows, link(name = "pythonXY"))]
Expand Down Expand Up @@ -116,8 +118,11 @@ extern "C" {
) -> *mut _mod;
}

pub enum symtable {}
pub enum _node {}
#[repr(C)]
pub struct symtable { _private: [u8; 0] }

#[repr(C)]
pub struct _node { _private: [u8; 0] }

#[inline]
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
Expand Down
3 changes: 2 additions & 1 deletion python3-sys/src/weakrefobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use libc::c_int;

use crate::object::*;

pub enum PyWeakReference {}
#[repr(C)]
pub struct PyWeakReference { _private: [u8; 0] }

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down

0 comments on commit 06e6109

Please sign in to comment.