Skip to content

Commit 724c3be

Browse files
committed
remove redundant imports and prefer it.first() to it.get(0)
1 parent 6627ad1 commit 724c3be

File tree

9 files changed

+6
-9
lines changed

9 files changed

+6
-9
lines changed

spec-test/src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl<'s> Parse<'s> for Script<'s> {
634634
while !parser.is_done()? {
635635
commands.push(parser.parse()?);
636636
}
637-
let start = commands.get(0).map(Command::start_pos).unwrap_or(0);
637+
let start = commands.first().map(Command::start_pos).unwrap_or(0);
638638
Ok(Script { start, commands })
639639
}
640640
}

wain-exec/src/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Memory {
2222
pub fn allocate(memories: &[ast::Memory]) -> Result<Self> {
2323
// Note: Only one memory exists thanks to validation
2424
assert!(memories.len() <= 1);
25-
if let Some(memory) = memories.get(0) {
25+
if let Some(memory) = memories.first() {
2626
if let Some(i) = &memory.import {
2727
Err(Trap::unknown_import(i, "memory", memory.start))
2828
} else {

wain-exec/src/runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'m, 's, I: Importer> Runtime<'m, 's, I> {
9999

100100
let fty = &module.types[func.idx as usize];
101101
let name = &i.name.0;
102-
match importer.validate(name, &fty.params, fty.results.get(0).copied()) {
102+
match importer.validate(name, &fty.params, fty.results.first().copied()) {
103103
Some(ImportInvalidError::NotFound) => {
104104
return Err(unknown_import(i, func.start));
105105
}

wain-exec/src/stack.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::value::{LittleEndian, Value};
22
use std::cmp::Ordering;
3-
use std::convert::{TryFrom, TryInto};
43
use std::fmt;
54
use std::mem;
65
use std::mem::size_of;

wain-exec/src/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Table {
1313
pub fn allocate(tables: &[ast::Table]) -> Result<Self> {
1414
// Note: Only one table exists thanks to validation
1515
assert!(tables.len() <= 1);
16-
if let Some(table) = tables.get(0) {
16+
if let Some(table) = tables.first() {
1717
if let Some(i) = &table.import {
1818
Err(Trap::unknown_import(i, "table", table.start))
1919
} else {

wain-exec/src/value.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::convert::{TryFrom, TryInto};
21
use std::fmt;
32
use std::mem::size_of;
43
use std::ops;

wain-syntax-binary/src/leb128.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ mod tests {
177177

178178
#[test]
179179
fn u32_value_ok() {
180-
for (input, expected) in vec![
180+
for (input, expected) in [
181181
(vec![0x00], 0),
182182
(vec![0x80, 0x01], 128),
183183
(vec![0xc0, 0xc4, 0x07], 123456),

wain-syntax-binary/src/parser.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::error::{Error, ErrorKind, Result};
22
use crate::leb128::Leb128;
33
use crate::source::BinarySource;
44
use std::borrow::Cow;
5-
use std::convert::TryInto;
65
use std::marker::PhantomData;
76
use std::str;
87
use wain_ast::*;

wain-validate/src/insn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub(crate) fn validate_func_body<'outer, S: Source>(
252252
) -> Result<(), S> {
253253
// Note: FuncType already validated func_ty has at most one result type
254254
// This assumes a function can have only one return value
255-
let ret_ty = func_ty.results.get(0).copied();
255+
let ret_ty = func_ty.results.first().copied();
256256
let mut ctx = FuncBodyContext {
257257
current_op: "",
258258
current_offset: start,

0 commit comments

Comments
 (0)