Skip to content

Commit 70d3a60

Browse files
committed
Sensible style checks as optional CI tasks.
This commit - introduces sensible style checks as optional CI tasks, - removes Travis CI - applies a few code style fixes
1 parent 661b478 commit 70d3a60

File tree

8 files changed

+63
-37
lines changed

8 files changed

+63
-37
lines changed

.github/workflows/rust.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@ jobs:
2020
run: cargo build --verbose
2121
- name: Run tests
2222
run: cargo test --verbose
23+
24+
25+
# As discussed, these tasks are optional for PRs.
26+
style_checks:
27+
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Rustfmt
33+
run: cargo fmt -- --check
34+
- name: Clippy
35+
run: cargo clippy
36+
- name: Rustdoc
37+
run: cargo doc

.travis.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/header.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ use core::marker::PhantomData;
1111
pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
1212

1313
/// Possible types of a Tag in the Multiboot2 Information Structure (MBI), therefore the value
14-
/// of the the `typ` field in [`Tag`]. The names and values are taken from the example C code
14+
/// of the the `typ` property. The names and values are taken from the example C code
1515
/// at the bottom of the Multiboot2 specification.
1616
#[repr(u32)]
1717
#[derive(Copy, Clone, Debug)]
18-
#[allow(missing_docs)]
1918
pub enum TagType {
2019
/// Marks the end of the tags.
2120
End = 0,

src/lib.rs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#![no_std]
22
#![deny(missing_debug_implementations)]
3-
#![deny(missing_docs)]
3+
// --- BEGIN STYLE CHECKS ---
4+
// These checks are optional in CI for PRs, as discussed in
5+
// https://github.com/rust-osdev/multiboot2/pull/92
6+
#![deny(clippy::all)]
7+
#![deny(rustdoc::all)]
8+
// Forcing this would be a little bit ridiculous, because it would require code examples for
9+
// each getter and each trivial trait implementation (like Debug).
10+
#![allow(rustdoc::missing_doc_code_examples)]
11+
// --- END STYLE CHECKS ---
412

513
//! Library that helps you to parse the multiboot information structure (mbi) from
614
//! Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the specification
@@ -9,15 +17,15 @@
917
//!
1018
//! The GNU Multiboot(2) specification aims to provide a standardised
1119
//! method of sharing commonly used information about the host machine at
12-
//! boot time and give the payload, i.e. a kernel, a well defined machien
20+
//! boot time and give the payload, i.e. a kernel, a well defined machine
1321
//! state.
1422
//!
1523
//! ## Example
1624
//!
17-
//! ```ignore
18-
//! use multiboot::load;
25+
//! ```rust
26+
//! use multiboot2::load;
1927
//! fn kmain(multiboot_info_ptr: u32) {
20-
//! let boot_info = unsafe { load(ptr as usize).unwrap() };
28+
//! let boot_info = unsafe { load(multiboot_info_ptr as usize).unwrap() };
2129
//! println!("{:?}", boot_info);
2230
//! }
2331
//! ```
@@ -26,23 +34,21 @@ use core::fmt;
2634

2735
pub use boot_loader_name::BootLoaderNameTag;
2836
pub use command_line::CommandLineTag;
37+
pub use efi::{EFIImageHandle32, EFIImageHandle64, EFISdt32, EFISdt64};
2938
pub use elf_sections::{
3039
ElfSection, ElfSectionFlags, ElfSectionIter, ElfSectionType, ElfSectionsTag,
3140
};
3241
pub use framebuffer::{FramebufferColor, FramebufferField, FramebufferTag, FramebufferType};
3342
pub use header::TagType;
3443
pub use header::MULTIBOOT2_BOOTLOADER_MAGIC;
3544
use header::{Tag, TagIter};
45+
pub use image_load_addr::ImageLoadPhysAddr;
3646
pub use memory_map::{
3747
EFIMemoryAreaType, EFIMemoryDesc, EFIMemoryMapTag, MemoryArea, MemoryAreaIter, MemoryAreaType,
3848
MemoryMapTag,
3949
};
4050
pub use module::{ModuleIter, ModuleTag};
41-
pub use rsdp::{
42-
RsdpV1Tag, RsdpV2Tag,
43-
};
44-
pub use image_load_addr::ImageLoadPhysAddr;
45-
pub use efi::{EFIImageHandle32, EFIImageHandle64, EFISdt32, EFISdt64};
51+
pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
4652
pub use vbe_info::{
4753
VBECapabilities, VBEControlInfo, VBEDirectColorAttributes, VBEField, VBEInfoTag,
4854
VBEMemoryModel, VBEModeAttributes, VBEModeInfo, VBEWindowAttributes,
@@ -53,46 +59,56 @@ extern crate bitflags;
5359

5460
mod boot_loader_name;
5561
mod command_line;
62+
mod efi;
5663
mod elf_sections;
5764
mod framebuffer;
5865
mod header;
66+
mod image_load_addr;
5967
mod memory_map;
6068
mod module;
6169
mod rsdp;
6270
mod vbe_info;
63-
mod efi;
64-
mod image_load_addr;
6571

6672
/// Load the multiboot boot information struct from an address.
6773
///
6874
/// This is the same as `load_with_offset` but the offset is omitted and set
6975
/// to zero.
7076
///
71-
/// Examples
77+
/// ## Example
7278
///
73-
/// ```ignore
74-
/// use multiboot::load;
79+
/// ```rust
80+
/// use multiboot2::load;
7581
///
7682
/// fn kmain(multiboot_info_ptr: u32) {
77-
/// let boot_info = unsafe { load(ptr as usize).unwrap() };
83+
/// let boot_info = unsafe { load(multiboot_info_ptr as usize).unwrap() };
7884
/// println!("{:?}", boot_info);
7985
/// }
8086
/// ```
87+
///
88+
/// ## Safety
89+
/// This function might terminate the program, if the address is invalid. This can be the case in
90+
/// environments with standard environment (segfault) but also in UEFI-applications,
91+
/// where the referenced memory is not (identity) mapped (UEFI does only identity mapping).
8192
pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
8293
load_with_offset(address, 0)
8394
}
8495

8596
/// Load the multiboot boot information struct from an address at an offset.
8697
///
87-
/// Examples
98+
/// ## Example
8899
///
89100
/// ```ignore
90-
/// use multiboot::load_with_offset;
101+
/// use multiboot2::load_with_offset;
91102
///
92-
/// let ptr = 0xDEADBEEF as *const _;
103+
/// let ptr = 0xDEADBEEF as *const u32;
93104
/// let boot_info = unsafe { load_with_offset(ptr as usize, 0xCAFEBABE).unwrap() };
94105
/// println!("{:?}", boot_info);
95106
/// ```
107+
///
108+
/// ## Safety
109+
/// This function might terminate the program, if the address is invalid. This can be the case in
110+
/// environments with standard environment (segfault) but also in UEFI-applications,
111+
/// where the referenced memory is not (identity) mapped (UEFI does only identity mapping).
96112
pub unsafe fn load_with_offset(
97113
address: usize,
98114
offset: usize,

src/memory_map.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use core::marker::PhantomData;
21
use crate::TagType;
2+
use core::marker::PhantomData;
33

44
/// This Tag provides an initial host memory map.
55
///
@@ -24,7 +24,8 @@ pub struct MemoryMapTag {
2424
impl MemoryMapTag {
2525
/// Return an iterator over all AVAILABLE marked memory areas.
2626
pub fn memory_areas(&self) -> impl Iterator<Item = &MemoryArea> {
27-
self.all_memory_areas().filter(|entry| matches!(entry.typ, MemoryAreaType::Available))
27+
self.all_memory_areas()
28+
.filter(|entry| matches!(entry.typ, MemoryAreaType::Available))
2829
}
2930

3031
/// Return an iterator over all marked memory areas.

src/module.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ impl ModuleTag {
2424
use core::{mem, slice, str};
2525
let strlen = self.size as usize - mem::size_of::<ModuleTag>();
2626
unsafe {
27-
str::from_utf8_unchecked(slice::from_raw_parts(&self.cmdline_str as *const u8, strlen))
27+
str::from_utf8_unchecked(slice::from_raw_parts(
28+
&self.cmdline_str as *const u8,
29+
strlen,
30+
))
2831
}
2932
}
3033

@@ -47,9 +50,9 @@ impl ModuleTag {
4750
impl Debug for ModuleTag {
4851
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
4952
f.debug_struct("ModuleTag")
50-
.field("type", &self.typ)
51-
.field("size (tag)", &self.size)
52-
.field("size (module)", &(self.module_size()))
53+
.field("type", &{ self.typ })
54+
.field("size (tag)", &{ self.size })
55+
.field("size (module)", &self.module_size())
5356
.field("mod_start", &(self.mod_start as *const usize))
5457
.field("mod_end", &(self.mod_end as *const usize))
5558
.field("cmdline", &self.cmdline())

src/rsdp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
//!
99
//! Even though the bootloader should give the address of the real RSDP/XSDT, the checksum and
1010
//! signature should be manually verified.
11+
use crate::TagType;
1112
use core::slice;
1213
use core::str;
13-
use crate::TagType;
1414

1515
const RSDPV1_LENGTH: usize = 20;
1616

src/vbe_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use core::fmt;
21
use crate::TagType;
2+
use core::fmt;
33

44
/// This tag contains VBE metadata, VBE controller information returned by the
55
/// VBE Function 00h and VBE mode information returned by the VBE Function 01h.

0 commit comments

Comments
 (0)