|
1 |
| -// this crate can use `std` in tests only |
2 |
| -#![cfg_attr(not(test), no_std)] |
| 1 | +#![no_std] |
| 2 | +#![cfg_attr(feature = "unstable", feature(error_in_core))] |
3 | 3 | #![deny(missing_debug_implementations)]
|
4 | 4 | // --- BEGIN STYLE CHECKS ---
|
5 | 5 | // These checks are optional in CI for PRs, as discussed in
|
|
39 | 39 | extern crate std;
|
40 | 40 |
|
41 | 41 | use core::fmt;
|
| 42 | +use derive_more::Display; |
42 | 43 |
|
43 | 44 | pub use boot_loader_name::BootLoaderNameTag;
|
44 | 45 | pub use command_line::CommandLineTag;
|
@@ -160,19 +161,25 @@ pub unsafe fn load_with_offset(
|
160 | 161 |
|
161 | 162 | /// Error type that describes errors while loading/parsing a multiboot2 information structure
|
162 | 163 | /// from a given address.
|
163 |
| -#[derive(Debug)] |
| 164 | +#[derive(Debug, Display)] |
164 | 165 | pub enum MbiLoadError {
|
165 | 166 | /// The address is invalid. Make sure that the address is 8-byte aligned,
|
166 | 167 | /// according to the spec.
|
| 168 | + #[display(fmt = "The address is invalid")] |
167 | 169 | IllegalAddress,
|
168 | 170 | /// The total size of the multiboot2 information structure must be a multiple of 8.
|
169 | 171 | /// (Not in spec, but it is implicitly the case, because the begin of MBI
|
170 | 172 | /// and all tags are 8-byte aligned and the end tag is exactly 8 byte long).
|
| 173 | + #[display(fmt = "The size of the MBI is unexpected")] |
171 | 174 | IllegalTotalSize(u32),
|
172 | 175 | /// End tag missing. Each multiboot2 header requires to have an end tag.
|
| 176 | + #[display(fmt = "There is no end tag")] |
173 | 177 | NoEndTag,
|
174 | 178 | }
|
175 | 179 |
|
| 180 | +#[cfg(feature = "unstable")] |
| 181 | +impl core::error::Error for MbiLoadError {} |
| 182 | + |
176 | 183 | /// A Multiboot 2 Boot Information struct.
|
177 | 184 | pub struct BootInformation {
|
178 | 185 | inner: *const BootInformationInner,
|
@@ -1434,4 +1441,12 @@ mod tests {
|
1434 | 1441 | core::mem::transmute::<[u8; 16], EFIMemoryMapTag>([0u8; 16]);
|
1435 | 1442 | }
|
1436 | 1443 | }
|
| 1444 | + |
| 1445 | + #[test] |
| 1446 | + #[cfg(feature = "unstable")] |
| 1447 | + /// This test succeeds if it compiles. |
| 1448 | + fn mbi_load_error_implements_error() { |
| 1449 | + fn consumer<E: core::error::Error>(_e: E) {} |
| 1450 | + consumer(MbiLoadError::IllegalAddress) |
| 1451 | + } |
1437 | 1452 | }
|
0 commit comments