Skip to content

Commit 215e750

Browse files
authored
Rollup merge of rust-lang#84212 - CDirkx:void, r=m-ou-se
Replace `Void` in `sys` with never type This PR replaces several occurrences in `sys` of the type `enum Void {}` with the Rust never type (`!`). The name `Void` is unfortunate because in other languages (C etc.) it refers to a unit type, not an uninhabited type. Note that the previous stabilization of the never type was reverted, however all uses here are implementation details and not publicly visible.
2 parents fc6194c + 191865d commit 215e750

File tree

18 files changed

+238
-252
lines changed

18 files changed

+238
-252
lines changed

std/src/sys/hermit/fs.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::sys::hermit::abi;
99
use crate::sys::hermit::abi::{O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
1010
use crate::sys::hermit::fd::FileDesc;
1111
use crate::sys::time::SystemTime;
12-
use crate::sys::{unsupported, Void};
12+
use crate::sys::unsupported;
1313
use crate::sys_common::os_str_bytes::OsStrExt;
1414

1515
pub use crate::sys_common::fs::copy;
@@ -22,11 +22,11 @@ fn cstr(path: &Path) -> io::Result<CString> {
2222
#[derive(Debug)]
2323
pub struct File(FileDesc);
2424

25-
pub struct FileAttr(Void);
25+
pub struct FileAttr(!);
2626

27-
pub struct ReadDir(Void);
27+
pub struct ReadDir(!);
2828

29-
pub struct DirEntry(Void);
29+
pub struct DirEntry(!);
3030

3131
#[derive(Clone, Debug)]
3232
pub struct OpenOptions {
@@ -41,146 +41,146 @@ pub struct OpenOptions {
4141
mode: i32,
4242
}
4343

44-
pub struct FilePermissions(Void);
44+
pub struct FilePermissions(!);
4545

46-
pub struct FileType(Void);
46+
pub struct FileType(!);
4747

4848
#[derive(Debug)]
4949
pub struct DirBuilder {}
5050

5151
impl FileAttr {
5252
pub fn size(&self) -> u64 {
53-
match self.0 {}
53+
self.0
5454
}
5555

5656
pub fn perm(&self) -> FilePermissions {
57-
match self.0 {}
57+
self.0
5858
}
5959

6060
pub fn file_type(&self) -> FileType {
61-
match self.0 {}
61+
self.0
6262
}
6363

6464
pub fn modified(&self) -> io::Result<SystemTime> {
65-
match self.0 {}
65+
self.0
6666
}
6767

6868
pub fn accessed(&self) -> io::Result<SystemTime> {
69-
match self.0 {}
69+
self.0
7070
}
7171

7272
pub fn created(&self) -> io::Result<SystemTime> {
73-
match self.0 {}
73+
self.0
7474
}
7575
}
7676

7777
impl Clone for FileAttr {
7878
fn clone(&self) -> FileAttr {
79-
match self.0 {}
79+
self.0
8080
}
8181
}
8282

8383
impl FilePermissions {
8484
pub fn readonly(&self) -> bool {
85-
match self.0 {}
85+
self.0
8686
}
8787

8888
pub fn set_readonly(&mut self, _readonly: bool) {
89-
match self.0 {}
89+
self.0
9090
}
9191
}
9292

9393
impl Clone for FilePermissions {
9494
fn clone(&self) -> FilePermissions {
95-
match self.0 {}
95+
self.0
9696
}
9797
}
9898

9999
impl PartialEq for FilePermissions {
100100
fn eq(&self, _other: &FilePermissions) -> bool {
101-
match self.0 {}
101+
self.0
102102
}
103103
}
104104

105105
impl Eq for FilePermissions {}
106106

107107
impl fmt::Debug for FilePermissions {
108108
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
109-
match self.0 {}
109+
self.0
110110
}
111111
}
112112

113113
impl FileType {
114114
pub fn is_dir(&self) -> bool {
115-
match self.0 {}
115+
self.0
116116
}
117117

118118
pub fn is_file(&self) -> bool {
119-
match self.0 {}
119+
self.0
120120
}
121121

122122
pub fn is_symlink(&self) -> bool {
123-
match self.0 {}
123+
self.0
124124
}
125125
}
126126

127127
impl Clone for FileType {
128128
fn clone(&self) -> FileType {
129-
match self.0 {}
129+
self.0
130130
}
131131
}
132132

133133
impl Copy for FileType {}
134134

135135
impl PartialEq for FileType {
136136
fn eq(&self, _other: &FileType) -> bool {
137-
match self.0 {}
137+
self.0
138138
}
139139
}
140140

141141
impl Eq for FileType {}
142142

143143
impl Hash for FileType {
144144
fn hash<H: Hasher>(&self, _h: &mut H) {
145-
match self.0 {}
145+
self.0
146146
}
147147
}
148148

149149
impl fmt::Debug for FileType {
150150
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
151-
match self.0 {}
151+
self.0
152152
}
153153
}
154154

155155
impl fmt::Debug for ReadDir {
156156
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
157-
match self.0 {}
157+
self.0
158158
}
159159
}
160160

161161
impl Iterator for ReadDir {
162162
type Item = io::Result<DirEntry>;
163163

164164
fn next(&mut self) -> Option<io::Result<DirEntry>> {
165-
match self.0 {}
165+
self.0
166166
}
167167
}
168168

169169
impl DirEntry {
170170
pub fn path(&self) -> PathBuf {
171-
match self.0 {}
171+
self.0
172172
}
173173

174174
pub fn file_name(&self) -> OsString {
175-
match self.0 {}
175+
self.0
176176
}
177177

178178
pub fn metadata(&self) -> io::Result<FileAttr> {
179-
match self.0 {}
179+
self.0
180180
}
181181

182182
pub fn file_type(&self) -> io::Result<FileType> {
183-
match self.0 {}
183+
self.0
184184
}
185185
}
186186

std/src/sys/hermit/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ pub fn unsupported_err() -> crate::io::Error {
6161
)
6262
}
6363

64-
// This enum is used as the storage for a bunch of types which can't actually
65-
// exist.
66-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
67-
pub enum Void {}
68-
6964
pub unsafe fn strlen(start: *const c_char) -> usize {
7065
let mut str = start;
7166

std/src/sys/hermit/net.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::str;
66
use crate::sync::Arc;
77
use crate::sys::hermit::abi;
88
use crate::sys::hermit::abi::IpAddress::{Ipv4, Ipv6};
9-
use crate::sys::{unsupported, Void};
9+
use crate::sys::unsupported;
1010
use crate::sys_common::AsInner;
1111
use crate::time::Duration;
1212

@@ -411,18 +411,18 @@ impl fmt::Debug for UdpSocket {
411411
}
412412
}
413413

414-
pub struct LookupHost(Void);
414+
pub struct LookupHost(!);
415415

416416
impl LookupHost {
417417
pub fn port(&self) -> u16 {
418-
match self.0 {}
418+
self.0
419419
}
420420
}
421421

422422
impl Iterator for LookupHost {
423423
type Item = SocketAddr;
424424
fn next(&mut self) -> Option<SocketAddr> {
425-
match self.0 {}
425+
self.0
426426
}
427427
}
428428

std/src/sys/hermit/os.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::path::{self, PathBuf};
99
use crate::str;
1010
use crate::sync::Mutex;
1111
use crate::sys::hermit::abi;
12-
use crate::sys::{unsupported, Void};
12+
use crate::sys::unsupported;
1313
use crate::sys_common::os_str_bytes::*;
1414
use crate::vec;
1515

@@ -29,7 +29,7 @@ pub fn chdir(_: &path::Path) -> io::Result<()> {
2929
unsupported()
3030
}
3131

32-
pub struct SplitPaths<'a>(&'a Void);
32+
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
3333

3434
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
3535
panic!("unsupported")
@@ -38,7 +38,7 @@ pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
3838
impl<'a> Iterator for SplitPaths<'a> {
3939
type Item = PathBuf;
4040
fn next(&mut self) -> Option<PathBuf> {
41-
match *self.0 {}
41+
self.0
4242
}
4343
}
4444

std/src/sys/sgx/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ pub fn decode_error_kind(code: i32) -> ErrorKind {
115115
}
116116
}
117117

118-
// This enum is used as the storage for a bunch of types which can't actually
119-
// exist.
120-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
121-
pub enum Void {}
122-
123118
pub unsafe fn strlen(mut s: *const c_char) -> usize {
124119
let mut n = 0;
125120
while unsafe { *s } != 0 {

0 commit comments

Comments
 (0)