Skip to content

Commit c451588

Browse files
committed
fix format
1 parent cee4f6f commit c451588

File tree

7 files changed

+342
-339
lines changed

7 files changed

+342
-339
lines changed

libchisel/src/deployer.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ fn deployer_code() -> Vec<u8> {
6060
4100410020001001200041046b2802002102200041046b20026b21012001200210
6161
020b
6262
",
63-
).unwrap()
63+
)
64+
.unwrap()
6465
}
6566

6667
/// Returns a module which contains the deployable bytecode as a custom section.
@@ -181,7 +182,8 @@ mod tests {
181182
182183
000d086465706c6f79657200000000
183184
",
184-
).unwrap();
185+
)
186+
.unwrap();
185187
let output = parity_wasm::serialize(module).expect("Failed to serialize");
186188
assert_eq!(output, expected);
187189
}
@@ -204,7 +206,8 @@ mod tests {
204206
205207
0015086465706c6f79657280ff007faa55001108000000
206208
",
207-
).unwrap();
209+
)
210+
.unwrap();
208211
let output = parity_wasm::serialize(module).expect("Failed to serialize");
209212
assert_eq!(output, expected);
210213
}
@@ -222,7 +225,8 @@ mod tests {
222225
696e697368000003030200010503010001071102046d61696e0001066d656d6f72
223226
7902000a0d0202000b08004100410010000b0b06010041000b00
224227
",
225-
).unwrap();
228+
)
229+
.unwrap();
226230
let output = parity_wasm::serialize(module).expect("Failed to serialize");
227231
assert_eq!(output, expected);
228232
}
@@ -241,7 +245,8 @@ mod tests {
241245
7902000a0d0202000b08004100410810000b0b0e010041000b0880ff007faa5500
242246
11
243247
",
244-
).unwrap();
248+
)
249+
.unwrap();
245250
let output = parity_wasm::serialize(module).expect("Failed to serialize");
246251
assert_eq!(output, expected);
247252
}

libchisel/src/instructionerrors.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,36 @@ use std::fmt;
44

55
#[derive(Debug)]
66
pub enum InstructionError {
7-
GlobalNotFound,
8-
LocalNotFound,
9-
UnmatchedInstruction,
10-
InvalidOperation(Instruction),
7+
GlobalNotFound,
8+
LocalNotFound,
9+
UnmatchedInstruction,
10+
InvalidOperation(Instruction),
1111
}
1212

1313
impl fmt::Display for InstructionError {
14-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15-
match self {
16-
InstructionError::GlobalNotFound =>
17-
write!(f, "Global not found"),
18-
InstructionError::LocalNotFound =>
19-
write!(f, "Local not found"),
20-
InstructionError::UnmatchedInstruction =>
21-
write!(f, "Unmatched instruction"),
22-
InstructionError::InvalidOperation(i) =>
23-
write!(f, "{}", format!("Invalid operation: {:?}", i).as_str()),
24-
}
25-
}
14+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15+
match self {
16+
InstructionError::GlobalNotFound => write!(f, "Global not found"),
17+
InstructionError::LocalNotFound => write!(f, "Local not found"),
18+
InstructionError::UnmatchedInstruction => write!(f, "Unmatched instruction"),
19+
InstructionError::InvalidOperation(i) => {
20+
write!(f, "{}", format!("Invalid operation: {:?}", i).as_str())
21+
}
22+
}
23+
}
2624
}
2725

2826
impl error::Error for InstructionError {
29-
fn description(&self) -> &str {
30-
match self {
31-
InstructionError::GlobalNotFound =>
32-
"Global not found",
33-
InstructionError::LocalNotFound =>
34-
"Local not found",
35-
InstructionError::UnmatchedInstruction =>
36-
"Unmatched instruction",
37-
InstructionError::InvalidOperation(_) =>
38-
"Invalid operation"
39-
}
40-
}
27+
fn description(&self) -> &str {
28+
match self {
29+
InstructionError::GlobalNotFound => "Global not found",
30+
InstructionError::LocalNotFound => "Local not found",
31+
InstructionError::UnmatchedInstruction => "Unmatched instruction",
32+
InstructionError::InvalidOperation(_) => "Invalid operation",
33+
}
34+
}
4135

42-
fn cause(&self) -> Option<&error::Error> {
43-
None
44-
}
36+
fn cause(&self) -> Option<&error::Error> {
37+
None
38+
}
4539
}

libchisel/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ extern crate rustc_hex;
44

55
pub mod checkstartfunc;
66
pub mod deployer;
7+
mod instructionerrors;
78
pub mod remapimports;
89
pub mod trimexports;
910
pub mod verifyexports;
1011
pub mod verifyimports;
1112
pub mod verifyinstructions;
12-
mod instructionerrors;
1313

1414
use crate::instructionerrors::*;
1515
use parity_wasm::elements::*;

libchisel/src/remapimports.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl Translations {
118118
ImportPair::new("ethereum", "selfDestruct"),
119119
),
120120
]
121-
.iter()
122-
.cloned()
123-
.collect();
121+
.iter()
122+
.cloned()
123+
.collect();
124124
Ok(Translations {
125125
translations: trans,
126126
})
@@ -203,7 +203,8 @@ mod tests {
203203
0061736d0100000001050160017e0002170103656e760f65746865726575
204204
6d5f7573654761730000
205205
",
206-
).unwrap();
206+
)
207+
.unwrap();
207208
let mut module = parity_wasm::deserialize_buffer(&input).expect("failed");
208209
let did_change = RemapImports::with_preset("ewasm")
209210
.unwrap()
@@ -215,7 +216,8 @@ mod tests {
215216
0061736d0100000001050160017e0002130108657468657265756d067573
216217
654761730000
217218
",
218-
).unwrap();
219+
)
220+
.unwrap();
219221
assert_eq!(output, expected);
220222
assert!(did_change);
221223
}

libchisel/src/verifyexports.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ fn has_table_export(section: &ExportSection, field: &str) -> bool {
128128
fn has_func_export(module: &Module, field: &str, sig: &FunctionType) -> bool {
129129
if let Some(section) = module.export_section() {
130130
match func_export_index_by_name(section, field) {
131-
Some(index) => if let Some(resolved) = func_sig_by_index(module, index) {
132-
*sig == *resolved
133-
} else {
134-
false
135-
},
131+
Some(index) => {
132+
if let Some(resolved) = func_sig_by_index(module, index) {
133+
*sig == *resolved
134+
} else {
135+
false
136+
}
137+
}
136138
None => false,
137139
}
138140
} else {
@@ -181,7 +183,8 @@ fn func_import_section_len(imports: &ImportSection) -> u32 {
181183
.filter(|e| match e.external() {
182184
&External::Function(_) => true,
183185
_ => false,
184-
}).count() as u32
186+
})
187+
.count() as u32
185188
}
186189

187190
/// Resolves a function export's index by name. Can be trivially adjusted for

libchisel/src/verifyimports.rs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ impl<'a> VerifyImports<'a> {
272272
"selfDestruct",
273273
FunctionType::new(vec![ValueType::I32], None),
274274
),
275-
].iter()
275+
]
276+
.iter()
276277
.cloned()
277278
.collect(),
278279
require_all: false,
@@ -389,32 +390,40 @@ impl<'a> ImportCheck for ImportType<'a> {
389390
{
390391
match entry.external() {
391392
// TODO: Wrap this in a helper.
392-
External::Function(idx) => if let Some(sig) = func_sig {
393-
if *sig == imported_func_sig_by_index(module, *idx as usize) {
394-
ImportStatus::Good
393+
External::Function(idx) => {
394+
if let Some(sig) = func_sig {
395+
if *sig == imported_func_sig_by_index(module, *idx as usize) {
396+
ImportStatus::Good
397+
} else {
398+
ImportStatus::Malformed
399+
}
395400
} else {
396401
ImportStatus::Malformed
397402
}
398-
} else {
399-
ImportStatus::Malformed
400-
},
403+
}
401404
// NOTE: There may be a better way to do mappings between enum variants.
402405
// Just check import variant here.
403-
External::Global(_idx) => if let ImportType::Global(_n, _f) = self {
404-
ImportStatus::Good
405-
} else {
406-
ImportStatus::Malformed
407-
},
408-
External::Memory(_idx) => if let ImportType::Memory(_n, _f) = self {
409-
ImportStatus::Good
410-
} else {
411-
ImportStatus::Malformed
412-
},
413-
External::Table(_idx) => if let ImportType::Table(_n, _f) = self {
414-
ImportStatus::Good
415-
} else {
416-
ImportStatus::Malformed
417-
},
406+
External::Global(_idx) => {
407+
if let ImportType::Global(_n, _f) = self {
408+
ImportStatus::Good
409+
} else {
410+
ImportStatus::Malformed
411+
}
412+
}
413+
External::Memory(_idx) => {
414+
if let ImportType::Memory(_n, _f) = self {
415+
ImportStatus::Good
416+
} else {
417+
ImportStatus::Malformed
418+
}
419+
}
420+
External::Table(_idx) => {
421+
if let ImportType::Table(_n, _f) = self {
422+
ImportStatus::Good
423+
} else {
424+
ImportStatus::Malformed
425+
}
426+
}
418427
}
419428
} else {
420429
ImportStatus::NotFound
@@ -777,7 +786,8 @@ mod tests {
777786
"ethereum",
778787
"storageStore",
779788
FunctionType::new(vec![ValueType::I32, ValueType::I32], None),
780-
)].iter()
789+
)]
790+
.iter()
781791
.cloned()
782792
.collect(),
783793
allow_unlisted: false,
@@ -814,7 +824,8 @@ mod tests {
814824
"ethereum",
815825
"storageStore",
816826
FunctionType::new(vec![ValueType::I32, ValueType::I32], None),
817-
)].iter()
827+
)]
828+
.iter()
818829
.cloned()
819830
.collect(),
820831
allow_unlisted: true,
@@ -851,7 +862,8 @@ mod tests {
851862
"ethereum",
852863
"storageStore",
853864
FunctionType::new(vec![ValueType::I32, ValueType::I32], None),
854-
)].iter()
865+
)]
866+
.iter()
855867
.cloned()
856868
.collect(),
857869
allow_unlisted: false,
@@ -888,7 +900,8 @@ mod tests {
888900
"ethereum",
889901
"storageStore",
890902
FunctionType::new(vec![ValueType::I32, ValueType::I32], None),
891-
)].iter()
903+
)]
904+
.iter()
892905
.cloned()
893906
.collect(),
894907
allow_unlisted: false,

0 commit comments

Comments
 (0)