Skip to content

Commit

Permalink
chore: enable some lints (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jan 30, 2024
1 parent dbb5df0 commit bd3dd65
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 56 deletions.
28 changes: 14 additions & 14 deletions src/artifact_output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,15 @@ pub trait Artifact {

/// Returns the reference of container type for abi, compact bytecode and deployed bytecode if
/// available
fn get_contract_bytecode(&self) -> CompactContractBytecodeCow;
fn get_contract_bytecode(&self) -> CompactContractBytecodeCow<'_>;

/// Returns the reference to the `bytecode`
fn get_bytecode(&self) -> Option<Cow<CompactBytecode>> {
fn get_bytecode(&self) -> Option<Cow<'_, CompactBytecode>> {
self.get_contract_bytecode().bytecode
}

/// Returns the reference to the `bytecode` object
fn get_bytecode_object(&self) -> Option<Cow<BytecodeObject>> {
fn get_bytecode_object(&self) -> Option<Cow<'_, BytecodeObject>> {
let val = match self.get_bytecode()? {
Cow::Borrowed(b) => Cow::Borrowed(&b.object),
Cow::Owned(b) => Cow::Owned(b.object),
Expand All @@ -491,7 +491,7 @@ pub trait Artifact {
}

/// Returns the bytes of the `bytecode` object
fn get_bytecode_bytes(&self) -> Option<Cow<Bytes>> {
fn get_bytecode_bytes(&self) -> Option<Cow<'_, Bytes>> {
let val = match self.get_bytecode_object()? {
Cow::Borrowed(b) => Cow::Borrowed(b.as_bytes()?),
Cow::Owned(b) => Cow::Owned(b.into_bytes()?),
Expand All @@ -500,12 +500,12 @@ pub trait Artifact {
}

/// Returns the reference to the `deployedBytecode`
fn get_deployed_bytecode(&self) -> Option<Cow<CompactDeployedBytecode>> {
fn get_deployed_bytecode(&self) -> Option<Cow<'_, CompactDeployedBytecode>> {
self.get_contract_bytecode().deployed_bytecode
}

/// Returns the reference to the `bytecode` object
fn get_deployed_bytecode_object(&self) -> Option<Cow<BytecodeObject>> {
fn get_deployed_bytecode_object(&self) -> Option<Cow<'_, BytecodeObject>> {
let val = match self.get_deployed_bytecode()? {
Cow::Borrowed(b) => Cow::Borrowed(&b.bytecode.as_ref()?.object),
Cow::Owned(b) => Cow::Owned(b.bytecode?.object),
Expand All @@ -514,7 +514,7 @@ pub trait Artifact {
}

/// Returns the bytes of the `deployed bytecode` object
fn get_deployed_bytecode_bytes(&self) -> Option<Cow<Bytes>> {
fn get_deployed_bytecode_bytes(&self) -> Option<Cow<'_, Bytes>> {
let val = match self.get_deployed_bytecode_object()? {
Cow::Borrowed(b) => Cow::Borrowed(b.as_bytes()?),
Cow::Owned(b) => Cow::Owned(b.into_bytes()?),
Expand All @@ -523,7 +523,7 @@ pub trait Artifact {
}

/// Returns the reference to the [JsonAbi] if available
fn get_abi(&self) -> Option<Cow<JsonAbi>> {
fn get_abi(&self) -> Option<Cow<'_, JsonAbi>> {
self.get_contract_bytecode().abi
}

Expand All @@ -536,7 +536,7 @@ pub trait Artifact {
}

/// Returns the creation bytecode `sourceMap` as str if it was included in the compiler output
fn get_source_map_str(&self) -> Option<Cow<str>> {
fn get_source_map_str(&self) -> Option<Cow<'_, str>> {
match self.get_bytecode()? {
Cow::Borrowed(code) => code.source_map.as_deref().map(Cow::Borrowed),
Cow::Owned(code) => code.source_map.map(Cow::Owned),
Expand All @@ -552,7 +552,7 @@ pub trait Artifact {
}

/// Returns the runtime bytecode `sourceMap` as str if it was included in the compiler output
fn get_source_map_deployed_str(&self) -> Option<Cow<str>> {
fn get_source_map_deployed_str(&self) -> Option<Cow<'_, str>> {
match self.get_bytecode()? {
Cow::Borrowed(code) => code.source_map.as_deref().map(Cow::Borrowed),
Cow::Owned(code) => code.source_map.map(Cow::Owned),
Expand Down Expand Up @@ -582,7 +582,7 @@ where
self.into_compact_contract().into_parts()
}

fn get_contract_bytecode(&self) -> CompactContractBytecodeCow {
fn get_contract_bytecode(&self) -> CompactContractBytecodeCow<'_> {
self.into()
}
}
Expand Down Expand Up @@ -612,7 +612,7 @@ pub trait ArtifactOutput {
contracts: &VersionedContracts,
sources: &VersionedSourceFiles,
layout: &ProjectPathsConfig,
ctx: OutputContext,
ctx: OutputContext<'_>,
) -> Result<Artifacts<Self::Artifact>> {
let mut artifacts = self.output_to_artifacts(contracts, sources, ctx, layout);
fs::create_dir_all(&layout.artifacts).map_err(|err| {
Expand Down Expand Up @@ -842,7 +842,7 @@ pub trait ArtifactOutput {
&self,
contracts: &VersionedContracts,
sources: &VersionedSourceFiles,
ctx: OutputContext,
ctx: OutputContext<'_>,
layout: &ProjectPathsConfig,
) -> Artifacts<Self::Artifact> {
let mut artifacts = ArtifactsMap::new();
Expand Down Expand Up @@ -1079,7 +1079,7 @@ impl ArtifactOutput for MinimalCombinedArtifactsHardhatFallback {
output: &VersionedContracts,
sources: &VersionedSourceFiles,
layout: &ProjectPathsConfig,
ctx: OutputContext,
ctx: OutputContext<'_>,
) -> Result<Artifacts<Self::Artifact>> {
MinimalCombinedArtifacts::default().on_output(output, sources, layout, ctx)
}
Expand Down
12 changes: 6 additions & 6 deletions src/artifacts/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Error {
/// ```text
/// Error (XXXX)
/// ```
fn fmt_severity(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_severity(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.severity.as_str())?;
if let Some(code) = self.error_code {
write!(f, " ({code})")?;
Expand All @@ -206,17 +206,17 @@ impl Error {
}

/// Calls `fun` in between [`Style::fmt_prefix`] and [`Style::fmt_suffix`].
fn styled<F>(f: &mut fmt::Formatter, style: Style, fun: F) -> fmt::Result
fn styled<F>(f: &mut fmt::Formatter<'_>, style: Style, fun: F) -> fmt::Result
where
F: FnOnce(&mut fmt::Formatter) -> fmt::Result,
F: FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result,
{
style.fmt_prefix(f)?;
fun(f)?;
style.fmt_suffix(f)
}

/// Formats the diagnostic message.
fn fmt_msg(f: &mut fmt::Formatter, msg: &str) -> fmt::Result {
fn fmt_msg(f: &mut fmt::Formatter<'_>, msg: &str) -> fmt::Result {
styled(f, Error::message_style(), |f| {
f.write_str(": ")?;
f.write_str(msg.trim_start())
Expand All @@ -231,7 +231,7 @@ fn fmt_msg(f: &mut fmt::Formatter, msg: &str) -> fmt::Result {
/// 420 | bad_code()
/// | ^
/// ```
fn fmt_source_location(f: &mut fmt::Formatter, lines: &mut std::str::Lines) -> fmt::Result {
fn fmt_source_location(f: &mut fmt::Formatter<'_>, lines: &mut std::str::Lines<'_>) -> fmt::Result {
// --> source
if let Some(line) = lines.next() {
f.write_str("\n")?;
Expand Down Expand Up @@ -292,7 +292,7 @@ fn fmt_source_location(f: &mut fmt::Formatter, lines: &mut std::str::Lines) -> f

/// Colors a single Solidity framed source location line. Part of [`fmt_source_location`].
fn fmt_framed_location(
f: &mut fmt::Formatter,
f: &mut fmt::Formatter<'_>,
line: &str,
highlight: Option<(Range<usize>, Style)>,
) -> fmt::Result {
Expand Down
14 changes: 7 additions & 7 deletions src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,20 @@ impl Settings {
.insert(key.into(), values.into_iter().map(|s| s.to_string()).collect());
}

/// Sets the ``viaIR` valu
/// Sets the `viaIR` value.
#[must_use]
pub fn set_via_ir(mut self, via_ir: bool) -> Self {
self.via_ir = Some(via_ir);
self
}

/// Enables `viaIR`
/// Enables `viaIR`.
#[must_use]
pub fn with_via_ir(self) -> Self {
self.set_via_ir(true)
}

/// Enable `viaIR` and use the minimum optimization settings
/// Enable `viaIR` and use the minimum optimization settings.
///
/// This is useful in the following scenarios:
/// - When compiling for test coverage, this can resolve the "stack too deep" error while still
Expand Down Expand Up @@ -574,7 +574,7 @@ impl Default for Settings {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(transparent)]
pub struct Libraries {
/// All libraries, `(file path -> (Lib name -> Address))
/// All libraries, `(file path -> (Lib name -> Address))`.
pub libs: BTreeMap<PathBuf, BTreeMap<String, String>>,
}

Expand Down Expand Up @@ -1581,7 +1581,7 @@ impl CompilerOutput {
}

/// Finds the _first_ contract with the given name
pub fn find(&self, contract: impl AsRef<str>) -> Option<CompactContractRef> {
pub fn find(&self, contract: impl AsRef<str>) -> Option<CompactContractRef<'_>> {
let contract_name = contract.as_ref();
self.contracts_iter().find_map(|(name, contract)| {
(name == contract_name).then(|| CompactContractRef::from(contract))
Expand All @@ -1606,7 +1606,7 @@ impl CompilerOutput {

/// Given the contract file's path and the contract's name, tries to return the contract's
/// bytecode, runtime bytecode, and abi
pub fn get(&self, path: &str, contract: &str) -> Option<CompactContractRef> {
pub fn get(&self, path: &str, contract: &str) -> Option<CompactContractRef<'_>> {
self.contracts
.get(path)
.and_then(|contracts| contracts.get(contract))
Expand Down Expand Up @@ -1656,7 +1656,7 @@ impl OutputContracts {
}

/// Finds the _first_ contract with the given name
pub fn find(&self, contract: impl AsRef<str>) -> Option<CompactContractRef> {
pub fn find(&self, contract: impl AsRef<str>) -> Option<CompactContractRef<'_>> {
let contract_name = contract.as_ref();
self.contracts_iter().find_map(|(name, contract)| {
(name == contract_name).then(|| CompactContractRef::from(contract))
Expand Down
2 changes: 1 addition & 1 deletion src/artifacts/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub mod tuple_vec_map {
{
type Value = Vec<(K, V)>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a map")
}

Expand Down
2 changes: 1 addition & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ impl<'a, T: ArtifactOutput> ArtifactsCache<'a, T> {
}
}

pub fn output_ctx(&self) -> OutputContext {
pub fn output_ctx(&self) -> OutputContext<'_> {
match self {
ArtifactsCache::Ephemeral(_, _) => Default::default(),
ArtifactsCache::Cached(inner) => OutputContext::new(&inner.cache),
Expand Down
10 changes: 5 additions & 5 deletions src/compile/output/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl VersionedContracts {
/// The `ctx` is used to avoid possible conflicts
pub(crate) fn artifact_files<T: ArtifactOutput + ?Sized>(
&self,
ctx: &OutputContext,
) -> MappedArtifactFiles {
ctx: &OutputContext<'_>,
) -> MappedArtifactFiles<'_> {
let mut output_files = MappedArtifactFiles::with_capacity(self.len());
for (file, contracts) in self.iter() {
for (name, versioned_contracts) in contracts {
Expand Down Expand Up @@ -105,7 +105,7 @@ impl VersionedContracts {
/// let contract = output.find_first("Greeter").unwrap();
/// # Ok::<_, Box<dyn std::error::Error>>(())
/// ```
pub fn find_first(&self, contract: impl AsRef<str>) -> Option<CompactContractRef> {
pub fn find_first(&self, contract: impl AsRef<str>) -> Option<CompactContractRef<'_>> {
let contract_name = contract.as_ref();
self.contracts().find_map(|(name, contract)| {
(name == contract_name).then(|| CompactContractRef::from(contract))
Expand All @@ -128,7 +128,7 @@ impl VersionedContracts {
&self,
path: impl AsRef<str>,
contract: impl AsRef<str>,
) -> Option<CompactContractRef> {
) -> Option<CompactContractRef<'_>> {
let contract_path = path.as_ref();
let contract_name = contract.as_ref();
self.contracts_with_files().find_map(|(path, name, contract)| {
Expand Down Expand Up @@ -202,7 +202,7 @@ impl VersionedContracts {
&self,
path: impl AsRef<str>,
contract: impl AsRef<str>,
) -> Option<CompactContractRef> {
) -> Option<CompactContractRef<'_>> {
let contract = contract.as_ref();
self.0
.get(path.as_ref())
Expand Down
6 changes: 3 additions & 3 deletions src/compile/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl AggregatedCompilerOutput {
&'a self,
ignored_error_codes: &'a [u64],
compiler_severity_filter: Severity,
) -> OutputDiagnostics {
) -> OutputDiagnostics<'a> {
OutputDiagnostics { compiler_output: self, ignored_error_codes, compiler_severity_filter }
}

Expand Down Expand Up @@ -598,7 +598,7 @@ impl AggregatedCompilerOutput {
/// let contract = output.find_first("Greeter").unwrap();
/// # Ok::<_, Box<dyn std::error::Error>>(())
/// ```
pub fn find_first(&self, contract: impl AsRef<str>) -> Option<CompactContractRef> {
pub fn find_first(&self, contract: impl AsRef<str>) -> Option<CompactContractRef<'_>> {
self.contracts.find_first(contract)
}

Expand Down Expand Up @@ -716,7 +716,7 @@ impl AggregatedCompilerOutput {
&self,
path: impl AsRef<str>,
contract: impl AsRef<str>,
) -> Option<CompactContractRef> {
) -> Option<CompactContractRef<'_>> {
self.contracts.get(path, contract)
}

Expand Down
7 changes: 5 additions & 2 deletions src/compile/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,13 @@ impl CompilerSources {
}
}
/// Filters out all sources that don't need to be compiled, see [`ArtifactsCache::filter`]
fn filtered<T: ArtifactOutput>(self, cache: &mut ArtifactsCache<T>) -> FilteredCompilerSources {
fn filtered<T: ArtifactOutput>(
self,
cache: &mut ArtifactsCache<'_, T>,
) -> FilteredCompilerSources {
fn filtered_sources<T: ArtifactOutput>(
sources: VersionedSources,
cache: &mut ArtifactsCache<T>,
cache: &mut ArtifactsCache<'_, T>,
) -> VersionedFilteredSources {
// fill all content hashes first so they're available for all source sets
sources.iter().for_each(|(_, (_, sources))| {
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ impl From<SolcConfig> for Settings {
pub struct SolcConfigBuilder {
settings: Option<Settings>,

/// additionally selected outputs that should be included in the `Contract` that `solc´ creates
/// additionally selected outputs that should be included in the `Contract` that solc creates.
output_selection: Vec<ContractOutputSelection>,
}

Expand Down
2 changes: 1 addition & 1 deletion src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Flattener {
updates: Updates,
target_pragmas: Vec<&'a str>,
target_license: Option<&'a str>,
) -> FlatteningResult {
) -> FlatteningResult<'_> {
FlatteningResult::new(self, updates, target_pragmas, target_license)
}

Expand Down
17 changes: 5 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#![doc = include_str!("../README.md")]
// #![warn(
// missing_copy_implementations,
// missing_debug_implementations,
// missing_docs,
// unreachable_pub,
// clippy::missing_const_for_fn,
// rustdoc::all
// )]
// #![cfg_attr(not(test), warn(unused_crate_dependencies))]
// #![deny(unused_must_use, rust_2018_idioms)]
#![warn(rustdoc::all)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

#[macro_use]
Expand Down Expand Up @@ -873,7 +866,7 @@ impl<T: ArtifactOutput> ArtifactOutput for Project<T> {
contracts: &VersionedContracts,
sources: &VersionedSourceFiles,
layout: &ProjectPathsConfig,
ctx: OutputContext,
ctx: OutputContext<'_>,
) -> Result<Artifacts<Self::Artifact>> {
self.artifacts_handler().on_output(contracts, sources, layout, ctx)
}
Expand Down Expand Up @@ -948,7 +941,7 @@ impl<T: ArtifactOutput> ArtifactOutput for Project<T> {
&self,
contracts: &VersionedContracts,
sources: &VersionedSourceFiles,
ctx: OutputContext,
ctx: OutputContext<'_>,
layout: &ProjectPathsConfig,
) -> Artifacts<Self::Artifact> {
self.artifacts_handler().output_to_artifacts(contracts, sources, ctx, layout)
Expand Down
2 changes: 1 addition & 1 deletion src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl Graph {
&self.nodes[index]
}

pub(crate) fn display_node(&self, index: usize) -> DisplayNode {
pub(crate) fn display_node(&self, index: usize) -> DisplayNode<'_> {
DisplayNode { node: self.node(index), root: &self.root }
}

Expand Down
Loading

0 comments on commit bd3dd65

Please sign in to comment.