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

Fix new lints from the latest clippy #696

Merged
merged 4 commits into from
Jan 24, 2022
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
27 changes: 16 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
image: ghcr.io/fuellabs/fuel-core:v0.2.1
ports:
- 4000:4000

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
Expand Down Expand Up @@ -59,6 +59,11 @@ jobs:
RUSTFLAGS: "-D warnings"

- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test

- name: Run test crate
uses: actions-rs/cargo@v1
with:
command: run
Expand Down Expand Up @@ -95,7 +100,7 @@ jobs:
with:
publish-delay: 30000
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

build-publish-master-image:
needs: build
if: github.ref == 'refs/heads/master'
Expand All @@ -107,7 +112,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
Expand All @@ -123,14 +128,14 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to the ghcr.io registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push the image to ghcr.io
uses: docker/build-push-action@v2
with:
Expand All @@ -140,8 +145,8 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max

build-publish-release-image:
# Build & Publish Docker Image Per Sway Release
needs: publish
Expand All @@ -153,7 +158,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
Expand All @@ -162,17 +167,17 @@ jobs:
ghcr.io/fuellabs/sway
tags: |
type=semver,pattern={{raw}}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to the ghcr.io registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push the image to ghcr.io
uses: docker/build-push-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clippy_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
uses: actions-rs/clippy-check@v1.0.7
with:
token: ${{ github.token }}
args: --all-features -- -D warnings
args: --all-features --all-targets -- -D warnings
7 changes: 2 additions & 5 deletions forc/src/ops/forc_dep_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ async fn check_tagged_dependency(
if current_release.ne(&latest) {
println!(
"[{}] not up-to-date. Current version: {}, latest: {}",
dependency_name,
current_release.to_string(),
latest.to_string()
dependency_name, current_release, latest
);
} else {
println!(
"[{}] up-to-date. Current version: {}",
dependency_name,
current_release.to_string(),
dependency_name, current_release,
);
}

Expand Down
4 changes: 2 additions & 2 deletions forc/src/ops/forc_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ name = "Fuel example project"


[dependencies]
core = {git="http://github.com/FuelLabs/sway-lib-core"}
Dentosal marked this conversation as resolved.
Show resolved Hide resolved
std = { git = "http://github.com/FuelLabs/sway-lib-std" }
core = {git="http://github.com/FuelLabs/sway-lib-core",version="v0.0.1"}
std = { git = "http://github.com/FuelLabs/sway-lib-std" , version = "v0.0.1" }
"#;
let formatted_content = taplo_fmt::format(whitespace_forc_manifest, taplo_alphabetize);
assert_eq!(formatted_content, correct_forc_manifest);
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/asm_generation/from_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ mod tests {
Some("asm") | Some("disabled") => (),
_ => panic!(
"File with invalid extension in tests dir: {:?}",
path.file_name().unwrap_or(path.as_os_str())
path.file_name().unwrap_or_else(|| path.as_os_str())
),
}
}
Expand Down Expand Up @@ -1396,7 +1396,7 @@ mod tests {
let asm_script = format!("{}", asm);
if asm_script != expected {
println!("{}", prettydiff::diff_lines(&expected, &asm_script));
assert!(false);
panic!();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/control_flow_analysis/flow_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ impl std::fmt::Debug for ControlFlowGraphNode {
ControlFlowGraphNode::OrganizationalDominator(s) => s.to_string(),
ControlFlowGraphNode::ProgramNode(node) => format!("{:?}", node),
ControlFlowGraphNode::EnumVariant { variant_name, .. } => {
format!("Enum variant {}", variant_name.to_string())
format!("Enum variant {}", variant_name)
}
ControlFlowGraphNode::MethodDeclaration { method_name, .. } => {
format!("Method {}", method_name.as_str().to_string())
format!("Method {}", method_name.as_str())
}
ControlFlowGraphNode::StructField {
struct_field_name, ..
} => {
format!("Struct field {}", struct_field_name.as_str().to_string())
format!("Struct field {}", struct_field_name.as_str())
}
};
f.write_str(&text)
Expand Down
7 changes: 3 additions & 4 deletions sway-core/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,7 @@ impl FnCompiler {
if let Some(ptr) = self
.symbol_map
.get(name)
.map(|local_name| self.function.get_local_ptr(context, local_name))
.flatten()
.and_then(|local_name| self.function.get_local_ptr(context, local_name))
{
Ok(if ptr.is_struct_ptr(context) {
self.current_block.ins(context).get_ptr(ptr)
Expand Down Expand Up @@ -1489,7 +1488,7 @@ mod tests {
Some("ir") | Some("disabled") => (),
_ => panic!(
"File with invalid extension in tests dir: {:?}",
path.file_name().unwrap_or(path.as_os_str())
path.file_name().unwrap_or_else(|| path.as_os_str())
),
}
}
Expand Down Expand Up @@ -1534,7 +1533,7 @@ mod tests {
Some("sw") | Some("disabled") => (),
_ => panic!(
"File with invalid extension in tests dir: {:?}",
path.file_name().unwrap_or(path.as_os_str())
path.file_name().unwrap_or_else(|| path.as_os_str())
),
}
}
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/parse_tree/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Literal {
Rule::u8_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U8)
.map_err(|e| {
Expand All @@ -78,7 +78,7 @@ impl Literal {
Rule::u16_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U16)
.map_err(|e| {
Expand All @@ -92,7 +92,7 @@ impl Literal {
Rule::u32_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U32)
.map_err(|e| {
Expand All @@ -106,7 +106,7 @@ impl Literal {
Rule::u64_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U64)
.map_err(|e| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ impl TypedExpression {
let enum_name = enum_name[0].clone();
let namespace = namespace.find_module_relative(module_path);
let namespace = namespace.ok(&mut warnings, &mut errors);
namespace.map(|ns| ns.find_enum(&enum_name)).flatten()
namespace.and_then(|ns| ns.find_enum(&enum_name))
};

// now we can see if this thing is a symbol (typed declaration) or reference to an
Expand Down Expand Up @@ -1644,7 +1644,7 @@ impl TypedExpression {
let enum_name = enum_name[0].clone();
let namespace = namespace.find_module_relative(module_path);
let namespace = namespace.ok(&mut warnings, &mut errors);
namespace.map(|ns| ns.find_enum(&enum_name)).flatten()
namespace.and_then(|ns| ns.find_enum(&enum_name))
};
let mut return_type = None;
let mut owned_enum_variant = None;
Expand Down Expand Up @@ -1794,7 +1794,7 @@ mod tests {
use super::*;

fn do_type_check(expr: Expression, type_annotation: TypeId) -> CompileResult<TypedExpression> {
let mut namespace = create_module();
let namespace = create_module();
let self_type = insert_type(TypeInfo::Unknown);
let build_config = BuildConfig {
file_name: Arc::new("test.sw".into()),
Expand Down
19 changes: 8 additions & 11 deletions sway-core/src/semantic_analysis/node_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,14 @@ fn find_recursive_call_chain(
))
};
}
decl_dependencies
.get(fn_sym)
.map(|deps_set| {
chain.push(fn_sym_ident.clone());
let result = deps_set.deps.iter().find_map(|dep_sym| {
find_recursive_call_chain(decl_dependencies, dep_sym, fn_span, chain)
});
chain.pop();
result
})
.flatten()
decl_dependencies.get(fn_sym).and_then(|deps_set| {
chain.push(fn_sym_ident.clone());
let result = deps_set.deps.iter().find_map(|dep_sym| {
find_recursive_call_chain(decl_dependencies, dep_sym, fn_span, chain)
});
chain.pop();
result
})
} else {
None
}
Expand Down
20 changes: 10 additions & 10 deletions sway-core/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn camel_case_split_words(ident: &str) -> impl Iterator<Item = &str> {
if ident.is_empty() {
return None;
}
let index = find_camel_case_word_boundary(ident).unwrap_or_else(|| ident.len());
let index = find_camel_case_word_boundary(ident).unwrap_or(ident.len());
let word = &ident[..index];
ident = &ident[index..];
Some(word)
Expand All @@ -27,7 +27,7 @@ fn camel_case_split_words(ident: &str) -> impl Iterator<Item = &str> {

/// Split an identifier of unknown style into words.
fn split_words(ident: &str) -> impl Iterator<Item = &str> {
ident.split('_').map(camel_case_split_words).flatten()
ident.split('_').flat_map(camel_case_split_words)
}

/// Detect whether an identifier is written in snake_case.
Expand Down Expand Up @@ -72,14 +72,14 @@ pub fn to_snake_case(ident: &str) -> String {
let mut ret = String::with_capacity(ident.len());

let (leading_underscores, trimmed) =
ident.split_at(ident.find(|c| c != '_').unwrap_or_else(|| ident.len()));
ident.split_at(ident.find(|c| c != '_').unwrap_or(ident.len()));
ret.push_str(leading_underscores);
let mut words = split_words(trimmed);
if let Some(word) = words.next() {
ret.extend(word.chars().map(char::to_lowercase).flatten());
ret.extend(word.chars().flat_map(char::to_lowercase));
for word in words {
ret.push('_');
ret.extend(word.chars().map(char::to_lowercase).flatten());
ret.extend(word.chars().flat_map(char::to_lowercase));
}
}
ret
Expand All @@ -91,14 +91,14 @@ pub fn to_screaming_snake_case(ident: &str) -> String {
let mut ret = String::with_capacity(ident.len());

let (leading_underscores, trimmed) =
ident.split_at(ident.find(|c| c != '_').unwrap_or_else(|| ident.len()));
ident.split_at(ident.find(|c| c != '_').unwrap_or(ident.len()));
ret.push_str(leading_underscores);
let mut words = split_words(trimmed);
if let Some(word) = words.next() {
ret.extend(word.chars().map(char::to_uppercase).flatten());
ret.extend(word.chars().flat_map(char::to_uppercase));
for word in words {
ret.push('_');
ret.extend(word.chars().map(char::to_uppercase).flatten());
ret.extend(word.chars().flat_map(char::to_uppercase));
}
}
ret
Expand All @@ -110,13 +110,13 @@ pub fn to_upper_camel_case(ident: &str) -> String {
let mut ret = String::with_capacity(ident.len());

let (leading_underscores, trimmed) =
ident.split_at(ident.find(|c| c != '_').unwrap_or_else(|| ident.len()));
ident.split_at(ident.find(|c| c != '_').unwrap_or(ident.len()));
ret.push_str(leading_underscores);
for word in split_words(trimmed) {
let mut chars = word.chars();
if let Some(c) = chars.next() {
ret.extend(c.to_uppercase());
ret.extend(chars.map(char::to_lowercase).flatten());
ret.extend(chars.flat_map(char::to_lowercase));
}
}
ret
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/type_engine/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl TypeInfo {
array_elem_count_pair
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse::<usize>()
// Could probably just .unwrap() here since it will succeed.
.map_or_else(
Expand Down
20 changes: 8 additions & 12 deletions sway-ir/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,14 @@ impl Block {
///
/// Returns `None` if block is empty.
pub fn get_term_inst<'a>(&self, context: &'a Context) -> Option<&'a Instruction> {
context.blocks[self.0]
.instructions
.last()
.map(|val| {
// It's guaranteed to be an instruction value.
if let ValueContent::Instruction(term_inst) = &context.values[val.0] {
Some(term_inst)
} else {
None
}
})
.flatten()
context.blocks[self.0].instructions.last().and_then(|val| {
// It's guaranteed to be an instruction value.
if let ValueContent::Instruction(term_inst) = &context.values[val.0] {
Some(term_inst)
} else {
None
}
})
}

/// Replace a value within this block.
Expand Down
Loading