Skip to content

Commit 87a45f1

Browse files
committed
misc: setup and start fixing Clippy lints
1 parent fb1f07a commit 87a45f1

File tree

145 files changed

+1266
-930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1266
-930
lines changed

Cargo.toml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,67 @@ repository = "https://github.com/Serial-ATA/jvm"
2323
edition = "2024"
2424
license = "MIT OR APACHE-2.0"
2525

26+
[workspace.lints.rust]
27+
rust_2018_idioms = { level = "deny", priority = -1 }
28+
rust_2021_compatibility = { level = "deny", priority = -1 }
29+
rust_2024_compatibility = { level = "deny", priority = -1 }
30+
trivial_casts = "deny"
31+
trivial_numeric_casts = "deny"
32+
unused_import_braces = "deny"
33+
explicit_outlives_requirements = "deny"
34+
unknown_lints = "allow"
35+
36+
[workspace.lints.clippy]
37+
# Doc stuff
38+
missing_panics_doc = "allow"
39+
missing_errors_doc = "allow"
40+
tabs_in_doc_comments = "allow"
41+
42+
string_to_string = "deny"
43+
pedantic = { level = "deny", priority = -1 }
44+
all = { level = "deny", priority = -1 }
45+
too_many_lines = "allow"
46+
cast_precision_loss = "allow"
47+
cast_sign_loss = "allow"
48+
cast_possible_wrap = "allow"
49+
cast_possible_truncation = "allow"
50+
module_name_repetitions = "allow"
51+
must_use_candidate = "allow"
52+
doc_markdown = "allow"
53+
match_wildcard_for_single_variants = "allow"
54+
semicolon_if_nothing_returned = "allow"
55+
from_over_into = "allow"
56+
upper_case_acronyms = "allow"
57+
single_match_else = "allow"
58+
similar_names = "allow"
59+
len_without_is_empty = "allow"
60+
needless_late_init = "allow"
61+
type_complexity = "allow"
62+
return_self_not_must_use = "allow"
63+
bool_to_int_with_if = "allow"
64+
uninlined_format_args = "allow" # This should be changed for any normal "{}", but I'm not a fan of it for any debug or width specific formatting
65+
let_underscore_untyped = "allow"
66+
field_reassign_with_default = "allow"
67+
manual_range_patterns = "allow" # This is not at all clearer as it suggests
68+
no_effect_underscore_binding = "allow"
69+
used_underscore_binding = "allow"
70+
ignored_unit_patterns = "allow" # Not a fan of this lint, doesn't make anything clearer as it claims
71+
needless_return = "allow" # Explicit returns are needed from time to time for clarity
72+
redundant_guards = "allow" # Currently broken for some cases, might enable later
73+
into_iter_without_iter = "allow" # This is only going to fire on some internal types, doesn't matter much
74+
struct_excessive_bools = "allow" # I have yet to find one case of this being useful
75+
needless_continue = "allow" # All occurences of this lint are just for clarity in large loops
76+
unbuffered_bytes = "allow" # It is up to the caller to wrap their data in `BufReader`s
77+
struct_field_names = "allow"
78+
new_ret_no_self = "allow" # Violations of this lint are intentional
79+
inline_always = "allow"
80+
wildcard_imports = "allow"
81+
linkedlist = "allow"
82+
new_without_default = "allow" # Doesn't matter, not building a public API
83+
cast_ptr_alignment = "allow"
84+
transmute_bytes_to_str = "allow" # This is only done on guaranteed UTF-8 inputs
85+
too_many_arguments = "allow" # Rarely in our control
86+
2687
[workspace.dependencies]
2788
runtime = { path = "runtime" }
2889
classfile = { path = "classfile" }

classfile/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ repository.workspace = true
1010

1111
[dependencies]
1212
common.workspace = true
13-
paste.workspace = true
13+
paste.workspace = true
14+
15+
[lints]
16+
workspace = true

classfile/src/attribute/resolved.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Debug for ResolvedBootstrapMethod {
154154
f.debug_struct("ResolvedBoostrapMethod")
155155
.field("method_handle_info", &self.method_handle_info)
156156
.field("arguments", &self.arguments)
157-
.finish()
157+
.finish_non_exhaustive()
158158
}
159159
}
160160

classfile/src/constant_pool/types.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum LoadableConstantPoolValueInner<'a> {
1919
Dynamic(<raw::RawDynamic as CpEntry<'a>>::Entry),
2020
}
2121

22-
impl<'a> LoadableConstantPoolValueInner<'a> {
22+
impl LoadableConstantPoolValueInner<'_> {
2323
pub fn into_owned(self) -> LoadableConstantPoolValueInner<'static> {
2424
match self {
2525
LoadableConstantPoolValueInner::Integer(val) => {
@@ -57,7 +57,7 @@ pub struct LoadableConstantPoolValue<'a> {
5757
pub value: LoadableConstantPoolValueInner<'a>,
5858
}
5959

60-
impl<'a> LoadableConstantPoolValue<'a> {
60+
impl LoadableConstantPoolValue<'_> {
6161
pub fn into_owned(self) -> LoadableConstantPoolValue<'static> {
6262
LoadableConstantPoolValue {
6363
index: self.index,
@@ -74,7 +74,7 @@ pub struct FieldRefEntry<'a> {
7474
pub name_and_type: <raw::RawNameAndType as super::CpEntry<'a>>::Entry,
7575
}
7676

77-
impl<'a> FieldRefEntry<'a> {
77+
impl FieldRefEntry<'_> {
7878
pub fn into_owned(self) -> FieldRefEntry<'static> {
7979
FieldRefEntry {
8080
class_index: self.class_index,
@@ -155,7 +155,7 @@ pub enum ReferenceEntry<'a> {
155155
MethodRef(<raw::RawMethodRef as CpEntry<'a>>::Entry),
156156
}
157157

158-
impl<'a> ReferenceEntry<'a> {
158+
impl ReferenceEntry<'_> {
159159
pub fn into_owned(self) -> ReferenceEntry<'static> {
160160
match self {
161161
ReferenceEntry::FieldRef(field) => ReferenceEntry::FieldRef(field.into_owned()),
@@ -178,7 +178,7 @@ impl Debug for ClassNameEntry<'_> {
178178
}
179179
}
180180

181-
impl<'a> ClassNameEntry<'a> {
181+
impl ClassNameEntry<'_> {
182182
pub fn into_owned(self) -> ClassNameEntry<'static> {
183183
ClassNameEntry {
184184
name_index: self.name_index,
@@ -194,7 +194,7 @@ pub struct MethodHandleEntry<'a> {
194194
pub reference: ReferenceEntry<'a>,
195195
}
196196

197-
impl<'a> MethodHandleEntry<'a> {
197+
impl MethodHandleEntry<'_> {
198198
pub fn into_owned(self) -> MethodHandleEntry<'static> {
199199
MethodHandleEntry {
200200
reference_kind: self.reference_kind,
@@ -213,7 +213,7 @@ pub struct MethodRefEntry<'a> {
213213
pub name_and_type: <raw::RawNameAndType as CpEntry<'a>>::Entry,
214214
}
215215

216-
impl<'a> MethodRefEntry<'a> {
216+
impl MethodRefEntry<'_> {
217217
pub fn into_owned(self) -> MethodRefEntry<'static> {
218218
MethodRefEntry {
219219
is_interface: self.is_interface,
@@ -242,7 +242,7 @@ impl Debug for NameAndTypeEntry<'_> {
242242
}
243243
}
244244

245-
impl<'a> NameAndTypeEntry<'a> {
245+
impl NameAndTypeEntry<'_> {
246246
pub fn into_owned(self) -> NameAndTypeEntry<'static> {
247247
NameAndTypeEntry {
248248
name_index: self.name_index,
@@ -260,7 +260,7 @@ pub struct InvokeDynamicEntry<'a> {
260260
pub name_and_type: <raw::RawNameAndType as CpEntry<'a>>::Entry,
261261
}
262262

263-
impl<'a> InvokeDynamicEntry<'a> {
263+
impl InvokeDynamicEntry<'_> {
264264
pub fn into_owned(self) -> InvokeDynamicEntry<'static> {
265265
InvokeDynamicEntry {
266266
bootstrap_method_attr_index: self.bootstrap_method_attr_index,
@@ -277,7 +277,7 @@ pub struct DynamicEntry<'a> {
277277
pub name_and_type: <raw::RawNameAndType as CpEntry<'a>>::Entry,
278278
}
279279

280-
impl<'a> DynamicEntry<'a> {
280+
impl DynamicEntry<'_> {
281281
pub fn into_owned(self) -> DynamicEntry<'static> {
282282
DynamicEntry {
283283
bootstrap_method_attr_index: self.bootstrap_method_attr_index,
@@ -386,9 +386,9 @@ pub mod raw {
386386

387387
#[inline]
388388
fn handle(_: &ConstantPool, args: Self::HandleArgs) -> Self::Entry {
389-
let high = (args.0 as u64) << 32;
389+
let high = u64::from(args.0) << 32;
390390
let low = args.1;
391-
f64::from_bits(high | low as u64)
391+
f64::from_bits(high | u64::from(low))
392392
}
393393
}
394394

classfile/src/fieldinfo.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ pub struct FieldInfo {
2020

2121
impl FieldInfo {
2222
pub fn get_constant_value_attribute(&self) -> Option<ConstantValue> {
23-
self.attributes
24-
.iter()
25-
.find_map(|attr| attr.constant_value())
23+
self.attributes.iter().find_map(Attribute::constant_value)
2624
}
2725
}
2826

@@ -95,10 +93,7 @@ impl FieldType {
9593
}
9694

9795
pub fn is_primitive(&self) -> bool {
98-
match self {
99-
Self::Object(_) | Self::Array(_) => false,
100-
_ => true,
101-
}
96+
!matches!(self, Self::Object(_) | Self::Array(_))
10297
}
10398

10499
pub fn is_byte(&self) -> bool {
@@ -184,9 +179,7 @@ impl FieldType {
184179
Self::Short => "short".into(),
185180
Self::Boolean => "boolean".into(),
186181
Self::Void => "void".into(),
187-
Self::Object(name) => {
188-
format!("{}", String::from_utf8_lossy(name).replace('/', ".")).into()
189-
},
182+
Self::Object(name) => String::from_utf8_lossy(name).replace('/', ".").into(),
190183
Self::Array(component) => format!("[{}", component.as_java_type()).into(),
191184
}
192185
}
@@ -224,12 +217,11 @@ impl FieldType {
224217
pub fn size(&self) -> usize {
225218
match self {
226219
FieldType::Byte => size_of::<s1>(),
227-
FieldType::Character => size_of::<u2>(),
220+
FieldType::Character | FieldType::Short => size_of::<u2>(),
228221
FieldType::Double => size_of::<f64>(),
229222
FieldType::Float => size_of::<f32>(),
230223
FieldType::Integer => size_of::<s4>(),
231224
FieldType::Long => size_of::<s8>(),
232-
FieldType::Short => size_of::<u2>(),
233225
FieldType::Boolean => size_of::<bool>(),
234226
FieldType::Void => 0,
235227
FieldType::Object(_) | FieldType::Array(_) => size_of::<*const ()>(),
@@ -239,12 +231,11 @@ impl FieldType {
239231
pub fn align(&self) -> usize {
240232
match self {
241233
FieldType::Byte => align_of::<s1>(),
242-
FieldType::Character => align_of::<u2>(),
234+
FieldType::Character | FieldType::Short => align_of::<u2>(),
243235
FieldType::Double => align_of::<f64>(),
244236
FieldType::Float => align_of::<f32>(),
245237
FieldType::Integer => align_of::<s4>(),
246238
FieldType::Long => align_of::<s8>(),
247-
FieldType::Short => align_of::<u2>(),
248239
FieldType::Boolean => align_of::<bool>(),
249240
FieldType::Void => 0,
250241
FieldType::Object(_) | FieldType::Array(_) => align_of::<*const ()>(),

classfile/src/parse/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::accessflags::ClassAccessFlags;
88
use crate::classfile::ClassFile;
99
use crate::constant_pool::ConstantPool;
1010
use crate::parse::attributes::Location;
11-
use crate::parse::error::Result;
11+
use crate::parse::error::{ClassFileParseError, Result};
1212

1313
use std::io::Read;
1414

@@ -20,7 +20,9 @@ where
2020
R: Read,
2121
{
2222
let magic = reader.read_u4()?;
23-
assert_eq!(magic, 0xCAFE_BABE, "No magic found!");
23+
if magic != 0xCAFE_BABE {
24+
return Err(ClassFileParseError::InvalidMagic);
25+
}
2426

2527
let minor_version = reader.read_u2()?;
2628
let major_version = reader.read_u2()?;

common/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ repository.workspace = true
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12-
byteorder.workspace = true
12+
byteorder.workspace = true
13+
14+
[lints]
15+
workspace = true

common/src/atomic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl AtomicF32 {
2020
let as_u32 = self.inner.load(ordering);
2121
f32::from_bits(as_u32)
2222
}
23+
#[allow(clippy::missing_errors_doc)]
2324
pub fn compare_exchange(
2425
&self,
2526
current: f32,
@@ -54,6 +55,7 @@ impl AtomicF64 {
5455
let as_u64 = self.inner.load(ordering);
5556
f64::from_bits(as_u64)
5657
}
58+
#[allow(clippy::missing_errors_doc)]
5759
pub fn compare_exchange(
5860
&self,
5961
current: f64,

common/src/endian.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,23 @@ impl Endian {
6565
}
6666

6767
impl Endian {
68+
/// Read a 1-byte unsigned integer from `reader`
69+
///
70+
/// # Errors
71+
///
72+
/// See [`JavaLittleEndianRead::read_u1()`] and [`JavaReadExt::read_u1()`]
6873
pub fn read_u1<R>(self, reader: &mut R) -> Result<u1>
6974
where
7075
R: Read,
7176
{
7277
JavaReadExt::read_u1(reader)
7378
}
7479

80+
/// Read a 4-byte, big-endian unsigned integer from `reader`
81+
///
82+
/// # Errors
83+
///
84+
/// See [`JavaLittleEndianRead::read_u4()`] and [`JavaReadExt::read_u4()`]
7585
pub fn read_u4<R>(self, reader: &mut R) -> Result<u4>
7686
where
7787
R: Read,
@@ -82,6 +92,11 @@ impl Endian {
8292
}
8393
}
8494

95+
/// Read an 8-byte, big-endian unsigned integer from `reader`
96+
///
97+
/// # Errors
98+
///
99+
/// See [`JavaLittleEndianRead::read_u8()`] and [`JavaReadExt::read_u8()`]
85100
pub fn read_u8<R>(self, reader: &mut R) -> Result<u8>
86101
where
87102
R: Read,
@@ -92,6 +107,11 @@ impl Endian {
92107
}
93108
}
94109

110+
/// Read a 4-byte signed integer from `reader`
111+
///
112+
/// # Errors
113+
///
114+
/// See [`JavaLittleEndianRead::read_s4()`] and [`JavaReadExt::read_s4()`]
95115
pub fn read_s4<R>(self, reader: &mut R) -> Result<s4>
96116
where
97117
R: Read,
@@ -102,6 +122,11 @@ impl Endian {
102122
}
103123
}
104124

125+
/// Read a 4-byte signed integer from `reader`, into `dst`
126+
///
127+
/// # Errors
128+
///
129+
/// See [`JavaLittleEndianRead::read_s4_into()`] and [`JavaReadExt::read_s4_into()`]
105130
pub fn read_s4_into<R>(self, reader: &mut R, dst: &mut [s4]) -> Result<()>
106131
where
107132
R: Read,
@@ -112,6 +137,11 @@ impl Endian {
112137
}
113138
}
114139

140+
/// Read a 4-byte unsigned integer from `reader`, into `dst`
141+
///
142+
/// # Errors
143+
///
144+
/// See [`JavaLittleEndianRead::read_u4_into()`] and [`JavaReadExt::read_u4_into()`]
115145
pub fn read_u4_into<R>(self, reader: &mut R, dst: &mut [u4]) -> Result<()>
116146
where
117147
R: Read,

0 commit comments

Comments
 (0)