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

chore: clippy fixes #728

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
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
159 changes: 159 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# paths = ["/path/to/override"] # path dependency overrides

# [alias] # command aliases
# b = "build"
# c = "check"
# t = "test"
# r = "run"
# rr = "run --release"
# recursive_example = "rr --example recursions"
# space_example = ["run", "--release", "--", "\"command list\""]

[build]
# jobs = 1 # number of parallel jobs, defaults to # of CPUs
# rustc = "rustc" # the rust compiler tool
# rustc-wrapper = "…" # run this wrapper instead of `rustc`
# rustc-workspace-wrapper = "…" # run this wrapper instead of `rustc` for workspace members
# rustdoc = "rustdoc" # the doc generator tool
# target = "triple" # build for the target triple (ignored by `cargo install`)
# target-dir = "target" # path of where to place all generated artifacts
rustflags = [
"-Dwarnings",
"-Dclippy::pedantic",
"-Aclippy::module_name_repetitions",
"-Aclippy::needless_pass_by_value",
"-Aclippy::too_many_lines",
"-Aclippy::must_use_candidate",
"-Aclippy::missing_errors_doc",
"-Aclippy::missing_safety_doc",
"-Aclippy::inline_always",
"-Aclippy::cast_possible_truncation",
"-Aclippy::cast_sign_loss",
"-Aclippy::cast_possible_wrap",
"-Aclippy::similar_names",
"-Aclippy::doc_markdown",
"-Aclippy::default_trait_access",
"-Aclippy::missing_safety_doc",
"-Aclippy::struct_excessive_bools",
"-Aclippy::missing_panics_doc",
"-Aclippy::cast_lossless",
"-Aclippy::trivially_copy_pass_by_ref",
"-Aclippy::wrong_self_convention",
"-Aclippy::unused_self",
"-Aclippy::enum_glob_use",
"-Aclippy::return_self_not_must_use",
"-Aclippy::map_entry",
"-Aclippy::match_same_arms",
"-Aclippy::iter_not_returning_iterator",
"-Aclippy::unnecessary_wraps",
"-Aclippy::type_complexity",
] # custom flags to pass to all compiler invocations
# rustdocflags = ["…", "…"] # custom flags to pass to rustdoc
# incremental = true # whether or not to enable incremental compilation
# dep-info-basedir = "…" # path for the base directory for targets in depfiles

# [doc]
# browser = "chromium" # browser to use with `cargo doc --open`,
# # overrides the `BROWSER` environment variable

# [env]
# # Set ENV_VAR_NAME=value for any process run by Cargo
# ENV_VAR_NAME = "value"
# # Set even if already present in environment
# ENV_VAR_NAME_2 = { value = "value", force = true }
# # Value is relative to .cargo directory containing `config.toml`, make absolute
# ENV_VAR_NAME_3 = { value = "relative/path", relative = true }

# [future-incompat-report]
# frequency = 'always' # when to display a notification about a future incompat report

# [cargo-new]
# vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')

# [http]
# debug = false # HTTP debugging
# proxy = "host:port" # HTTP proxy in libcurl format
# ssl-version = "tlsv1.3" # TLS version to use
# ssl-version.max = "tlsv1.3" # maximum TLS version
# ssl-version.min = "tlsv1.1" # minimum TLS version
# timeout = 30 # timeout for each HTTP request, in seconds
# low-speed-limit = 10 # network timeout threshold (bytes/sec)
# cainfo = "cert.pem" # path to Certificate Authority (CA) bundle
# check-revoke = true # check for SSL certificate revocation
# multiplexing = true # HTTP/2 multiplexing
# user-agent = "…" # the user-agent header

# [install]
# root = "/some/path" # `cargo install` destination directory

# [net]
# retry = 2 # network retries
# git-fetch-with-cli = true # use the `git` executable for git operations
# offline = true # do not access the network

# [net.ssh]
# known-hosts = ["..."] # known SSH host keys

# [patch.<registry>]
# # Same keys as for [patch] in Cargo.toml

# [profile.<name>] # Modify profile settings via config.
# inherits = "dev" # Inherits settings from [profile.dev].
# opt-level = 0 # Optimization level.
# debug = true # Include debug info.
# split-debuginfo = '...' # Debug info splitting behavior.
# debug-assertions = true # Enables debug assertions.
# overflow-checks = true # Enables runtime integer overflow checks.
# lto = false # Sets link-time optimization.
# panic = 'unwind' # The panic strategy.
# incremental = true # Incremental compilation.
# codegen-units = 16 # Number of code generation units.
# rpath = false # Sets the rpath linking option.
# [profile.<name>.build-override] # Overrides build-script settings.
# # Same keys for a normal profile.
# [profile.<name>.package.<name>] # Override profile for a package.
# # Same keys for a normal profile (minus `panic`, `lto`, and `rpath`).

# [registries.<name>] # registries other than crates.io
# index = "…" # URL of the registry index
# token = "…" # authentication token for the registry

# [registry]
# default = "…" # name of the default registry
# token = "…" # authentication token for crates.io

# [source.<name>] # source definition and replacement
# replace-with = "…" # replace this source with the given named source
# directory = "…" # path to a directory source
# registry = "…" # URL to a registry source
# local-registry = "…" # path to a local registry source
# git = "…" # URL of a git repository source
# branch = "…" # branch name for the git repository
# tag = "…" # tag name for the git repository
# rev = "…" # revision for the git repository

# [target.<triple>]
# linker = "…" # linker to use
# runner = "…" # wrapper to run executables
# rustflags = ["…", "…"] # custom flags for `rustc`

# [target.<cfg>]
# runner = "…" # wrapper to run executables
# rustflags = ["…", "…"] # custom flags for `rustc`

# [target.<triple>.<links>] # `links` build script override
# rustc-link-lib = ["foo"]
# rustc-link-search = ["/path/to/foo"]
# rustc-flags = ["-L", "/some/path"]
# rustc-cfg = ['key="value"']
# rustc-env = {key = "value"}
# rustc-cdylib-link-arg = ["…"]
# metadata_key1 = "value"
# metadata_key2 = "value"

# [term]
# quiet = false # whether cargo output is quiet
# verbose = false # whether cargo provides verbose output
# color = 'auto' # whether cargo colorizes output
# progress.when = 'auto' # whether cargo shows progress bar
# progress.width = 80 # width of progress bar
5 changes: 1 addition & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on:
branches: [main, release/**]
pull_request:

env:
RUSTFLAGS: -D warnings

jobs:

complete:
Expand Down Expand Up @@ -64,7 +61,7 @@ jobs:
with:
name: cargo-hack
version: 0.5.16
- run: cargo hack --feature-powerset check --locked --target ${{ matrix.sys.target }}
- run: cargo hack --feature-powerset clippy --locked --target ${{ matrix.sys.target }}
- if: matrix.sys.test
run: cargo hack --feature-powerset test --locked --target ${{ matrix.sys.target }}

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ test:
build:
cargo hack --feature-powerset check

clippy:
cargo hack --feature-powerset clippy --all-targets

watch:
cargo watch --clear --watch-when-idle --shell '$(MAKE)'

Expand Down
121 changes: 56 additions & 65 deletions soroban-env-common/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<T, C: Compare<T>> Compare<Box<T>> for C {
type Error = C::Error;

fn compare(&self, a: &Box<T>, b: &Box<T>) -> Result<Ordering, Self::Error> {
<Self as Compare<T>>::compare(self, &*a, &*b)
<Self as Compare<T>>::compare(self, a, b)
}
}

Expand All @@ -106,7 +106,7 @@ impl<T, C: Compare<T>> Compare<Rc<T>> for C {
type Error = C::Error;

fn compare(&self, a: &Rc<T>, b: &Rc<T>) -> Result<Ordering, Self::Error> {
<Self as Compare<T>>::compare(self, &*a, &*b)
<Self as Compare<T>>::compare(self, a, b)
}
}

Expand Down Expand Up @@ -135,74 +135,65 @@ impl<E: Env> Compare<RawVal> for E {
if a.is_object() || b.is_object() {
// Delegate any object-comparing to environment.
let v = self.obj_cmp(*a, *b)?;
return if v == 0 {
Ok(Ordering::Equal)
} else if v < 0 {
Ok(Ordering::Less)
} else {
Ok(Ordering::Greater)
};
return Ok(v.cmp(&0));
}
let a_tag = a.get_tag();
let b_tag = b.get_tag();
if a_tag < b_tag {
Ok(Ordering::Less)
} else if a_tag > b_tag {
Ok(Ordering::Greater)
} else {
match a_tag.cmp(&b_tag) {
Ordering::Equal =>
// Tags are equal so we only have to switch on one.
match a_tag {
Tag::False => Ok(Ordering::Equal),
Tag::True => Ok(Ordering::Equal),
Tag::Void => Ok(Ordering::Equal),

Tag::Status => delegate_compare_to_wrapper!(Status, a, b, self),

Tag::U32Val => delegate_compare_to_wrapper!(U32Val, a, b, self),
Tag::I32Val => delegate_compare_to_wrapper!(I32Val, a, b, self),

Tag::U64Small => delegate_compare_to_wrapper!(U64Small, a, b, self),
Tag::I64Small => delegate_compare_to_wrapper!(I64Small, a, b, self),

Tag::TimepointSmall => delegate_compare_to_wrapper!(TimepointSmall, a, b, self),
Tag::DurationSmall => delegate_compare_to_wrapper!(DurationSmall, a, b, self),

Tag::U128Small => delegate_compare_to_wrapper!(U128Small, a, b, self),
Tag::I128Small => delegate_compare_to_wrapper!(I128Small, a, b, self),

Tag::U256Small => delegate_compare_to_wrapper!(U256Small, a, b, self),
Tag::I256Small => delegate_compare_to_wrapper!(I256Small, a, b, self),

Tag::SymbolSmall => delegate_compare_to_wrapper!(SymbolSmall, a, b, self),

Tag::LedgerKeyContractExecutable => Ok(Ordering::Equal),

Tag::SmallCodeUpperBound => Ok(Ordering::Equal),
Tag::ObjectCodeLowerBound => Ok(Ordering::Equal),

// None of the object cases should be reachable, they
// should all have been handled by the is_object() branch
// above.
Tag::U64Object
| Tag::I64Object
| Tag::TimepointObject
| Tag::DurationObject
| Tag::U128Object
| Tag::I128Object
| Tag::U256Object
| Tag::I256Object
| Tag::BytesObject
| Tag::StringObject
| Tag::SymbolObject
| Tag::VecObject
| Tag::MapObject
| Tag::ContractExecutableObject
| Tag::AddressObject
| Tag::LedgerKeyNonceObject => unreachable!(),

Tag::ObjectCodeUpperBound => Ok(Ordering::Equal),
Tag::Bad => Ok(Ordering::Equal),
{
match a_tag {
Tag::False
| Tag::True
| Tag::Void
| Tag::LedgerKeyContractExecutable
| Tag::SmallCodeUpperBound
| Tag::ObjectCodeLowerBound
| Tag::ObjectCodeUpperBound
| Tag::Bad => Ok(Ordering::Equal),

Tag::Status => delegate_compare_to_wrapper!(Status, a, b, self),

Tag::U32Val => delegate_compare_to_wrapper!(U32Val, a, b, self),
Tag::I32Val => delegate_compare_to_wrapper!(I32Val, a, b, self),

Tag::U64Small => delegate_compare_to_wrapper!(U64Small, a, b, self),
Tag::I64Small => delegate_compare_to_wrapper!(I64Small, a, b, self),

Tag::TimepointSmall => delegate_compare_to_wrapper!(TimepointSmall, a, b, self),
Tag::DurationSmall => delegate_compare_to_wrapper!(DurationSmall, a, b, self),

Tag::U128Small => delegate_compare_to_wrapper!(U128Small, a, b, self),
Tag::I128Small => delegate_compare_to_wrapper!(I128Small, a, b, self),

Tag::U256Small => delegate_compare_to_wrapper!(U256Small, a, b, self),
Tag::I256Small => delegate_compare_to_wrapper!(I256Small, a, b, self),

Tag::SymbolSmall => delegate_compare_to_wrapper!(SymbolSmall, a, b, self),

// None of the object cases should be reachable, they
// should all have been handled by the is_object() branch
// above.
Tag::U64Object
| Tag::I64Object
| Tag::TimepointObject
| Tag::DurationObject
| Tag::U128Object
| Tag::I128Object
| Tag::U256Object
| Tag::I256Object
| Tag::BytesObject
| Tag::StringObject
| Tag::SymbolObject
| Tag::VecObject
| Tag::MapObject
| Tag::ContractExecutableObject
| Tag::AddressObject
| Tag::LedgerKeyNonceObject => unreachable!(),
}
}
greater_or_less => Ok(greater_or_less),
}
}
}
9 changes: 5 additions & 4 deletions soroban-env-common/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub trait EnvBase: Sized + Clone {
fn check_same_env(&self, other: &Self);

/// Used to clone an environment deeply, not just a handle to it.
#[allow(clippy::return_self_not_must_use)]
fn deep_clone(&self) -> Self;

// Helpers for methods that wish to pass Rust lifetime-qualified _slices_
Expand Down Expand Up @@ -160,7 +161,7 @@ pub trait EnvBase: Sized + Clone {

/// Log a formatted debugging message to the debug log (if present), passing
/// a simplified format string (supporting only positional `{}` markers) and
/// a single [RawVal] argument that will be inserted at the marker in the
/// a single [`RawVal`] argument that will be inserted at the marker in the
/// format string.
fn log_static_fmt_val(&self, fmt: &'static str, v: RawVal) -> Result<(), Self::Error>;

Expand All @@ -176,7 +177,7 @@ pub trait EnvBase: Sized + Clone {

/// Log a formatted debugging message to the debug log (if present), passing
/// a simplified format string (supporting only positional `{}` markers) and
/// both a [RawVal] and a string-slice argument, that will each be inserted
/// both a [`RawVal`] and a string-slice argument, that will each be inserted
/// at markers in the format string.
fn log_static_fmt_val_static_str(
&self,
Expand All @@ -187,7 +188,7 @@ pub trait EnvBase: Sized + Clone {

/// Log a formatted debugging message to the debug log (if present), passing
/// a simplified format string (supporting only positional `{}` markers) and
/// both a slice of [RawVal]s and a slice of string-slice argument, that
/// both a slice of [`RawVal`]s and a slice of string-slice argument, that
/// will be sequentially inserted at markers in the format string.
fn log_static_fmt_general(
&self,
Expand Down Expand Up @@ -285,7 +286,7 @@ macro_rules! generate_env_trait {
/// This trait represents the interface between Host and Guest, used by
/// client contract code and implemented (via [Env](crate::Env)) by the host.
/// It consists of functions that take or return only 64-bit values such
/// as [RawVal] or [u64].
/// as [`RawVal`] or [`u64`].
pub trait Env: EnvBase
{
$(
Expand Down
Loading