Skip to content

Commit 85a985e

Browse files
Update Rust style to 2024 edition
This style will become the default when we upgrade to the crates to 2024. Setting in the rustfmt config allows us to make the style changes separate from the edition upgrade, and can be useful for editors that use rustfmt directly [0]. The only manual change in this commit is in `.rustfmt.toml`, the rest is the result of `cargo fmt --all`. [0]: https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rustfmt-style-edition.html#migration
1 parent 864c64f commit 85a985e

26 files changed

+104
-70
lines changed

.rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
max_width = 80
2+
style_edition = "2024"

src/block_group.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4Read;
910
use crate::checksum::Checksum;
1011
use crate::error::{CorruptKind, Ext4Error};
1112
use crate::features::{IncompatibleFeatures, ReadOnlyCompatibleFeatures};
1213
use crate::superblock::Superblock;
1314
use crate::util::{read_u16le, read_u32le, u64_from_hilo, usize_from_u32};
14-
use crate::Ext4Read;
1515
use alloc::vec;
1616
use alloc::vec::Vec;
1717

src/dir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::dir_entry::DirEntryName;
1011
use crate::dir_htree::get_dir_entry_via_htree;
1112
use crate::error::Ext4Error;
1213
use crate::inode::{Inode, InodeFlags};
1314
use crate::iters::read_dir::ReadDir;
1415
use crate::path::PathBuf;
15-
use crate::Ext4;
1616

1717
/// Search a directory inode for an entry with the given `name`. If
1818
/// found, return the entry's inode, otherwise return a `NotFound`

src/dir_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::checksum::Checksum;
1011
use crate::error::{CorruptKind, Ext4Error};
1112
use crate::inode::InodeIndex;
1213
use crate::util::{read_u16le, read_u32le};
13-
use crate::Ext4;
1414

1515
#[derive(Debug, Eq, PartialEq)]
1616
enum DirBlockType {

src/dir_entry.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::error::{CorruptKind, Ext4Error};
1011
use crate::file_type::FileType;
11-
use crate::format::{format_bytes_debug, BytesDisplay};
12+
use crate::format::{BytesDisplay, format_bytes_debug};
1213
use crate::inode::{Inode, InodeIndex};
1314
use crate::metadata::Metadata;
1415
use crate::path::{Path, PathBuf};
1516
use crate::util::{read_u16le, read_u32le};
16-
use crate::Ext4;
1717
use alloc::rc::Rc;
1818
use core::error::Error;
1919
use core::fmt::{self, Debug, Display, Formatter};
@@ -516,7 +516,9 @@ mod tests {
516516
bytes.push(8u8); // file type
517517
bytes.extend("ab/".bytes()); // name
518518
bytes.resize(72, 0u8);
519-
assert!(DirEntry::from_bytes(fs.clone(), &bytes, inode1, path).is_err());
519+
assert!(
520+
DirEntry::from_bytes(fs.clone(), &bytes, inode1, path).is_err()
521+
);
520522
}
521523

522524
#[test]

src/dir_htree.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::dir_block::DirBlock;
1011
use crate::dir_entry::{DirEntry, DirEntryName};
1112
use crate::dir_entry_hash::dir_hash_md4_half;
@@ -16,7 +17,6 @@ use crate::iters::extents::Extents;
1617
use crate::iters::file_blocks::FileBlocks;
1718
use crate::path::PathBuf;
1819
use crate::util::{read_u16le, read_u32le, usize_from_u32};
19-
use crate::Ext4;
2020
use alloc::rc::Rc;
2121
use alloc::vec;
2222

@@ -495,14 +495,16 @@ mod tests {
495495
assert_eq!(entry.file_name(), "..");
496496

497497
// Check that an arbitrary name returns `None`.
498-
assert!(read_dot_or_dotdot(
499-
fs.clone(),
500-
&inode,
501-
"somename".try_into().unwrap(),
502-
&block
503-
)
504-
.unwrap()
505-
.is_none());
498+
assert!(
499+
read_dot_or_dotdot(
500+
fs.clone(),
501+
&inode,
502+
"somename".try_into().unwrap(),
503+
&block
504+
)
505+
.unwrap()
506+
.is_none()
507+
);
506508
}
507509

508510
/// Use ReadDir to iterate over all directory entries. Check that

src/error.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ impl Display for CorruptKind {
405405
block_group,
406406
num_block_groups,
407407
} => {
408-
write!(f, "inode {inode} has an invalid block group index: block_group={block_group}, num_block_groups={num_block_groups}")
408+
write!(
409+
f,
410+
"inode {inode} has an invalid block group index: block_group={block_group}, num_block_groups={num_block_groups}"
411+
)
409412
}
410413
Self::InodeLocation {
411414
inode,
@@ -415,7 +418,10 @@ impl Display for CorruptKind {
415418
block_size,
416419
inode_table_first_block,
417420
} => {
418-
write!(f, "inode {inode} has invalid location: block_group={block_group}, inodes_per_block_group={inodes_per_block_group}, inode_size={inode_size}, block_size={block_size}, inode_table_first_block={inode_table_first_block}")
421+
write!(
422+
f,
423+
"inode {inode} has invalid location: block_group={block_group}, inodes_per_block_group={inodes_per_block_group}, inode_size={inode_size}, block_size={block_size}, inode_table_first_block={inode_table_first_block}"
424+
)
419425
}
420426
Self::InodeFileType { inode, mode } => {
421427
write!(
@@ -461,7 +467,10 @@ impl Display for CorruptKind {
461467
offset_within_block,
462468
read_len,
463469
} => {
464-
write!(f, "invalid read of length {read_len} from block {block_index} at offset {offset_within_block}")
470+
write!(
471+
f,
472+
"invalid read of length {read_len} from block {block_index} at offset {offset_within_block}"
473+
)
465474
}
466475
}
467476
}

src/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::error::Ext4Error;
1011
use crate::inode::Inode;
1112
use crate::iters::file_blocks::FileBlocks;
1213
use crate::metadata::Metadata;
1314
use crate::path::Path;
1415
use crate::resolve::FollowSymlinks;
1516
use crate::util::usize_from_u32;
16-
use crate::Ext4;
1717
use core::fmt::{self, Debug, Formatter};
1818

1919
#[cfg(feature = "std")]

src/file_type.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,31 @@ mod tests {
128128
fn test_file_type() {
129129
// Check each valid file type.
130130
assert!(FileType::try_from(InodeMode::S_IFIFO).unwrap().is_fifo());
131-
assert!(FileType::try_from(InodeMode::S_IFCHR)
132-
.unwrap()
133-
.is_char_dev());
134-
assert!(FileType::try_from(InodeMode::S_IFBLK)
135-
.unwrap()
136-
.is_block_dev());
137-
assert!(FileType::try_from(InodeMode::S_IFREG)
138-
.unwrap()
139-
.is_regular_file());
131+
assert!(
132+
FileType::try_from(InodeMode::S_IFCHR)
133+
.unwrap()
134+
.is_char_dev()
135+
);
136+
assert!(
137+
FileType::try_from(InodeMode::S_IFBLK)
138+
.unwrap()
139+
.is_block_dev()
140+
);
141+
assert!(
142+
FileType::try_from(InodeMode::S_IFREG)
143+
.unwrap()
144+
.is_regular_file()
145+
);
140146
assert!(FileType::try_from(InodeMode::S_IFLNK).unwrap().is_symlink());
141147
assert!(FileType::try_from(InodeMode::S_IFSOCK).unwrap().is_socket());
142148

143149
// Check that other bits being set in the mode don't impact the
144150
// file type.
145-
assert!(FileType::try_from(InodeMode::S_IFREG | InodeMode::S_IXOTH)
146-
.unwrap()
147-
.is_regular_file());
151+
assert!(
152+
FileType::try_from(InodeMode::S_IFREG | InodeMode::S_IXOTH)
153+
.unwrap()
154+
.is_regular_file()
155+
);
148156

149157
// Error, no file type set.
150158
assert_eq!(

src/inode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::checksum::Checksum;
1011
use crate::error::{CorruptKind, Ext4Error};
1112
use crate::file_type::FileType;
@@ -14,7 +15,6 @@ use crate::path::PathBuf;
1415
use crate::util::{
1516
read_u16le, read_u32le, u32_from_hilo, u64_from_hilo, usize_from_u32,
1617
};
17-
use crate::Ext4;
1818
use alloc::vec;
1919
use bitflags::bitflags;
2020
use core::num::NonZeroU32;

src/iters/extents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::checksum::Checksum;
1011
use crate::error::{CorruptKind, Ext4Error};
1112
use crate::extent::Extent;
1213
use crate::inode::{Inode, InodeIndex};
1314
use crate::util::{read_u16le, read_u32le, u64_from_hilo, usize_from_u32};
14-
use crate::Ext4;
1515
use alloc::vec;
1616
use alloc::vec::Vec;
1717

src/iters/file_blocks/extents_blocks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::error::{CorruptKind, Ext4Error};
1011
use crate::extent::Extent;
1112
use crate::inode::{Inode, InodeIndex};
1213
use crate::iters::extents::Extents;
13-
use crate::Ext4;
1414

1515
/// Iterator over blocks in a file that uses extents.
1616
///

src/iters/read_dir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::checksum::Checksum;
1011
use crate::dir_block::DirBlock;
1112
use crate::dir_entry::DirEntry;
1213
use crate::error::{CorruptKind, Ext4Error};
1314
use crate::inode::{Inode, InodeFlags, InodeIndex};
1415
use crate::iters::file_blocks::FileBlocks;
1516
use crate::path::PathBuf;
16-
use crate::Ext4;
1717
use alloc::rc::Rc;
1818
use alloc::vec;
1919
use alloc::vec::Vec;

src/journal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ mod commit_block;
1212
mod descriptor_block;
1313
mod superblock;
1414

15+
use crate::Ext4;
1516
use crate::error::Ext4Error;
1617
use crate::inode::Inode;
17-
use crate::Ext4;
18-
use block_map::{load_block_map, BlockMap};
18+
use block_map::{BlockMap, load_block_map};
1919
use superblock::JournalSuperblock;
2020

2121
#[derive(Debug)]

src/journal/block_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::checksum::Checksum;
1011
use crate::error::{CorruptKind, Ext4Error, IncompatibleKind};
1112
use crate::inode::Inode;
1213
use crate::iters::file_blocks::FileBlocks;
1314
use crate::journal::block_header::{JournalBlockHeader, JournalBlockType};
1415
use crate::journal::commit_block::validate_commit_block_checksum;
1516
use crate::journal::descriptor_block::{
16-
validate_descriptor_block_checksum, DescriptorBlockTagIter,
17+
DescriptorBlockTagIter, validate_descriptor_block_checksum,
1718
};
1819
use crate::journal::superblock::JournalSuperblock;
1920
use crate::util::usize_from_u32;
20-
use crate::Ext4;
2121
use alloc::collections::BTreeMap;
2222
use alloc::vec;
2323
use alloc::vec::Vec;

src/journal/descriptor_block.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ mod tests {
197197
);
198198

199199
block[1020..].copy_from_slice(&[0x74, 0xef, 0x0e, 0xf6]);
200-
assert!(validate_descriptor_block_checksum(&superblock, &block).is_ok());
200+
assert!(
201+
validate_descriptor_block_checksum(&superblock, &block).is_ok()
202+
);
201203
}
202204

203205
fn push_u32be(bytes: &mut Vec<u8>, value: u32) {

src/journal/superblock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use crate::Ext4;
910
use crate::checksum::Checksum;
1011
use crate::error::{CorruptKind, Ext4Error, IncompatibleKind};
1112
use crate::inode::Inode;
1213
use crate::iters::file_blocks::FileBlocks;
1314
use crate::journal::block_header::{JournalBlockHeader, JournalBlockType};
1415
use crate::util::read_u32be;
1516
use crate::uuid::Uuid;
16-
use crate::Ext4;
1717
use alloc::vec;
1818
use bitflags::bitflags;
1919

src/label.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use crate::format::{format_bytes_debug, BytesDisplay};
9+
use crate::format::{BytesDisplay, format_bytes_debug};
1010
use core::fmt::{self, Debug, Formatter};
1111
use core::str::Utf8Error;
1212

0 commit comments

Comments
 (0)