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

Replace rustflags with [lints] #880

Merged
merged 6 commits into from
Mar 5, 2024
Merged
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
38 changes: 0 additions & 38 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,3 @@ debug = true
[profile.release]
incremental = true
lto = true

[build]
# TODO: Replace with [lints]:
# https://github.com/NomicFoundation/slang/issues/837
rustflags = [
# rustc additional warnings:
"-Wunused_crate_dependencies",
"-Wunused_lifetimes",
"-Wunused_macro_rules",
"-Wunused_tuple_struct_fields", # Will be uplifed into `dead_code` (warn-by-default) with https://github.com/rust-lang/rust/pull/118297
"-Wmeta_variable_misuse",
# Rust 2018 idioms that are not yet warn-by-default:
"-Welided_lifetimes_in_paths",
"-Wunused_extern_crates",
"-Wexplicit_outlives_requirements",
# 📎 Lints that are enabled (warn/deny) by default
"-Wclippy::all",
# Cargo
"-Wclippy::cargo", # Warn about Cargo.toml issues, except...
"-Aclippy::multiple_crate_versions", # Not possible to deduplicate, should be done periodically ourselves
# Restriction (optional, neutral lints)
"-Wclippy::exit", # Prefer not `process::exit`ing directly
"-Wclippy::rest_pat_in_fully_bound_structs", # Prefer not to use `..` in fully bound structs
"-Wclippy::verbose_file_reads", # Prefer simpler and more concise `fs::read_to_string`
# Pedantic
"-Wclippy::pedantic", # Warn about pedantic lints, except...
"-Aclippy::implicit_clone", # A lot of false positives, tuned down in Clippy bundled with Rust 1.73
"-Aclippy::match_same_arms", # It's often clearer to have the same arm twice
"-Aclippy::missing_errors_doc", # Most of our code is internal; let's not clutter the docs until...
"-Aclippy::missing_panics_doc", # ... we care about the public documentation in our shipped crates
"-Aclippy::module_name_repetitions", # It seems we prefer it this way; we'd need to discuss that
"-Aclippy::must_use_candidate", # Overzealous, we'd have to `[must_use]` a lot of things
"-Aclippy::redundant_closure_for_method_calls", # Not always clearer, let's not pepper `allow`s whenever needed
# Nursery
"-Wclippy::collection_is_never_read", # Lint against collections not used after creation
"-Wclippy::equatable_if_let", # Prefer regular `==` checks over Yoda `if let $pat = $value`
"-Wclippy::useless_let_if_seq", # Use idiomatic direct assignment of `let $val = if $cond { .. } else { ..};`
]
34 changes: 34 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,37 @@ thiserror = { version = "1.0.57" }
trybuild = { version = "1.0.89" }
toml = { version = "0.7.8" }
url = { version = "2.3.1" }

[workspace.lints.rust]
unused_crate_dependencies = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
meta_variable_misuse = "warn"
# Rust 2018 idioms that are not yet warn-by-default:
elided_lifetimes_in_paths = "warn"
unused_extern_crates = "warn"
explicit_outlives_requirements = "warn"

[workspace.lints.clippy]
# Lints that are enabled (warn/deny) by default
all = "warn"
# Cargo
cargo = "warn" # Warn about Cargo.toml issues, except...
multiple_crate_versions = { level = "allow", priority = 1 } # Not possible to deduplicate, should be done periodically ourselves
# Restriction (optional, neutral lints)
exit = "warn" # Prefer not `process::exit`ing directly
rest_pat_in_fully_bound_structs = "warn" # Prefer not to use `..` in fully bound structs
verbose_file_reads = "warn" # Prefer simpler and more concise `fs::read_to_string`
# Pedantic
pedantic = "warn" # Warn about pedantic lints, except...
match_same_arms = { level = "allow", priority = 1 } # It's often clearer to have the same arm twice
missing_errors_doc = { level = "allow", priority = 1 } # Most of our code is internal; let's not clutter the docs until...
missing_panics_doc = { level = "allow", priority = 1 } # ... we care about the public documentation in our shipped crates
module_name_repetitions = { level = "allow", priority = 1 } # It seems we prefer it this way; we'd need to discuss that
must_use_candidate = { level = "allow", priority = 1 } # Overzealous, we'd have to `[must_use]` a lot of things
redundant_closure_for_method_calls = { level = "allow", priority = 1 } # Not always clearer, let's not pepper `allow`s whenever needed
# Nursery
collection_is_never_read = "warn" # Lint against collections not used after creation
equatable_if_let = "warn" # Prefer regular `==` checks over Yoda `if let $pat = $value`
useless_let_if_seq = "warn" # Use idiomatic direct assignment of `let $val = if $cond { .. } else { .. };`
redundant_else = "warn" # Warn about redundant `else` blocks
4 changes: 4 additions & 0 deletions crates/codegen/ebnf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ codegen_language_definition = { workspace = true }
derive-new = { workspace = true }
indexmap = { workspace = true }
Inflector = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/codegen/grammar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ codegen_language_definition = { workspace = true }
indexmap = { workspace = true }
semver = { workspace = true }
strum_macros = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/codegen/language/definition/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ serde = { workspace = true }
strum_macros = { workspace = true }
syn = { workspace = true }
thiserror = { workspace = true }

[lints]
workspace = true

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn collect_top_level_items(analysis: &mut Analysis) {
}

analysis.metadata.insert(
(**name).to_owned(),
(**name).clone(),
ItemMetadata {
name: name.clone(),
item: item.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn check_reference(
if let Some(source) = source {
analysis.metadata[source]
.referenced_items
.push((**reference).to_owned());
.push((**reference).clone());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl VersionSet {
// there is some overlap:
// make sure 'range' is included in 'from..till', then remove it:
if range.start < from {
from = range.start.to_owned();
from = range.start.clone();
}
if till < range.end {
till = range.end.to_owned();
till = range.end.clone();
}
false
});
Expand Down Expand Up @@ -89,7 +89,7 @@ impl VersionSet {

if first.start < second.start {
// take part of first that exists before second:
ranges.push(first.start.to_owned()..second.start.to_owned());
ranges.push(first.start.clone()..second.start.clone());
}

if first.end <= second.end {
Expand All @@ -99,7 +99,7 @@ impl VersionSet {
}

// keep part of first that exists after second:
first.start = second.end.to_owned();
first.start = second.end.clone();

// advance second, as it's been fully processed:
second_iter.next();
Expand Down
4 changes: 4 additions & 0 deletions crates/codegen/language/internal_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ itertools = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { workspace = true }

[lints]
workspace = true

2 changes: 1 addition & 1 deletion crates/codegen/language/internal_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::input_model::InputItem;
pub fn derive_spanned_type(args: TokenStream, mut input: TokenStream) -> TokenStream {
let spanned_type = {
let spanned_derive_args = args.into();
let input = input.to_owned();
let input = input.clone();

let item = syn::parse_macro_input!(input as InputItem);
derive::spanned(item, spanned_derive_args)
Expand Down
4 changes: 4 additions & 0 deletions crates/codegen/language/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ proc-macro = true

[dependencies]
codegen_language_definition = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/codegen/language/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ infra_utils = { workspace = true }
rayon = { workspace = true }
semver = { workspace = true }
trybuild = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/codegen/parser/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ proc-macro2 = { workspace = true }
quote = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/codegen/parser/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ strum_macros = { workspace = true }
[features]
default = ["slang_napi_interfaces"]
slang_napi_interfaces = ["dep:napi", "dep:napi-derive"]

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/codegen/spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ Inflector = { workspace = true }
infra_utils = { workspace = true }
itertools = { workspace = true }
serde = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/codegen/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ anyhow = { workspace = true }
codegen_language_definition = { workspace = true }
Inflector = { workspace = true }
infra_utils = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/infra/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ semver = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
toml = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/infra/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ serde_json = { workspace = true }
similar-asserts = { workspace = true }
tera = { workspace = true }
toml = { workspace = true }

[lints]
workspace = true

4 changes: 2 additions & 2 deletions crates/infra/utils/src/cargo/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl CargoWorkspace {
.get(crate_name)
.with_context(|| format!("Cannot find dependency '{crate_name}' in workspace."))?
.version
.to_owned()
.clone()
.with_context(|| {
format!("Dependency '{crate_name}' did not specify a version in Cargo.toml.")
})?
Expand All @@ -47,7 +47,7 @@ impl CargoWorkspace {
.get(crate_name)
.with_context(|| format!("Cannot find dependency '{crate_name}' in workspace."))?
.path
.to_owned()
.clone()
.with_context(|| {
format!("Dependency '{crate_name}' did not specify a path in Cargo.toml.")
})?;
Expand Down
2 changes: 1 addition & 1 deletion crates/infra/utils/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Display for Command {
parts.push("&&".to_owned());
}

parts.push(self.name.to_owned());
parts.push(self.name.clone());

for arg in &self.args {
let delimiter = if arg.contains(' ') {
Expand Down
4 changes: 4 additions & 0 deletions crates/solidity/inputs/language/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ publish = false
codegen_language_definition = { workspace = true }
codegen_language_macros = { workspace = true }
semver = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/solidity/outputs/cargo/slang_solidity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ serde_json = { workspace = true, optional = true }
strum = { workspace = true }
strum_macros = { workspace = true }
thiserror = { workspace = true }

[lints]
workspace = true

Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ serde = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }
thiserror = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/solidity/outputs/cargo/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ semver = { workspace = true }
slang_solidity = { workspace = true }
solidity_testing_utils = { workspace = true }
strum_macros = { workspace = true }

[lints]
workspace = true

2 changes: 1 addition & 1 deletion crates/solidity/outputs/cargo/tests/src/trivia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn compare_end_of_lines(input: &str, expected: &[&str]) -> Result<()> {

Node::Token(token) => {
assert_eq!(token.kind, TokenKind::EndOfLine);
Some(token.text.to_owned())
Some(token.text.clone())
}
})
.collect::<Vec<_>>();
Expand Down
4 changes: 4 additions & 0 deletions crates/solidity/outputs/npm/package/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ anyhow = { workspace = true }
codegen_parser_generator = { workspace = true }
infra_utils = { workspace = true }
solidity_language = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/solidity/outputs/spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ anyhow = { workspace = true }
codegen_spec = { workspace = true }
infra_utils = { workspace = true }
solidity_language = { workspace = true }

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/solidity/testing/sanctuary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ serde_json = { workspace = true }
slang_solidity = { workspace = true }
strum_macros = { workspace = true }
url = { workspace = true }

[lints]
workspace = true

2 changes: 1 addition & 1 deletion crates/solidity/testing/sanctuary/src/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn list_contracts(repo_dir: &Path, network: &str) -> Result<BTreeMap<String, Vec
.or_insert_with(Vec::new)
.push(SourceFile {
path,
compiler: compiler.to_owned(),
compiler: compiler.clone(),
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/solidity/testing/sanctuary/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn run_test(file: &SourceFile, events: &Events) -> Result<()> {
// https://github.com/tintinweb/smart-contract-sanctuary/issues/31
.replace("[email protected]", "[email-protected]");

let language = Language::new(version.to_owned())?;
let language = Language::new(version.clone())?;
let output = language.parse(RuleKind::SourceUnit, &source);

if output.is_valid() {
Expand Down
4 changes: 4 additions & 0 deletions crates/solidity/testing/snapshots/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ version.workspace = true
rust-version.workspace = true
edition.workspace = true
publish = false

[lints]
workspace = true

4 changes: 4 additions & 0 deletions crates/solidity/testing/solc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ serde_json = { workspace = true }
solidity_language = { workspace = true }
strum_macros = { workspace = true }
url = { workspace = true }

[lints]
workspace = true

4 changes: 2 additions & 2 deletions crates/solidity/testing/solc/src/commands/dissect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl DissectCommand {
let language = SolidityDefinition::create();
let binaries = Binary::fetch_all(&language)?;

let mut dissector = Dissector::new(self.file.to_owned())?;
let mut dissector = Dissector::new(self.file.clone())?;

for binary in binaries {
dissector.inspect_version(&binary)?;
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Dissector {
sources: [(
self.file.unwrap_string(),
InputSource {
content: self.source.to_owned(),
content: self.source.clone(),
},
)]
.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl KeywordVersioningCommand {

for variation in variations {
assert!(
already_seen.insert((&item.identifier, variation.to_owned())),
already_seen.insert((&item.identifier, variation.clone())),
"Duplicate variation: {variation}"
);

Expand Down Expand Up @@ -245,7 +245,7 @@ impl TestCase {
sources: [(
"input.sol".into(),
InputSource {
content: self.source.to_owned(),
content: self.source.clone(),
},
)]
.into(),
Expand Down
Loading