Skip to content

Commit 06e6109

Browse files
committed
Use empty structs instead of empty enums for opaque types.
Empty enums are uninhabited types and can cause issues like rust-lang/rust#74840 This fixes the compiler warning: static of uninhabited type
1 parent 40c815e commit 06e6109

14 files changed

+35
-19
lines changed

python27-sys/src/dictobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use libc::{c_char, c_int};
33
use crate::object::*;
44
use crate::pyport::Py_ssize_t;
55

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

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

python27-sys/src/longobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_
33
use crate::object::*;
44
use crate::pyport::Py_ssize_t;
55

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

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

python27-sys/src/pyarena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use libc::{c_int, c_void, size_t};
33
use crate::object::PyObject;
44

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

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

python27-sys/src/pystate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use libc::{c_int, c_long};
33
use crate::frameobject::PyFrameObject;
44
use crate::object::PyObject;
55

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

88
pub type Py_tracefunc = unsafe extern "C" fn(
99
arg1: *mut PyObject,

python27-sys/src/pythonrun.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ pub struct PyCompilerFlags {
2222
}
2323

2424
#[allow(missing_copy_implementations)]
25-
pub enum Struct__mod {}
25+
#[repr(C)] pub struct Struct__mod { _private: [u8; 0] }
26+
2627
#[allow(missing_copy_implementations)]
27-
pub enum Struct__node {}
28+
#[repr(C)] pub struct Struct__node { _private: [u8; 0] }
29+
2830
#[allow(missing_copy_implementations)]
29-
pub enum Struct_symtable {}
31+
#[repr(C)] pub struct Struct_symtable { _private: [u8; 0] }
3032

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

python27-sys/src/setobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use libc::c_int;
33
use crate::object::*;
44
use crate::pyport::Py_ssize_t;
55

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

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

python3-sys/src/code.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::object::*;
55
use crate::pyport::Py_ssize_t;
66

77
#[cfg(Py_3_8)]
8-
pub enum _PyOpcache {}
8+
#[repr(C)]
9+
pub struct _PyOpcache { _private: [u8; 0] }
910

1011
#[repr(C)]
1112
#[derive(Copy)]

python3-sys/src/frameobject.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub struct PyTryBlock {
1414
}
1515

1616
#[cfg(Py_LIMITED_API)]
17-
pub enum PyFrameObject {}
17+
#[repr(C)]
18+
pub struct PyFrameObject { _private: [u8; 0] }
1819

1920
#[cfg(not(Py_LIMITED_API))]
2021
#[repr(C)]

python3-sys/src/longobject.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_
33
use crate::object::*;
44
use crate::pyport::Py_ssize_t;
55

6-
pub enum PyLongObject {}
6+
#[repr(C)]
7+
pub struct PyLongObject { _private: [u8; 0] }
78

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

python3-sys/src/object.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ pub type vectorcallfunc = unsafe extern "C" fn(
201201
) -> *mut crate::object::PyObject;
202202

203203
#[cfg(Py_LIMITED_API)]
204-
pub enum PyTypeObject {}
204+
#[repr(C)]
205+
pub struct PyTypeObject { _private: [u8; 0] }
205206

206207
#[cfg(not(Py_LIMITED_API))]
207208
mod typeobject {

python3-sys/src/pyarena.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pub enum PyArena {}
1+
#[repr(C)]
2+
pub struct PyArena { _private: [u8; 0] }

python3-sys/src/pystate.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use crate::object::PyObject;
88
#[cfg(Py_3_6)]
99
pub const MAX_CO_EXTRA_USERS: libc::c_int = 255;
1010

11-
pub enum PyInterpreterState {}
12-
pub enum PyThreadState {}
11+
#[repr(C)]
12+
pub struct PyInterpreterState { _private: [u8; 0] }
13+
14+
#[repr(C)]
15+
pub struct PyThreadState { _private: [u8; 0] }
1316

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

python3-sys/src/pythonrun.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ pub struct PyCompilerFlags {
3737
}
3838

3939
#[cfg(not(Py_LIMITED_API))]
40-
pub enum _mod {}
40+
#[repr(C)]
41+
pub struct _mod { _private: [u8; 0] }
42+
4143

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

119-
pub enum symtable {}
120-
pub enum _node {}
121+
#[repr(C)]
122+
pub struct symtable { _private: [u8; 0] }
123+
124+
#[repr(C)]
125+
pub struct _node { _private: [u8; 0] }
121126

122127
#[inline]
123128
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]

python3-sys/src/weakrefobject.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use libc::c_int;
22

33
use crate::object::*;
44

5-
pub enum PyWeakReference {}
5+
#[repr(C)]
6+
pub struct PyWeakReference { _private: [u8; 0] }
67

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

0 commit comments

Comments
 (0)