Skip to content

Commit 552c2db

Browse files
authored
Merge pull request raspberrypi#980 from ojeda/rust-reduce-fixes
Reduce differences with mainline
2 parents f0912b2 + 7b82acd commit 552c2db

File tree

11 files changed

+242
-220
lines changed

11 files changed

+242
-220
lines changed

rust/build_error.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22

33
//! Build-time error.
44
//!
5-
//! This crate provides a function `build_error`, which will panic in
6-
//! compile-time if executed in const context, and will cause a build error
7-
//! if not executed at compile time and the optimizer does not optimise away the
8-
//! call.
5+
//! This crate provides a [const function][const-functions] `build_error`, which will panic in
6+
//! compile-time if executed in [const context][const-context], and will cause a build error
7+
//! if not executed at compile time and the optimizer does not optimise away the call.
98
//!
109
//! It is used by `build_assert!` in the kernel crate, allowing checking of
1110
//! conditions that could be checked statically, but could not be enforced in
12-
//! Rust yet (e.g. perform some checks in const functions, but those
11+
//! Rust yet (e.g. perform some checks in [const functions][const-functions], but those
1312
//! functions could still be called in the runtime).
13+
//!
14+
//! For details on constant evaluation in Rust, please see the [Reference][const-eval].
15+
//!
16+
//! [const-eval]: https://doc.rust-lang.org/reference/const_eval.html
17+
//! [const-functions]: https://doc.rust-lang.org/reference/const_eval.html#const-functions
18+
//! [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
1419
1520
#![no_std]
1621

17-
/// Panics if executed in const context, or triggers a build error if not.
22+
/// Panics if executed in [const context][const-context], or triggers a build error if not.
23+
///
24+
/// [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
1825
#[inline(never)]
1926
#[cold]
2027
#[export_name = "rust_build_error"]

rust/kernel/build_assert.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ macro_rules! build_error {
4343
/// These examples show that different types of [`assert!`] will trigger errors
4444
/// at different stage of compilation. It is preferred to err as early as
4545
/// possible, so [`static_assert!`] should be used whenever possible.
46-
// TODO: Could be `compile_fail` when supported.
4746
/// ```ignore
4847
/// fn foo() {
4948
/// static_assert!(1 > 1); // Compile-time error

rust/kernel/error.rs

Lines changed: 6 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -27,79 +27,42 @@ pub mod code {
2727
}
2828

2929
declare_err!(EPERM, "Operation not permitted.");
30-
3130
declare_err!(ENOENT, "No such file or directory.");
32-
3331
declare_err!(ESRCH, "No such process.");
34-
3532
declare_err!(EINTR, "Interrupted system call.");
36-
3733
declare_err!(EIO, "I/O error.");
38-
3934
declare_err!(ENXIO, "No such device or address.");
40-
4135
declare_err!(E2BIG, "Argument list too long.");
42-
4336
declare_err!(ENOEXEC, "Exec format error.");
44-
4537
declare_err!(EBADF, "Bad file number.");
46-
4738
declare_err!(ECHILD, "Exec format error.");
48-
4939
declare_err!(EAGAIN, "Try again.");
50-
5140
declare_err!(ENOMEM, "Out of memory.");
52-
5341
declare_err!(EACCES, "Permission denied.");
54-
5542
declare_err!(EFAULT, "Bad address.");
56-
5743
declare_err!(ENOTBLK, "Block device required.");
58-
5944
declare_err!(EBUSY, "Device or resource busy.");
60-
6145
declare_err!(EEXIST, "File exists.");
62-
6346
declare_err!(EXDEV, "Cross-device link.");
64-
6547
declare_err!(ENODEV, "No such device.");
66-
6748
declare_err!(ENOTDIR, "Not a directory.");
68-
6949
declare_err!(EISDIR, "Is a directory.");
70-
7150
declare_err!(EINVAL, "Invalid argument.");
72-
7351
declare_err!(ENFILE, "File table overflow.");
74-
7552
declare_err!(EMFILE, "Too many open files.");
76-
7753
declare_err!(ENOTTY, "Not a typewriter.");
78-
7954
declare_err!(ETXTBSY, "Text file busy.");
80-
8155
declare_err!(EFBIG, "File too large.");
82-
8356
declare_err!(ENOSPC, "No space left on device.");
84-
8557
declare_err!(ESPIPE, "Illegal seek.");
86-
8758
declare_err!(EROFS, "Read-only file system.");
88-
8959
declare_err!(EMLINK, "Too many links.");
90-
9160
declare_err!(EPIPE, "Broken pipe.");
92-
9361
declare_err!(EDOM, "Math argument out of domain of func.");
94-
9562
declare_err!(ERANGE, "Math result not representable.");
96-
9763
declare_err!(EDEADLK, "Resource deadlock would occur");
98-
9964
declare_err!(ENAMETOOLONG, "File name too long");
100-
10165
declare_err!(ENOLCK, "No record locks available");
102-
10366
declare_err!(
10467
ENOSYS,
10568
"Invalid system call number.",
@@ -110,201 +73,103 @@ pub mod code {
11073
"failures due to attempts to use a nonexistent syscall, syscall",
11174
"implementations should refrain from returning [`ENOSYS`]."
11275
);
113-
11476
declare_err!(ENOTEMPTY, "Directory not empty.");
115-
11677
declare_err!(ELOOP, "Too many symbolic links encountered.");
117-
11878
declare_err!(EWOULDBLOCK, "Operation would block.");
119-
12079
declare_err!(ENOMSG, "No message of desired type.");
121-
12280
declare_err!(EIDRM, "Identifier removed.");
123-
12481
declare_err!(ECHRNG, "Channel number out of range.");
125-
12682
declare_err!(EL2NSYNC, "Level 2 not synchronized.");
127-
12883
declare_err!(EL3HLT, "Level 3 halted.");
129-
13084
declare_err!(EL3RST, "Level 3 reset.");
131-
13285
declare_err!(ELNRNG, "Link number out of range.");
133-
13486
declare_err!(EUNATCH, "Protocol driver not attached.");
135-
13687
declare_err!(ENOCSI, "No CSI structure available.");
137-
13888
declare_err!(EL2HLT, "Level 2 halted.");
139-
14089
declare_err!(EBADE, "Invalid exchange.");
141-
14290
declare_err!(EBADR, "Invalid request descriptor.");
143-
14491
declare_err!(EXFULL, "Exchange full.");
145-
14692
declare_err!(ENOANO, "No anode.");
147-
14893
declare_err!(EBADRQC, "Invalid request code.");
149-
15094
declare_err!(EBADSLT, "Invalid slot.");
151-
15295
declare_err!(EDEADLOCK, "Resource deadlock would occur.");
153-
15496
declare_err!(EBFONT, "Bad font file format.");
155-
15697
declare_err!(ENOSTR, "Device not a stream.");
157-
15898
declare_err!(ENODATA, "No data available.");
159-
16099
declare_err!(ETIME, "Timer expired.");
161-
162100
declare_err!(ENOSR, "Out of streams resources.");
163-
164101
declare_err!(ENONET, "Machine is not on the network.");
165-
166102
declare_err!(ENOPKG, "Package not installed.");
167-
168103
declare_err!(EREMOTE, "Object is remote.");
169-
170104
declare_err!(ENOLINK, "Link has been severed.");
171-
172105
declare_err!(EADV, "Advertise error.");
173-
174106
declare_err!(ESRMNT, "Srmount error.");
175-
176107
declare_err!(ECOMM, "Communication error on send.");
177-
178108
declare_err!(EPROTO, "Protocol error.");
179-
180109
declare_err!(EMULTIHOP, "Multihop attempted.");
181-
182110
declare_err!(EDOTDOT, "RFS specific error.");
183-
184111
declare_err!(EBADMSG, "Not a data message.");
185-
186112
declare_err!(EOVERFLOW, "Value too large for defined data type.");
187-
188113
declare_err!(ENOTUNIQ, "Name not unique on network.");
189-
190114
declare_err!(EBADFD, "File descriptor in bad state.");
191-
192115
declare_err!(EREMCHG, "Remote address changed.");
193-
194116
declare_err!(ELIBACC, "Can not access a needed shared library.");
195-
196117
declare_err!(ELIBBAD, "Accessing a corrupted shared library.");
197-
198118
declare_err!(ELIBSCN, ".lib section in a.out corrupted.");
199-
200119
declare_err!(ELIBMAX, "Attempting to link in too many shared libraries.");
201-
202120
declare_err!(ELIBEXEC, "Cannot exec a shared library directly.");
203-
204121
declare_err!(EILSEQ, "Illegal byte sequence.");
205-
206122
declare_err!(ERESTART, "Interrupted system call should be restarted.");
207-
208123
declare_err!(ESTRPIPE, "Streams pipe error.");
209-
210124
declare_err!(EUSERS, "Too many users.");
211-
212125
declare_err!(ENOTSOCK, "Socket operation on non-socket.");
213-
214126
declare_err!(EDESTADDRREQ, "Destination address required.");
215-
216127
declare_err!(EMSGSIZE, "Message too long.");
217-
218128
declare_err!(EPROTOTYPE, "Protocol wrong type for socket.");
219-
220129
declare_err!(ENOPROTOOPT, "Protocol not available.");
221-
222130
declare_err!(EPROTONOSUPPORT, "Protocol not supported.");
223-
224131
declare_err!(ESOCKTNOSUPPORT, "Socket type not supported.");
225-
226132
declare_err!(EOPNOTSUPP, "Operation not supported on transport endpoint.");
227-
228133
declare_err!(EPFNOSUPPORT, "Protocol family not supported.");
229-
230134
declare_err!(EAFNOSUPPORT, "Address family not supported by protocol.");
231-
232135
declare_err!(EADDRINUSE, "Address already in use.");
233-
234136
declare_err!(EADDRNOTAVAIL, "Cannot assign requested address.");
235-
236137
declare_err!(ENETDOWN, "Network is down.");
237-
238138
declare_err!(ENETUNREACH, "Network is unreachable.");
239-
240139
declare_err!(ENETRESET, "Network dropped connection because of reset.");
241-
242140
declare_err!(ECONNABORTED, "Software caused connection abort.");
243-
244141
declare_err!(ECONNRESET, "Connection reset by peer.");
245-
246142
declare_err!(ENOBUFS, "No buffer space available.");
247-
248143
declare_err!(EISCONN, "Transport endpoint is already connected.");
249-
250144
declare_err!(ENOTCONN, "Transport endpoint is not connected.");
251-
252145
declare_err!(ESHUTDOWN, "Cannot send after transport endpoint shutdown.");
253-
254146
declare_err!(ETOOMANYREFS, "Too many references: cannot splice.");
255-
256147
declare_err!(ETIMEDOUT, "Connection timed out.");
257-
258148
declare_err!(ECONNREFUSED, "Connection refused.");
259-
260149
declare_err!(EHOSTDOWN, "Host is down.");
261-
262150
declare_err!(EHOSTUNREACH, "No route to host.");
263-
264151
declare_err!(EALREADY, "Operation already in progress.");
265-
266152
declare_err!(EINPROGRESS, "Operation now in progress.");
267-
268153
declare_err!(ESTALE, "Stale file handle.");
269-
270154
declare_err!(EUCLEAN, "Structure needs cleaning.");
271-
272155
declare_err!(ENOTNAM, "Not a XENIX named type file.");
273-
274156
declare_err!(ENAVAIL, "No XENIX semaphores available.");
275-
276157
declare_err!(EISNAM, "Is a named type file.");
277-
278158
declare_err!(EREMOTEIO, "Remote I/O error.");
279-
280159
declare_err!(EDQUOT, "Quota exceeded.");
281-
282160
declare_err!(ENOMEDIUM, "No medium found.");
283-
284161
declare_err!(EMEDIUMTYPE, "Wrong medium type.");
285-
286162
declare_err!(ECANCELED, "Operation Canceled.");
287-
288163
declare_err!(ENOKEY, "Required key not available.");
289-
290164
declare_err!(EKEYEXPIRED, "Key has expired.");
291-
292165
declare_err!(EKEYREVOKED, "Key has been revoked.");
293-
294166
declare_err!(EKEYREJECTED, "Key was rejected by service.");
295-
296167
declare_err!(EOWNERDEAD, "Owner died.", "", "For robust mutexes.");
297-
298168
declare_err!(ENOTRECOVERABLE, "State not recoverable.");
299-
300169
declare_err!(ERFKILL, "Operation not possible due to RF-kill.");
301-
302170
declare_err!(EHWPOISON, "Memory page has hardware error.");
303-
304171
declare_err!(ERESTARTSYS, "Restart the system call.");
305-
306172
declare_err!(ENOTSUPP, "Operation is not supported.");
307-
308173
declare_err!(ENOPARAM, "Parameter not supported.");
309174
}
310175

@@ -392,6 +257,12 @@ impl fmt::Debug for Error {
392257
}
393258
}
394259

260+
impl From<AllocError> for Error {
261+
fn from(_: AllocError) -> Error {
262+
code::ENOMEM
263+
}
264+
}
265+
395266
impl From<TryFromIntError> for Error {
396267
fn from(_: TryFromIntError) -> Error {
397268
code::EINVAL
@@ -450,12 +321,6 @@ impl From<core::convert::Infallible> for Error {
450321
/// just an [`Error`].
451322
pub type Result<T = ()> = core::result::Result<T, Error>;
452323

453-
impl From<AllocError> for Error {
454-
fn from(_: AllocError) -> Error {
455-
code::ENOMEM
456-
}
457-
}
458-
459324
// # Invariant: `-bindings::MAX_ERRNO` fits in an `i16`.
460325
crate::static_assert!(bindings::MAX_ERRNO <= -(i16::MIN as i32) as u32);
461326

0 commit comments

Comments
 (0)