From 706a88e21c9de00d4e3ef5bd591d5169bc94f982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Mon, 8 Jun 2020 21:00:46 +0100 Subject: [PATCH] Fix clippy errors (#62) * Move from travis to github actions (#58) * Added github actions * Remove travis * Fixed clippy warnings * Add the clippy check to ci * Move workflows to .github * Fix missing clippy --- .github/workflows/pipeline.yml | 32 ++++++++++++++++++++++++++++++++ .travis.yml | 1 - src/back/msl.rs | 18 +++++++----------- src/front/spirv.rs | 25 +++++++++++++------------ src/front/wgsl.rs | 6 +++--- 5 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/pipeline.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000000..d455eeeb1e --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,32 @@ +name: pipeline +on: [push, pull_request] + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: test + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 22761ba7ee..0000000000 --- a/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: rust diff --git a/src/back/msl.rs b/src/back/msl.rs index 20eb6a3706..a2086ef7f0 100644 --- a/src/back/msl.rs +++ b/src/back/msl.rs @@ -460,10 +460,8 @@ impl Writer { return Ok(MaybeOwned::Borrowed(base_inner)); } } - } else { - if let crate::TypeInner::Struct { .. } = *inner { + } else if let crate::TypeInner::Struct { .. } = *inner { return Ok(MaybeOwned::Borrowed(inner)); - } } write!(self.out, "{}.", OUTPUT_STRUCT_NAME)?; } @@ -881,15 +879,13 @@ impl Writer { resolved.try_fmt_decorated(&mut self.out, ";\n")?; } } - } else { - if let Some(ref binding@crate::Binding::Location(_)) = var.binding { - let tyvar = TypedGlobalVariable { module, handle, usage: crate::GlobalUse::empty() }; - let resolved = options.resolve_binding(binding, in_mode)?; + } else if let Some(ref binding@crate::Binding::Location(_)) = var.binding { + let tyvar = TypedGlobalVariable { module, handle, usage: crate::GlobalUse::empty() }; + let resolved = options.resolve_binding(binding, in_mode)?; - write!(self.out, "\t")?; - tyvar.try_fmt(&mut self.out)?; - resolved.try_fmt_decorated(&mut self.out, ";\n")?; - } + write!(self.out, "\t")?; + tyvar.try_fmt(&mut self.out)?; + resolved.try_fmt_decorated(&mut self.out, ";\n")?; } } writeln!(self.out, "}};")?; diff --git a/src/front/spirv.rs b/src/front/spirv.rs index 3afcb39bf3..142d00576e 100644 --- a/src/front/spirv.rs +++ b/src/front/spirv.rs @@ -763,7 +763,7 @@ impl> Parser { return Err(Error::InvalidOperand); } if !SUPPORTED_EXTENSIONS.contains(&name.as_str()) { - return Err(Error::UnsupportedExtension(name.to_owned())); + return Err(Error::UnsupportedExtension(name)); } Ok(()) } @@ -777,7 +777,7 @@ impl> Parser { return Err(Error::InvalidOperand); } if !SUPPORTED_EXT_SETS.contains(&name.as_str()) { - return Err(Error::UnsupportedExtSet(name.to_owned())); + return Err(Error::UnsupportedExtSet(name)); } Ok(()) } @@ -804,7 +804,7 @@ impl> Parser { let (name, left) = self.next_string(inst.wc - 3)?; let ep = EntryPoint { exec_model, - name: name.to_owned(), + name, function_id, variable_ids: self.data .by_ref() @@ -852,7 +852,7 @@ impl> Parser { self.future_decor .entry(id) .or_default() - .name = Some(name.to_owned()); + .name = Some(name); Ok(()) } @@ -868,7 +868,7 @@ impl> Parser { self.future_member_decor .entry((id, member)) .or_default() - .name = Some(name.to_owned()); + .name = Some(name); Ok(()) } @@ -1266,14 +1266,15 @@ impl> Parser { crate::ConstantInner::Uint((u64::from(high) << 32) | u64::from(low)) } crate::TypeInner::Scalar { kind: crate::ScalarKind::Sint, width } => { + use std::cmp::Ordering; let low = self.next()?; - let high = if width < 32 { - return Err(Error::InvalidTypeWidth(u32::from(width))); - } else if width > 32 { - inst.expect(4)?; - self.next()? - } else { - !0 + let high = match width.cmp(&32) { + Ordering::Less => return Err(Error::InvalidTypeWidth(u32::from(width))), + Ordering::Greater => { + inst.expect(4)?; + self.next()? + }, + Ordering::Equal => !0 }; crate::ConstantInner::Sint(((u64::from(high) << 32) | u64::from(low)) as i64) } diff --git a/src/front/wgsl.rs b/src/front/wgsl.rs index 5e7ac351da..22cbc4eea4 100644 --- a/src/front/wgsl.rs +++ b/src/front/wgsl.rs @@ -521,7 +521,7 @@ impl Parser { self.scopes.pop(); return Ok(*handle); } - if self.std_namespace.as_ref().map(|s| s.as_str()) == Some(word) { + if self.std_namespace.as_deref() == Some(word) { lexer.expect(Token::DoubleColon)?; let name = lexer.next_ident()?; let mut arguments = Vec::new(); @@ -575,7 +575,7 @@ impl Parser { crate::TypeInner::Struct { ref members } => { let index = members .iter() - .position(|m| m.name.as_ref().map(|s| s.as_str()) == Some(name)) + .position(|m| m.name.as_deref() == Some(name)) .ok_or(Error::BadAccessor(name))? as u32; crate::Expression::AccessIndex { base: handle, @@ -1354,7 +1354,7 @@ impl Parser { lexer.expect(Token::Separator(';'))?; let (fun_handle, _) = module.functions .iter() - .find(|(_, fun)| fun.name.as_ref().map(|s| s.as_str()) == Some(fun_ident)) + .find(|(_, fun)| fun.name.as_deref() == Some(fun_ident)) .ok_or(Error::UnknownFunction(fun_ident))?; module.entry_points.push(crate::EntryPoint { exec_model,