Skip to content

Commit fa10b30

Browse files
committed
multiboot2: tiny code improvement
1 parent 70ea65b commit fa10b30

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

integration-test/bins/multiboot2_chainloader/src/loader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ pub fn load_module(mut modules: multiboot::information::ModuleIter) -> ! {
4444

4545
// build MBI
4646
let mbi = multiboot2::builder::InformationBuilder::new()
47-
.bootloader_name_tag(BootLoaderNameTag::new("mb2_integrationtest_chainloader"))
48-
.command_line_tag(CommandLineTag::new("chainloaded YEAH"))
47+
.bootloader_name_tag(&BootLoaderNameTag::new("mb2_integrationtest_chainloader"))
48+
.command_line_tag(&CommandLineTag::new("chainloaded YEAH"))
4949
// random non-sense memory map
50-
.memory_map_tag(MemoryMapTag::new(&[MemoryArea::new(
50+
.memory_map_tag(&MemoryMapTag::new(&[MemoryArea::new(
5151
0,
5252
0xffffffff,
5353
MemoryAreaType::Reserved,
5454
)]))
55-
.add_module_tag(ModuleTag::new(
55+
.add_module_tag(&ModuleTag::new(
5656
elf_mod.start as u32,
5757
elf_mod.end as u32,
5858
elf_mod.string.unwrap(),

multiboot2/src/boot_loader_name.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ mod tests {
8989
use super::*;
9090
use crate::tag::{GenericTag, TagBytesRef};
9191
use crate::test_util::AlignedBytes;
92+
use core::borrow::Borrow;
9293

9394
#[rustfmt::skip]
9495
fn get_bytes() -> AlignedBytes<16> {
@@ -105,7 +106,7 @@ mod tests {
105106
#[test]
106107
fn test_parse_str() {
107108
let bytes = get_bytes();
108-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
109+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
109110
let tag = GenericTag::ref_from(bytes);
110111
let tag = tag.cast::<BootLoaderNameTag>();
111112
assert_eq!(tag.header.typ, TagType::BootLoaderName);

multiboot2/src/command_line.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ mod tests {
8383
use super::*;
8484
use crate::tag::{GenericTag, TagBytesRef};
8585
use crate::test_util::AlignedBytes;
86+
use core::borrow::Borrow;
8687

8788
#[rustfmt::skip]
8889
fn get_bytes() -> AlignedBytes<16> {
@@ -99,7 +100,7 @@ mod tests {
99100
#[test]
100101
fn test_parse_str() {
101102
let bytes = get_bytes();
102-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
103+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
103104
let tag = GenericTag::ref_from(bytes);
104105
let tag = tag.cast::<CommandLineTag>();
105106
assert_eq!(tag.header.typ, TagType::Cmdline);

multiboot2/src/module.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ mod tests {
130130
use super::*;
131131
use crate::tag::{GenericTag, TagBytesRef};
132132
use crate::test_util::AlignedBytes;
133+
use core::borrow::Borrow;
133134

134135
#[rustfmt::skip]
135136
fn get_bytes() -> AlignedBytes<24> {
@@ -150,7 +151,7 @@ mod tests {
150151
#[test]
151152
fn test_parse_str() {
152153
let bytes = get_bytes();
153-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
154+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
154155
let tag = GenericTag::ref_from(bytes);
155156
let tag = tag.cast::<ModuleTag>();
156157
assert_eq!(tag.header.typ, TagType::Module);

multiboot2/src/smbios.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod tests {
7373
use super::*;
7474
use crate::tag::{GenericTag, TagBytesRef};
7575
use crate::test_util::AlignedBytes;
76+
use core::borrow::Borrow;
7677

7778
#[rustfmt::skip]
7879
fn get_bytes() -> AlignedBytes<32> {
@@ -96,7 +97,7 @@ mod tests {
9697
#[test]
9798
fn test_parse() {
9899
let bytes = get_bytes();
99-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
100+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
100101
let tag = GenericTag::ref_from(bytes);
101102
let tag = tag.cast::<SmbiosTag>();
102103
assert_eq!(tag.header.typ, TagType::Smbios);

multiboot2/src/tag.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ impl<'a> Iterator for TagIter<'a> {
236236
mod tests {
237237
use super::*;
238238
use crate::test_util::AlignedBytes;
239+
use core::borrow::Borrow;
239240
use core::mem;
240241

241242
#[test]
@@ -248,7 +249,7 @@ mod tests {
248249
0x13, 0x37, 0x13, 0x37,
249250
]);
250251

251-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
252+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
252253
let tag = GenericTag::ref_from(bytes);
253254
assert_eq!(tag.header.typ, 0xffff_ffff);
254255
assert_eq!(tag.header.size, 16);
@@ -277,7 +278,7 @@ mod tests {
277278
0xef, 0xbe, 0xad, 0xde, /* field b: 0x1337_1337 */
278279
0x37, 0x13, 0x37, 0x13,
279280
]);
280-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
281+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
281282
let tag = GenericTag::ref_from(bytes);
282283
let custom_tag = tag.cast::<CustomTag>();
283284

@@ -313,7 +314,7 @@ mod tests {
313314
0x37, 0x13, 0x37, 0x13,
314315
]);
315316

316-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
317+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
317318
let tag = GenericTag::ref_from(bytes);
318319
let custom_tag = tag.cast::<CustomDstTag>();
319320

@@ -369,7 +370,7 @@ mod tests {
369370
0, 0, 0, 0, 0, 0
370371
],
371372
);
372-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
373+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
373374
let tag = GenericTag::ref_from(bytes);
374375
assert_eq!(tag.header.typ, TagType::Cmdline);
375376
assert_eq!(tag.header.size, 8 + 10);
@@ -391,7 +392,7 @@ mod tests {
391392
0, 0, 0, 0, 0, 0
392393
],
393394
);
394-
let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
395+
let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
395396
let tag = GenericTag::ref_from(bytes);
396397

397398
// Main objective here is also that this test passes Miri.
@@ -419,7 +420,7 @@ mod tests {
419420
8, 0, 0, 0,
420421
],
421422
);
422-
let mut iter = TagIter::new(&bytes[..]);
423+
let mut iter = TagIter::new(bytes.borrow());
423424
let first = iter.next().unwrap();
424425
assert_eq!(first.header.typ, TagType::Custom(0xff));
425426
assert_eq!(first.header.size, 8);

multiboot2/src/test_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ mod tests {
8282
0, 0,
8383
]
8484
);
85-
let _a = TagBytesRef::try_from(&bytes[..]).unwrap();
85+
let _a = TagBytesRef::try_from(bytes.borrow()).unwrap();
8686
}
8787
}

0 commit comments

Comments
 (0)