Skip to content

Commit

Permalink
Apply clippy to all code (use-ink#306)
Browse files Browse the repository at this point in the history
* Check all the code with clippy

* Fix clippy warnings
  • Loading branch information
athei authored Jul 20, 2021
1 parent 9b36b62 commit 5f3a7a7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ clippy:
stage: check
<<: *docker-env
script:
- cargo clippy --verbose -- -D warnings;
- cargo clippy --verbose --all-targets --all-features -- -D warnings;

#### stage: test (all features)

Expand Down
9 changes: 3 additions & 6 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,7 @@ mod tests_ci_only {

/// Modifies the `Cargo.toml` under the supplied `cargo_toml_path` by
/// setting `optimization-passes` in `[package.metadata.contract]` to `passes`.
fn write_optimization_passes_into_manifest(
cargo_toml_path: &PathBuf,
passes: OptimizationPasses,
) {
fn write_optimization_passes_into_manifest(cargo_toml_path: &Path, passes: OptimizationPasses) {
let manifest_path =
ManifestPath::new(cargo_toml_path).expect("manifest path creation failed");
let mut manifest = Manifest::new(manifest_path.clone()).expect("manifest creation failed");
Expand Down Expand Up @@ -760,7 +757,7 @@ mod tests_ci_only {
with_new_contract_project(|manifest_path| {
// given
write_optimization_passes_into_manifest(
&manifest_path.clone().into(),
manifest_path.as_ref(),
OptimizationPasses::Three,
);
let cmd = BuildCommand {
Expand Down Expand Up @@ -798,7 +795,7 @@ mod tests_ci_only {
with_new_contract_project(|manifest_path| {
// given
write_optimization_passes_into_manifest(
&manifest_path.clone().into(),
manifest_path.as_ref(),
OptimizationPasses::Three,
);
let cmd = BuildCommand {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) fn execute_deploy(
let events = cli.put_code_and_watch(&signer, &code).await?;
let code_stored = events
.code_stored()?
.ok_or(anyhow::anyhow!("Failed to find CodeStored event"))?;
.context("Failed to find CodeStored event")?;

Ok(code_stored.code_hash)
})
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

use anyhow::Result;
use anyhow::{Context, Result};
use subxt::{balances::Balances, contracts::*, system::System, ClientBuilder, DefaultNodeRuntime};

use crate::{ExtrinsicOpts, HexData};
Expand Down Expand Up @@ -43,7 +43,7 @@ pub(crate) fn execute_instantiate(
.await?;
let instantiated = events
.instantiated()?
.ok_or(anyhow::anyhow!("Failed to find Instantiated event"))?;
.context("Failed to find Instantiated event")?;

Ok(instantiated.contract)
})
Expand Down
19 changes: 7 additions & 12 deletions src/cmd/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ mod tests {
cmd, crate_metadata::CrateMetadata, util::tests::with_new_contract_project, BuildArtifacts,
ManifestPath, OptimizationPasses, UnstableFlags, Verbosity,
};
use anyhow::Context;
use contract_metadata::*;
use serde_json::{Map, Value};
use std::{fmt::Write, fs};
Expand All @@ -249,9 +250,9 @@ mod tests {
fn package_mut(&mut self) -> anyhow::Result<&mut value::Table> {
self.toml
.get_mut("package")
.ok_or(anyhow::anyhow!("package section not found"))?
.context("package section not found")?
.as_table_mut()
.ok_or(anyhow::anyhow!("package section should be a table"))
.context("package section should be a table")
}

/// Add a key/value to the `[package.metadata.contract.user]` section
Expand All @@ -264,19 +265,15 @@ mod tests {
.entry("metadata")
.or_insert(value::Value::Table(Default::default()))
.as_table_mut()
.ok_or(anyhow::anyhow!("metadata section should be a table"))?
.context("metadata section should be a table")?
.entry("contract")
.or_insert(value::Value::Table(Default::default()))
.as_table_mut()
.ok_or(anyhow::anyhow!(
"metadata.contract section should be a table"
))?
.context("metadata.contract section should be a table")?
.entry("user")
.or_insert(value::Value::Table(Default::default()))
.as_table_mut()
.ok_or(anyhow::anyhow!(
"metadata.contract.user section should be a table"
))?
.context("metadata.contract.user section should be a table")?
.insert(key.into(), value);
Ok(())
}
Expand Down Expand Up @@ -393,9 +390,7 @@ mod tests {
.insert("some-user-provided-field".into(), "and-its-value".into());
expected_user_metadata.insert(
"more-user-provided-fields".into(),
serde_json::Value::Array(
vec!["and".into(), "their".into(), "values".into()].into(),
),
serde_json::Value::Array(vec!["and".into(), "their".into(), "values".into()]),
);

assert_eq!(build_byte_str(&expected_hash.0[..]), hash.as_str().unwrap());
Expand Down
8 changes: 3 additions & 5 deletions src/workspace/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,15 @@ impl Manifest {
.entry("package")
.or_insert(value::Value::Table(Default::default()))
.as_table_mut()
.ok_or(anyhow::anyhow!("package section should be a table"))?
.context("package section should be a table")?
.entry("metadata")
.or_insert(value::Value::Table(Default::default()))
.as_table_mut()
.ok_or(anyhow::anyhow!("metadata section should be a table"))?
.context("metadata section should be a table")?
.entry("contract")
.or_insert(value::Value::Table(Default::default()))
.as_table_mut()
.ok_or(anyhow::anyhow!(
"metadata.contract section should be a table"
))?
.context("metadata.contract section should be a table")?
.insert(
"optimization-passes".to_string(),
value::Value::String(passes.to_string()),
Expand Down

0 comments on commit 5f3a7a7

Please sign in to comment.