Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add clippy job #1050

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ jobs:
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update stable && rustup default stable
- run: cargo clippy --all -- -D warnings

fuzz:
name: Fuzz
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-compose/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'a> TypeEncoder<'a> {
wasmparser::HeapType::Struct => HeapType::Struct,
wasmparser::HeapType::Array => HeapType::Array,
wasmparser::HeapType::I31 => HeapType::I31,
wasmparser::HeapType::Indexed(i) => HeapType::Indexed(i.into()),
wasmparser::HeapType::Indexed(i) => HeapType::Indexed(i),
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm-compose/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ mod test {
validate: true,
})?;

let wat = wasmprinter::print_bytes(&encoded)?;
let wat = wasmprinter::print_bytes(encoded)?;
assert_eq!(r#"(component)"#, wat);

Ok(())
Expand All @@ -1144,7 +1144,7 @@ mod test {
validate: true,
})?;

let wat = wasmprinter::print_bytes(&encoded)?.replace("\r\n", "\n");
let wat = wasmprinter::print_bytes(encoded)?.replace("\r\n", "\n");
assert_eq!(
r#"(component
(type (;0;)
Expand Down Expand Up @@ -1173,7 +1173,7 @@ mod test {
validate: true,
})?;

let wat = wasmprinter::print_bytes(&encoded)?.replace("\r\n", "\n");
let wat = wasmprinter::print_bytes(encoded)?.replace("\r\n", "\n");
assert_eq!(
r#"(component
(component (;0;))
Expand Down Expand Up @@ -1236,7 +1236,7 @@ mod test {
validate: true,
})?;

let wat = wasmprinter::print_bytes(&encoded)?.replace("\r\n", "\n");
let wat = wasmprinter::print_bytes(encoded)?.replace("\r\n", "\n");
assert_eq!(
r#"(component
(type (;0;)
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-compose/tests/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ fn component_composing() -> Result<()> {
};

if std::env::var_os("BLESS").is_some() {
fs::write(&baseline_path, output + "\n")?;
fs::write(baseline_path, output + "\n")?;
} else {
assert_eq!(
fs::read_to_string(&baseline_path)
fs::read_to_string(baseline_path)
.with_context(|| format!(
"failed to read component baseline `{}`",
baseline_path.display()
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-encoder/src/component/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ComponentNameSection {
}

/// View the encoded section as a CustomSection.
pub fn as_custom<'a>(&'a self) -> CustomSection<'a> {
pub fn as_custom(&self) -> CustomSection<'_> {
CustomSection {
name: "component-name".into(),
data: Cow::Borrowed(&self.bytes),
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-encoder/src/core/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl CoreDumpSection {
}

/// View the encoded section as a CustomSection.
fn as_custom<'a>(&'a self) -> CustomSection<'a> {
fn as_custom(&self) -> CustomSection<'_> {
let mut data = vec![0];
self.name.encode(&mut data);
CustomSection {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl CoreDumpStackSection {
}

/// View the encoded section as a CustomSection.
pub fn as_custom<'a>(&'a self) -> CustomSection<'a> {
pub fn as_custom(&self) -> CustomSection<'_> {
let mut data = vec![0];
self.name.encode(&mut data);
self.count.encode(&mut data);
Expand Down
6 changes: 3 additions & 3 deletions crates/wasm-encoder/src/core/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ElementSection {
}

/// Define an element segment.
pub fn segment<'a>(&mut self, segment: ElementSegment<'a>) -> &mut Self {
pub fn segment(&mut self, segment: ElementSegment<'_>) -> &mut Self {
let expr_bit = match segment.elements {
Elements::Expressions(_) => 0b100u32,
Elements::Functions(_) => 0b000u32,
Expand Down Expand Up @@ -184,7 +184,7 @@ impl ElementSection {
/// Encode a passive element segment.
///
/// Passive segments are part of the bulk memory proposal.
pub fn passive<'a>(&mut self, element_type: RefType, elements: Elements<'a>) -> &mut Self {
pub fn passive(&mut self, element_type: RefType, elements: Elements<'_>) -> &mut Self {
self.segment(ElementSegment {
mode: ElementMode::Passive,
element_type,
Expand All @@ -195,7 +195,7 @@ impl ElementSection {
/// Encode a declared element segment.
///
/// Declared segments are part of the bulk memory proposal.
pub fn declared<'a>(&mut self, element_type: RefType, elements: Elements<'a>) -> &mut Self {
pub fn declared(&mut self, element_type: RefType, elements: Elements<'_>) -> &mut Self {
self.segment(ElementSegment {
mode: ElementMode::Declared,
element_type,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-encoder/src/core/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl NameSection {
}

/// View the encoded section as a CustomSection.
pub fn as_custom<'a>(&'a self) -> CustomSection<'a> {
pub fn as_custom(&self) -> CustomSection<'_> {
CustomSection {
name: "name".into(),
data: Cow::Borrowed(&self.bytes),
Expand Down
22 changes: 2 additions & 20 deletions crates/wasm-encoder/src/core/producers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{CustomSection, Encode, Section, SectionId};
/// module.section(&producers);
/// let wasm_bytes = module.finish();
/// ```
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct ProducersSection {
bytes: Vec<u8>,
num_fields: u32,
Expand All @@ -47,15 +47,6 @@ impl ProducersSection {
}
}

impl Default for ProducersSection {
fn default() -> Self {
Self {
bytes: Vec::new(),
num_fields: 0,
}
}
}

impl Encode for ProducersSection {
fn encode(&self, sink: &mut Vec<u8>) {
let mut data = Vec::new();
Expand All @@ -77,7 +68,7 @@ impl Section for ProducersSection {
}

/// The value of a field in the producers custom section
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct ProducersField {
bytes: Vec<u8>,
num_values: u32,
Expand All @@ -100,15 +91,6 @@ impl ProducersField {
}
}

impl Default for ProducersField {
fn default() -> Self {
Self {
bytes: Vec::new(),
num_values: 0,
}
}
}

impl Encode for ProducersField {
fn encode(&self, sink: &mut Vec<u8>) {
self.num_values.encode(sink);
Expand Down
1 change: 0 additions & 1 deletion crates/wasm-mutate-stats/src/bin/wasm-mutate-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ impl State {
let generation_start = std::time::Instant::now();

let threads = (0..self.corpus.len())
.into_iter()
.map(|usize| {
let state = self.clone();
let artifact_folder = artifact_folders[usize].clone();
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-mutate/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ fn validate(validator: &mut Validator, bytes: &[u8]) {
Ok(_) => return,
Err(e) => e,
};
drop(std::fs::write("test.wasm", &bytes));
drop(std::fs::write("test.wasm", bytes));
if let Ok(text) = wasmprinter::print_bytes(bytes) {
drop(std::fs::write("test.wat", &text));
drop(std::fs::write("test.wat", text));
}

panic!("Wasm failed to validate: {:?}", err);
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-shrink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rand::{rngs::SmallRng, Rng, SeedableRng};
use wasm_mutate::WasmMutate;

#[rustfmt::skip]
static EMPTY_WASM: &'static [u8] = &[
static EMPTY_WASM: &[u8] = &[
// Magic.
0x00, b'a', b's', b'm',
// Version.
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-shrink/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn shrink_to_empty_allowed() -> Result<()> {
#[test]
fn smoke_test() -> Result<()> {
let info = WasmShrink::default().attempts(100).run(wasm(), |wasm| {
let wat = wasmprinter::print_bytes(&wasm)?;
let wat = wasmprinter::print_bytes(wasm)?;
Ok(wat.contains("local.get"))
})?;

Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-smith/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,9 @@ impl ComponentBuilder {
Ok(Step::StillBuilding)
}

fn arbitrary_type_ref<'a>(
fn arbitrary_type_ref(
&self,
u: &mut Unstructured<'a>,
u: &mut Unstructured<'_>,
for_import: bool,
for_type_def: bool,
) -> Result<Option<ComponentTypeRef>> {
Expand Down
10 changes: 5 additions & 5 deletions crates/wasm-smith/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ impl Module {
if self.funcs.len() >= self.config.max_funcs() {
continue;
} else if let Some((sig_idx, func_type)) = make_func_type(*sig_idx) {
let entity = EntityType::Func(sig_idx as u32, Rc::clone(&func_type));
let entity = EntityType::Func(sig_idx, Rc::clone(&func_type));
if type_size_budget < entity.size() {
continue;
}
Expand Down Expand Up @@ -828,7 +828,7 @@ impl Module {
arbitrary_loop(
u,
self.config.min_tables() as usize,
self.config.max_tables() as usize,
self.config.max_tables(),
|u| {
if !self.can_add_local_or_import_table() {
return Ok(false);
Expand All @@ -845,7 +845,7 @@ impl Module {
arbitrary_loop(
u,
self.config.min_memories() as usize,
self.config.max_memories() as usize,
self.config.max_memories(),
|u| {
if !self.can_add_local_or_import_memory() {
return Ok(false);
Expand Down Expand Up @@ -1002,7 +1002,7 @@ impl Module {
return Ok(());
}

let mut choices = Vec::with_capacity(self.funcs.len() as usize);
let mut choices = Vec::with_capacity(self.funcs.len());

for (func_idx, ty) in self.funcs() {
if ty.params.is_empty() && ty.results.is_empty() {
Expand Down Expand Up @@ -1654,7 +1654,7 @@ fn convert_reftype(ty: wasmparser::RefType) -> RefType {
wasmparser::HeapType::Struct => HeapType::Struct,
wasmparser::HeapType::Array => HeapType::Array,
wasmparser::HeapType::I31 => HeapType::I31,
wasmparser::HeapType::Indexed(i) => HeapType::Indexed(i.into()),
wasmparser::HeapType::Indexed(i) => HeapType::Indexed(i),
},
}
}
Expand Down
Loading