Skip to content

Commit d8506a6

Browse files
authored
fmt: update rustfmt config (foundry-rs#31)
1 parent bb3d78b commit d8506a6

24 files changed

+278
-318
lines changed

rustfmt.toml

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
reorder_imports = true
2-
imports_granularity = "Crate"
2+
use_field_init_shorthand = true
33
use_small_heuristics = "Max"
4+
5+
# Nightly
6+
max_width = 100
47
comment_width = 100
8+
imports_granularity = "Crate"
59
wrap_comments = true
6-
binop_separator = "Back"
7-
trailing_comma = "Vertical"
8-
trailing_semicolon = false
9-
use_field_init_shorthand = true
10+
format_code_in_doc_comments = true
11+
doc_comment_code_block_width = 100
12+
format_macro_matchers = true

src/artifact_output/configurable.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ pub struct ConfigurableArtifacts {
152152
/// _always_ be done using a public constructor or update syntax:
153153
///
154154
/// ```rust
155-
///
156-
/// use foundry_compilers::{ExtraOutputFiles, ConfigurableArtifacts};
155+
/// use foundry_compilers::{ConfigurableArtifacts, ExtraOutputFiles};
157156
/// let config = ConfigurableArtifacts {
158157
/// additional_files: ExtraOutputFiles { metadata: true, ..Default::default() },
159158
/// ..Default::default()
@@ -395,12 +394,8 @@ pub struct ExtraOutputValues {
395394
/// _always_ be done using a public constructor or update syntax:
396395
///
397396
/// ```rust
398-
///
399397
/// use foundry_compilers::ExtraOutputValues;
400-
/// let config = ExtraOutputValues {
401-
/// ir: true,
402-
/// ..Default::default()
403-
/// };
398+
/// let config = ExtraOutputValues { ir: true, ..Default::default() };
404399
/// ```
405400
#[doc(hidden)]
406401
pub __non_exhaustive: (),
@@ -516,12 +511,8 @@ pub struct ExtraOutputFiles {
516511
/// _always_ be done using a public constructor or update syntax:
517512
///
518513
/// ```rust
519-
///
520514
/// use foundry_compilers::ExtraOutputFiles;
521-
/// let config = ExtraOutputFiles {
522-
/// metadata: true,
523-
/// ..Default::default()
524-
/// };
515+
/// let config = ExtraOutputFiles { metadata: true, ..Default::default() };
525516
/// ```
526517
#[doc(hidden)]
527518
pub __non_exhaustive: (),
@@ -584,8 +575,8 @@ impl ExtraOutputFiles {
584575
EvmOutputSelection::ByteCode(BytecodeOutputSelection::SourceMap) => {
585576
config.source_map = true;
586577
}
587-
EvmOutputSelection::DeployedByteCode(DeployedBytecodeOutputSelection::All) |
588-
EvmOutputSelection::DeployedByteCode(
578+
EvmOutputSelection::DeployedByteCode(DeployedBytecodeOutputSelection::All)
579+
| EvmOutputSelection::DeployedByteCode(
589580
DeployedBytecodeOutputSelection::Object,
590581
) => {
591582
config.deployed_bytecode = true;

src/artifact_output/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ pub trait ArtifactOutput {
709709
let out_path = artifacts_folder.join(&candidate);
710710
if !already_taken.contains(&out_path) {
711711
trace!("found alternative output file={:?} for {:?}", out_path, contract_file);
712-
return out_path
712+
return out_path;
713713
}
714714
current_parent = current_parent.and_then(|f| f.parent());
715715
}
@@ -739,7 +739,7 @@ pub trait ArtifactOutput {
739739
.collect();
740740
if !already_taken.contains(&candidate) {
741741
trace!("found alternative output file={:?} for {:?}", candidate, contract_file);
742-
return candidate
742+
return candidate;
743743
}
744744

745745
num += 1;
@@ -877,8 +877,8 @@ pub trait ArtifactOutput {
877877
// we keep the top most conflicting file unchanged
878878
let is_top_most =
879879
contracts.iter().enumerate().filter(|(i, _)| *i != idx).all(|(_, c)| {
880-
Path::new(file).components().count() <
881-
Path::new(c.file).components().count()
880+
Path::new(file).components().count()
881+
< Path::new(c.file).components().count()
882882
});
883883
if !is_top_most {
884884
// we resolve the conflicting by finding a new unique, alternative path
@@ -922,10 +922,10 @@ pub trait ArtifactOutput {
922922
// source units
923923
// there's also no need to create a standalone artifact for source files that
924924
// don't contain an ast
925-
if source.source_file.contains_contract_definition() ||
926-
source.source_file.ast.is_none()
925+
if source.source_file.contains_contract_definition()
926+
|| source.source_file.ast.is_none()
927927
{
928-
continue
928+
continue;
929929
}
930930

931931
// we use file and file stem

src/artifacts/bytecode.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl CompactBytecode {
7272
address: Address,
7373
) -> bool {
7474
if !self.object.is_unlinked() {
75-
return true
75+
return true;
7676
}
7777

7878
let file = file.as_ref();
@@ -85,7 +85,7 @@ impl CompactBytecode {
8585
self.link_references.insert(key, contracts);
8686
}
8787
if self.link_references.is_empty() {
88-
return self.object.resolve().is_some()
88+
return self.object.resolve().is_some();
8989
}
9090
}
9191
false
@@ -167,7 +167,7 @@ impl Bytecode {
167167
address: Address,
168168
) -> bool {
169169
if !self.object.is_unlinked() {
170-
return true
170+
return true;
171171
}
172172

173173
let file = file.as_ref();
@@ -180,7 +180,7 @@ impl Bytecode {
180180
self.link_references.insert(key, contracts);
181181
}
182182
if self.link_references.is_empty() {
183-
return self.object.resolve().is_some()
183+
return self.object.resolve().is_some();
184184
}
185185
}
186186
false
@@ -195,7 +195,7 @@ impl Bytecode {
195195
{
196196
for (file, lib, addr) in libs.into_iter() {
197197
if self.link(file, lib, addr) {
198-
return true
198+
return true;
199199
}
200200
}
201201
false
@@ -209,7 +209,7 @@ impl Bytecode {
209209
{
210210
for (name, addr) in libs.into_iter() {
211211
if self.link_fully_qualified(name, addr) {
212-
return true
212+
return true;
213213
}
214214
}
215215
false
@@ -362,8 +362,8 @@ impl BytecodeObject {
362362
pub fn contains_fully_qualified_placeholder(&self, name: impl AsRef<str>) -> bool {
363363
if let BytecodeObject::Unlinked(unlinked) = self {
364364
let name = name.as_ref();
365-
unlinked.contains(&utils::library_hash_placeholder(name)) ||
366-
unlinked.contains(&utils::library_fully_qualified_placeholder(name))
365+
unlinked.contains(&utils::library_hash_placeholder(name))
366+
|| unlinked.contains(&utils::library_fully_qualified_placeholder(name))
367367
} else {
368368
false
369369
}

src/artifacts/contract.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ impl ContractBytecode {
8585
/// # Example
8686
///
8787
/// ```
88-
/// use foundry_compilers::Project;
89-
/// use foundry_compilers::artifacts::*;
88+
/// use foundry_compilers::{artifacts::*, Project};
9089
/// # fn demo(project: Project) {
9190
/// let mut output = project.compile().unwrap().output();
9291
/// let contract: ContractBytecode = output.remove_first("Greeter").unwrap().into();
@@ -236,7 +235,7 @@ impl TryFrom<ContractBytecode> for ContractBytecodeSome {
236235

237236
fn try_from(value: ContractBytecode) -> Result<Self, Self::Error> {
238237
if value.abi.is_none() || value.bytecode.is_none() || value.deployed_bytecode.is_none() {
239-
return Err(value)
238+
return Err(value);
240239
}
241240
Ok(value.unwrap())
242241
}
@@ -258,7 +257,7 @@ impl TryFrom<CompactContract> for CompactContractSome {
258257

259258
fn try_from(value: CompactContract) -> Result<Self, Self::Error> {
260259
if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() {
261-
return Err(value)
260+
return Err(value);
262261
}
263262
Ok(value.unwrap())
264263
}
@@ -308,8 +307,7 @@ impl CompactContract {
308307
/// # Example
309308
///
310309
/// ```
311-
/// use foundry_compilers::Project;
312-
/// use foundry_compilers::artifacts::*;
310+
/// use foundry_compilers::{artifacts::*, Project};
313311
/// # fn demo(project: Project) {
314312
/// let mut output = project.compile().unwrap().output();
315313
/// let contract: CompactContract = output.remove_first("Greeter").unwrap().into();
@@ -448,7 +446,7 @@ impl<'a> TryFrom<CompactContractRef<'a>> for CompactContractRefSome<'a> {
448446

449447
fn try_from(value: CompactContractRef<'a>) -> Result<Self, Self::Error> {
450448
if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() {
451-
return Err(value)
449+
return Err(value);
452450
}
453451
Ok(value.unwrap())
454452
}
@@ -494,8 +492,7 @@ impl<'a> CompactContractRef<'a> {
494492
/// # Example
495493
///
496494
/// ```
497-
/// use foundry_compilers::Project;
498-
/// use foundry_compilers::artifacts::*;
495+
/// use foundry_compilers::{artifacts::*, Project};
499496
/// # fn demo(project: Project) {
500497
/// let output = project.compile().unwrap().output();
501498
/// let contract = output.find_first("Greeter").unwrap();

src/artifacts/mod.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ impl Settings {
401401
/// Inserts the value for all files and contracts
402402
///
403403
/// ```
404-
/// use foundry_compilers::artifacts::output_selection::ContractOutputSelection;
405-
/// use foundry_compilers::artifacts::Settings;
404+
/// use foundry_compilers::artifacts::{output_selection::ContractOutputSelection, Settings};
406405
/// let mut selection = Settings::default();
407406
/// selection.push_output_selection(ContractOutputSelection::Metadata);
408407
/// ```
@@ -608,7 +607,7 @@ impl Libraries {
608607
if items.next().is_some() {
609608
return Err(SolcError::msg(format!(
610609
"failed to parse, too many arguments passed: {lib}"
611-
)))
610+
)));
612611
}
613612
libraries
614613
.entry(file.into())
@@ -741,15 +740,15 @@ pub struct OptimizerDetails {
741740
impl OptimizerDetails {
742741
/// Returns true if no settings are set.
743742
pub fn is_empty(&self) -> bool {
744-
self.peephole.is_none() &&
745-
self.inliner.is_none() &&
746-
self.jumpdest_remover.is_none() &&
747-
self.order_literals.is_none() &&
748-
self.deduplicate.is_none() &&
749-
self.cse.is_none() &&
750-
self.constant_optimizer.is_none() &&
751-
self.yul.is_none() &&
752-
self.yul_details.as_ref().map(|yul| yul.is_empty()).unwrap_or(true)
743+
self.peephole.is_none()
744+
&& self.inliner.is_none()
745+
&& self.jumpdest_remover.is_none()
746+
&& self.order_literals.is_none()
747+
&& self.deduplicate.is_none()
748+
&& self.cse.is_none()
749+
&& self.constant_optimizer.is_none()
750+
&& self.yul.is_none()
751+
&& self.yul_details.as_ref().map(|yul| yul.is_empty()).unwrap_or(true)
753752
}
754753
}
755754

@@ -1900,7 +1899,7 @@ impl fmt::Display for Error {
19001899
let msg = self.formatted_message.as_ref().unwrap_or(&self.message);
19011900
self.fmt_severity(f)?;
19021901
f.write_str(": ")?;
1903-
return f.write_str(msg)
1902+
return f.write_str(msg);
19041903
}
19051904

19061905
// Error (XXXX): Error Message
@@ -2029,7 +2028,7 @@ fn fmt_source_location(f: &mut fmt::Formatter, lines: &mut std::str::Lines) -> f
20292028
f.write_str("\n")?;
20302029
f.write_str(line)?;
20312030
}
2032-
return Ok(())
2031+
return Ok(());
20332032
};
20342033

20352034
// line 1, just a frame
@@ -2070,7 +2069,7 @@ fn fmt_framed_location(
20702069
if let Some((space_or_line_number, rest)) = line.split_once('|') {
20712070
// if the potential frame is not just whitespace or numbers, don't color it
20722071
if !space_or_line_number.chars().all(|c| c.is_whitespace() || c.is_numeric()) {
2073-
return f.write_str(line)
2072+
return f.write_str(line);
20742073
}
20752074

20762075
styled(f, Error::frame_style(), |f| {
@@ -2187,7 +2186,7 @@ impl SourceFile {
21872186
pub fn contains_contract_definition(&self) -> bool {
21882187
if let Some(ref ast) = self.ast {
21892188
// contract definitions are only allowed at the source-unit level <https://docs.soliditylang.org/en/latest/grammar.html>
2190-
return ast.nodes.iter().any(|node| node.node_type == NodeType::ContractDefinition)
2189+
return ast.nodes.iter().any(|node| node.node_type == NodeType::ContractDefinition);
21912190
// abstract contract, interfaces: ContractDefinition
21922191
}
21932192

@@ -2204,10 +2203,10 @@ impl SourceFiles {
22042203
/// Returns an iterator over the source files' ids and path
22052204
///
22062205
/// ```
2207-
/// use std::collections::BTreeMap;
22082206
/// use foundry_compilers::artifacts::SourceFiles;
2207+
/// use std::collections::BTreeMap;
22092208
/// # fn demo(files: SourceFiles) {
2210-
/// let sources: BTreeMap<u32,String> = files.into_ids().collect();
2209+
/// let sources: BTreeMap<u32, String> = files.into_ids().collect();
22112210
/// # }
22122211
/// ```
22132212
pub fn into_ids(self) -> impl Iterator<Item = (u32, String)> {
@@ -2217,10 +2216,10 @@ impl SourceFiles {
22172216
/// Returns an iterator over the source files' paths and ids
22182217
///
22192218
/// ```
2220-
/// use std::collections::BTreeMap;
22212219
/// use foundry_compilers::artifacts::SourceFiles;
2220+
/// use std::collections::BTreeMap;
22222221
/// # fn demo(files: SourceFiles) {
2223-
/// let sources :BTreeMap<String, u32> = files.into_paths().collect();
2222+
/// let sources: BTreeMap<String, u32> = files.into_paths().collect();
22242223
/// # }
22252224
/// ```
22262225
pub fn into_paths(self) -> impl Iterator<Item = (String, u32)> {

src/artifacts/output_selection.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ impl FromStr for DeployedBytecodeOutputSelection {
482482
"evm.deployedBytecode.functionDebugData" => {
483483
Ok(DeployedBytecodeOutputSelection::FunctionDebugData)
484484
}
485-
"deployed-code" |
486-
"deployed-bin" |
487-
"runtime-code" |
488-
"runtime-bin" |
489-
"evm.deployedBytecode.object" => Ok(DeployedBytecodeOutputSelection::Object),
485+
"deployed-code"
486+
| "deployed-bin"
487+
| "runtime-code"
488+
| "runtime-bin"
489+
| "evm.deployedBytecode.object" => Ok(DeployedBytecodeOutputSelection::Object),
490490
"evm.deployedBytecode.opcodes" => Ok(DeployedBytecodeOutputSelection::Opcodes),
491491
"evm.deployedBytecode.sourceMap" => Ok(DeployedBytecodeOutputSelection::SourceMap),
492492
"evm.deployedBytecode.linkReferences" => {

src/artifacts/serde_helpers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub mod json_string_opt {
5151
{
5252
if let Some(s) = Option::<String>::deserialize(deserializer)? {
5353
if s.is_empty() {
54-
return Ok(None)
54+
return Ok(None);
5555
}
5656
let value = serde_json::Value::String(s);
5757
serde_json::from_value(value).map_err(de::Error::custom).map(Some)
@@ -88,10 +88,10 @@ pub mod empty_json_object_opt {
8888
{
8989
let json = serde_json::Value::deserialize(deserializer)?;
9090
if json.is_null() {
91-
return Ok(None)
91+
return Ok(None);
9292
}
9393
if json.as_object().map(|obj| obj.is_empty()).unwrap_or_default() {
94-
return Ok(None)
94+
return Ok(None);
9595
}
9696
serde_json::from_value(json).map_err(de::Error::custom).map(Some)
9797
}

0 commit comments

Comments
 (0)