diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8010f8446e4..cb458b94d3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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' @@ -107,7 +112,7 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v2 - + - name: Docker meta id: meta uses: docker/metadata-action@v3 @@ -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: @@ -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 @@ -153,7 +158,7 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v2 - + - name: Docker meta id: meta uses: docker/metadata-action@v3 @@ -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: diff --git a/.github/workflows/clippy_check.yml b/.github/workflows/clippy_check.yml index 2ed7dcd5685..5e887919d14 100644 --- a/.github/workflows/clippy_check.yml +++ b/.github/workflows/clippy_check.yml @@ -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 diff --git a/forc/src/ops/forc_dep_check.rs b/forc/src/ops/forc_dep_check.rs index 54d47df7a0c..ab1a6aed337 100644 --- a/forc/src/ops/forc_dep_check.rs +++ b/forc/src/ops/forc_dep_check.rs @@ -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, ); } diff --git a/forc/src/ops/forc_fmt.rs b/forc/src/ops/forc_fmt.rs index 67da5a44206..647d654d559 100644 --- a/forc/src/ops/forc_fmt.rs +++ b/forc/src/ops/forc_fmt.rs @@ -222,8 +222,8 @@ name = "Fuel example project" [dependencies] -core = {git="http://github.com/FuelLabs/sway-lib-core"} -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); diff --git a/sway-core/src/asm_generation/from_ir.rs b/sway-core/src/asm_generation/from_ir.rs index 01e789b10c9..029bb217403 100644 --- a/sway-core/src/asm_generation/from_ir.rs +++ b/sway-core/src/asm_generation/from_ir.rs @@ -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()) ), } } @@ -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!(); } } } diff --git a/sway-core/src/control_flow_analysis/flow_graph/mod.rs b/sway-core/src/control_flow_analysis/flow_graph/mod.rs index d8bf3ffddc5..4e419551556 100644 --- a/sway-core/src/control_flow_analysis/flow_graph/mod.rs +++ b/sway-core/src/control_flow_analysis/flow_graph/mod.rs @@ -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) diff --git a/sway-core/src/optimize.rs b/sway-core/src/optimize.rs index 30b805fc8ee..d55717e5c8e 100644 --- a/sway-core/src/optimize.rs +++ b/sway-core/src/optimize.rs @@ -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) @@ -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()) ), } } @@ -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()) ), } } diff --git a/sway-core/src/parse_tree/literal.rs b/sway-core/src/parse_tree/literal.rs index 87a2c875c5e..9cf8823024b 100644 --- a/sway-core/src/parse_tree/literal.rs +++ b/sway-core/src/parse_tree/literal.rs @@ -64,7 +64,7 @@ impl Literal { Rule::u8_integer => int_inner .as_str() .trim() - .replace("_", "") + .replace('_', "") .parse() .map(Literal::U8) .map_err(|e| { @@ -78,7 +78,7 @@ impl Literal { Rule::u16_integer => int_inner .as_str() .trim() - .replace("_", "") + .replace('_', "") .parse() .map(Literal::U16) .map_err(|e| { @@ -92,7 +92,7 @@ impl Literal { Rule::u32_integer => int_inner .as_str() .trim() - .replace("_", "") + .replace('_', "") .parse() .map(Literal::U32) .map_err(|e| { @@ -106,7 +106,7 @@ impl Literal { Rule::u64_integer => int_inner .as_str() .trim() - .replace("_", "") + .replace('_', "") .parse() .map(Literal::U64) .map_err(|e| { diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs index c6923812641..d195300dab1 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs @@ -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 @@ -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; @@ -1794,7 +1794,7 @@ mod tests { use super::*; fn do_type_check(expr: Expression, type_annotation: TypeId) -> CompileResult { - 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()), diff --git a/sway-core/src/semantic_analysis/node_dependencies.rs b/sway-core/src/semantic_analysis/node_dependencies.rs index b3697f7d608..53cda98f47b 100644 --- a/sway-core/src/semantic_analysis/node_dependencies.rs +++ b/sway-core/src/semantic_analysis/node_dependencies.rs @@ -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 } diff --git a/sway-core/src/style.rs b/sway-core/src/style.rs index 61ee8fc0779..488a1dec003 100644 --- a/sway-core/src/style.rs +++ b/sway-core/src/style.rs @@ -18,7 +18,7 @@ fn camel_case_split_words(ident: &str) -> impl Iterator { 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) @@ -27,7 +27,7 @@ fn camel_case_split_words(ident: &str) -> impl Iterator { /// Split an identifier of unknown style into words. fn split_words(ident: &str) -> impl Iterator { - 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. @@ -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 @@ -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 @@ -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 diff --git a/sway-core/src/type_engine/type_info.rs b/sway-core/src/type_engine/type_info.rs index 243aa93943c..2fa3731acde 100644 --- a/sway-core/src/type_engine/type_info.rs +++ b/sway-core/src/type_engine/type_info.rs @@ -163,7 +163,7 @@ impl TypeInfo { array_elem_count_pair .as_str() .trim() - .replace("_", "") + .replace('_', "") .parse::() // Could probably just .unwrap() here since it will succeed. .map_or_else( diff --git a/sway-ir/src/block.rs b/sway-ir/src/block.rs index 8f958f8f0b7..3f40999de23 100644 --- a/sway-ir/src/block.rs +++ b/sway-ir/src/block.rs @@ -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. diff --git a/sway-ir/src/context.rs b/sway-ir/src/context.rs index 6dc0f8d2647..57500d6f355 100644 --- a/sway-ir/src/context.rs +++ b/sway-ir/src/context.rs @@ -74,8 +74,7 @@ impl Context { pub fn get_aggregate_index(&self, aggregate: &Aggregate, field_name: &str) -> Option { self.aggregate_symbols .get(aggregate) - .map(|idx_map| idx_map.get(field_name).copied()) - .flatten() + .and_then(|idx_map| idx_map.get(field_name).copied()) } /// Get a globally unique symbol. diff --git a/sway-ir/src/instruction.rs b/sway-ir/src/instruction.rs index ae9586d862b..03f677ad82a 100644 --- a/sway-ir/src/instruction.rs +++ b/sway-ir/src/instruction.rs @@ -110,23 +110,20 @@ impl Instruction { Type::Struct(aggregate) => Some(*aggregate), _otherwise => None, }, - Instruction::ExtractElement { ty, .. } => ty - .get_elem_type(context) - .map(|ty| match ty { + Instruction::ExtractElement { ty, .. } => { + ty.get_elem_type(context).and_then(|ty| match ty { Type::Array(nested_aggregate) => Some(nested_aggregate), Type::Struct(nested_aggregate) => Some(nested_aggregate), _otherwise => None, }) - .flatten(), + } Instruction::ExtractValue { ty, indices, .. } => { // This array is a field in a struct or element in an array. - ty.get_field_type(context, indices) - .map(|ty| match ty { - Type::Array(nested_aggregate) => Some(nested_aggregate), - Type::Struct(nested_aggregate) => Some(nested_aggregate), - _otherwise => None, - }) - .flatten() + ty.get_field_type(context, indices).and_then(|ty| match ty { + Type::Array(nested_aggregate) => Some(nested_aggregate), + Type::Struct(nested_aggregate) => Some(nested_aggregate), + _otherwise => None, + }) } // Unknown aggregate instruction. Adding these as we come across them... diff --git a/sway-ir/src/irtype.rs b/sway-ir/src/irtype.rs index bc4cb482042..7b424880b36 100644 --- a/sway-ir/src/irtype.rs +++ b/sway-ir/src/irtype.rs @@ -112,7 +112,7 @@ impl Aggregate { /// Get the type of (nested) aggregate fields, if found. pub fn get_field_type(&self, context: &Context, indices: &[u64]) -> Option { indices.iter().fold(Some(Type::Struct(*self)), |ty, idx| { - ty.map(|ty| match ty { + ty.and_then(|ty| match ty { Type::Struct(agg) => context.aggregates[agg.0] .field_types() .get(*idx as usize) @@ -121,7 +121,6 @@ impl Aggregate { // Trying to index a non-aggregate. _otherwise => None, }) - .flatten() }) } diff --git a/sway-ir/src/verify.rs b/sway-ir/src/verify.rs index 80a1fe96fb8..3c80a90192e 100644 --- a/sway-ir/src/verify.rs +++ b/sway-ir/src/verify.rs @@ -59,8 +59,7 @@ impl Context { if !last_is_term || num_terms != 1 { Err(format!( "Block {} must have single terminator as its last instruction.\n\n{}", - block.label, - self.to_string() + block.label, self )) } else { Ok(()) diff --git a/sway-ir/tests/tests.rs b/sway-ir/tests/tests.rs index a32e8614971..734e9a23d5c 100644 --- a/sway-ir/tests/tests.rs +++ b/sway-ir/tests/tests.rs @@ -25,14 +25,14 @@ fn ir_to_ir_tests() { } else { panic!( "File which doesn't match valid passes: {:?}", - path.file_name().unwrap_or(path.as_os_str()) + path.file_name().unwrap_or_else(|| path.as_os_str()) ); } } Some("out_ir") => (), _ => 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()) ), } }