Skip to content

Commit 129e305

Browse files
committed
Make several changes recommended by Clippy
1 parent 6a18cef commit 129e305

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/class_file.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ impl ClassFile {
5959

6060
let class = self.get_constant(self.this_class as usize);
6161

62-
if let &ConstantClass { name_index } = class.deref() {
62+
if let ConstantClass { name_index } = *class.deref() {
6363
let class_name = self.get_constant(name_index as usize);
6464

65-
if let &ConstantUtf8 { ref string } = class_name.deref() {
65+
if let ConstantUtf8 { ref string } = *class_name.deref() {
6666
string
6767
} else {
6868
panic!("The \"name_index\" pointed to by \"this_class\" did not point to a ConstantUtf8. Found: {:?}", class_name.deref())
@@ -93,7 +93,7 @@ impl ClassFile {
9393
for ref attr in self.attributes.iter() {
9494
let name_constant = self.get_constant(attr.attribute_name_index as usize);
9595

96-
if let &ConstantUtf8 { ref string } = name_constant.deref() {
96+
if let ConstantUtf8 { ref string } = *name_constant.deref() {
9797
if string == "SourceFile" {
9898
if attr.info.len() != 2 {
9999
panic!("Incorrectly formatted SourceFile attribute. Expected info length of 2, found: {}", attr.info.len());
@@ -103,8 +103,8 @@ impl ClassFile {
103103
let source_file_index = u16::from_be_bytes(info);
104104
let source_constant = self.get_constant(source_file_index as usize);
105105

106-
if let &ConstantUtf8 { ref string } =
107-
source_constant.deref() { return Some(string) }
106+
if let ConstantUtf8 { ref string } =
107+
*source_constant.deref() { return Some(string) }
108108
else {
109109
panic!("The \"info\" of the \"SourceFile\" annotation did not point to a ConstantUtf8. Found: {:?}", source_constant.deref());
110110
}
@@ -131,7 +131,7 @@ impl ClassFile {
131131

132132
let constant_utf8 = self.get_constant(index);
133133

134-
if let &ConstantUtf8 { ref string } = constant_utf8.deref() {
134+
if let ConstantUtf8 { ref string } = *constant_utf8.deref() {
135135
string
136136
} else {
137137
panic!("Failed to get constant \"#{}\" as a ConstantUtf8. Found: {:?}", index, constant_utf8)
@@ -154,7 +154,7 @@ impl ClassFile {
154154

155155
let constant_class = self.get_constant(index);
156156

157-
if let &ConstantClass { name_index } = constant_class.deref() {
157+
if let ConstantClass { name_index } = *constant_class.deref() {
158158
self.get_constant_utf8(name_index as usize)
159159
} else {
160160
panic!("Failed to get constant \"#{}\" as a ConstantClass. Found: {:?}", index, constant_class)
@@ -181,8 +181,8 @@ impl ClassFile {
181181

182182
let constant_nat = self.get_constant(index);
183183

184-
if let &ConstantNameAndType { name_index, descriptor_index } =
185-
constant_nat.deref() {
184+
if let ConstantNameAndType { name_index, descriptor_index } =
185+
*constant_nat.deref() {
186186
format!(
187187
"\"{}\":{}",
188188
self.get_constant_utf8(name_index as usize),

src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,27 @@ fn print_constant_pool(class_file: &ClassFile) {
7878
}
7979

8080
fn format_constant_pool_entry(
81-
class_file: &ClassFile, constant: &Box<ConstantPoolEntry>
81+
class_file: &ClassFile, constant: &ConstantPoolEntry
8282
) -> String {
8383
use ConstantPoolEntry::*;
8484

85-
match constant.deref() {
86-
&ConstantUtf8 { ref string } => {
85+
match *constant.deref() {
86+
ConstantUtf8 { ref string } => {
8787
format!(
8888
"{:<20}{}",
8989
"Utf8",
9090
string
9191
)
9292
},
93-
&ConstantClass { name_index } => {
93+
ConstantClass { name_index } => {
9494
format!(
9595
"{:<20}{:<16}// {}",
9696
"Class",
9797
format!("#{}", name_index),
9898
class_file.get_constant_utf8(name_index as usize)
9999
)
100100
},
101-
&ConstantFieldref { class_index, name_and_type_index } => {
101+
ConstantFieldref { class_index, name_and_type_index } => {
102102
format!(
103103
"{:<20}{:<16}// {}",
104104
"Fieldref",
@@ -112,7 +112,7 @@ fn format_constant_pool_entry(
112112
)
113113
)
114114
},
115-
&ConstantMethodref { class_index, name_and_type_index } => {
115+
ConstantMethodref { class_index, name_and_type_index } => {
116116
format!(
117117
"{:<20}{:<16}// {}",
118118
"Methodref",
@@ -126,7 +126,7 @@ fn format_constant_pool_entry(
126126
)
127127
)
128128
},
129-
&ConstantNameAndType { name_index, descriptor_index } => {
129+
ConstantNameAndType { name_index, descriptor_index } => {
130130
format!(
131131
"{:<20}{:<16}// {}",
132132
"NameAndType",
@@ -172,12 +172,12 @@ fn print_method(class_file: &ClassFile, method: &Method) {
172172

173173
print_bytecode(class_file, &code.code);
174174

175-
if code.exception_table.len() > 0 {
175+
if !code.exception_table.is_empty() {
176176
print_exception_table(class_file, &code.exception_table);
177177
}
178178
}
179179

180-
fn print_bytecode(class_file: &ClassFile, code: &Vec<(usize, Bytecode)>) {
180+
fn print_bytecode(class_file: &ClassFile, code: &[(usize, Bytecode)]) {
181181
for (i, bytecode) in code {
182182
print!(
183183
" {:>3}: {:35}",
@@ -192,7 +192,7 @@ fn print_bytecode(class_file: &ClassFile, code: &Vec<(usize, Bytecode)>) {
192192
}
193193

194194
fn print_exception_table(
195-
class_file: &ClassFile, exception_table: &Vec<ExceptionTableEntry>
195+
class_file: &ClassFile, exception_table: &[ExceptionTableEntry]
196196
) {
197197
println!(" Exception table:");
198198
println!(" from to target type");

src/method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Method {
2121
attr.attribute_name_index as usize
2222
);
2323

24-
if let &ConstantUtf8 { ref string } = name_constant.deref() {
24+
if let ConstantUtf8 { ref string } = *name_constant.deref() {
2525
if string == "Code" {
2626
return Some(Code::from_bytes(&attr.info))
2727
}

src/parsing.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use constant_pool::*;
99
use field::*;
1010
use method::*;
1111

12-
const EXPECTED_MAGIC: u32 = 0xCAFEBABE;
12+
const EXPECTED_MAGIC: u32 = 0xCAFE_BABE;
1313

1414
const CONSTANT_TAG_UTF8: u8 = 1;
1515
const CONSTANT_TAG_CLASS: u8 = 7;
@@ -57,23 +57,23 @@ pub fn read_class_file(file: &mut File) -> io::Result<ClassFile> {
5757
fn read_u8(file: &mut File) -> io::Result<u8> {
5858
let mut buffer = [0; 1];
5959

60-
file.read(&mut buffer)?;
60+
file.read_exact(&mut buffer)?;
6161

6262
Ok(u8::from_be_bytes(buffer))
6363
}
6464

6565
fn read_u16(file: &mut File) -> io::Result<u16> {
6666
let mut buffer = [0; 2];
6767

68-
file.read(&mut buffer)?;
68+
file.read_exact(&mut buffer)?;
6969

7070
Ok(u16::from_be_bytes(buffer))
7171
}
7272

7373
fn read_u32(file: &mut File) -> io::Result<u32> {
7474
let mut buffer = [0; 4];
7575

76-
file.read(&mut buffer)?;
76+
file.read_exact(&mut buffer)?;
7777

7878
Ok(u32::from_be_bytes(buffer))
7979
}
@@ -87,7 +87,7 @@ fn read_n_bytes(file: &mut File, length: usize) -> io::Result<Vec<u8>> {
8787
}
8888

8989
fn read_constant_pool(file: &mut File) -> io::Result<Vec<Box<ConstantPoolEntry>>> {
90-
let constant_pool_count = read_u16(file)? as i32;
90+
let constant_pool_count = i32::from(read_u16(file)?);
9191

9292
let mut constant_pool = Vec::<Box<ConstantPoolEntry>>::new();
9393

@@ -172,7 +172,7 @@ fn read_constant_name_and_type(file: &mut File) -> io::Result<ConstantPoolEntry>
172172
}
173173

174174
fn read_interfaces(file: &mut File) -> io::Result<Vec<u16>> {
175-
let interfaces_count = read_u16(file)? as i32;
175+
let interfaces_count = i32::from(read_u16(file)?);
176176

177177
let mut interfaces = Vec::<u16>::new();
178178

@@ -186,7 +186,7 @@ fn read_interfaces(file: &mut File) -> io::Result<Vec<u16>> {
186186
}
187187

188188
fn read_fields(file: &mut File) -> io::Result<Vec<Field>> {
189-
let fields_count = read_u16(file)? as i32;
189+
let fields_count = i32::from(read_u16(file)?);
190190

191191
let mut fields = Vec::<Field>::new();
192192

@@ -215,7 +215,7 @@ fn read_field(file: &mut File) -> io::Result<Field> {
215215
}
216216

217217
fn read_methods(file: &mut File) -> io::Result<Vec<Method>> {
218-
let methods_count = read_u16(file)? as i32;
218+
let methods_count = i32::from(read_u16(file)?);
219219

220220
let mut methods = Vec::<Method>::new();
221221

0 commit comments

Comments
 (0)