Skip to content

Commit 02733a4

Browse files
authored
Merge branch 'master' into ironcev/panic-expression
2 parents b11f629 + 173b65b commit 02733a4

File tree

25 files changed

+90
-91
lines changed

25 files changed

+90
-91
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515
env:
1616
CARGO_TERM_COLOR: always
1717
REGISTRY: ghcr.io
18-
RUST_VERSION: 1.85.0
18+
RUST_VERSION: 1.86.0
1919
NIGHTLY_RUST_VERSION: nightly-2025-03-20
2020

2121
jobs:

forc-pkg/src/manifest/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ fn implicit_std_dep() -> Dependency {
881881

882882
if let Some((_, build_metadata)) = det.tag.as_ref().and_then(|tag| tag.split_once('+')) {
883883
// Nightlies are in the format v<version>+nightly.<date>.<hash>
884-
let rev = build_metadata.split('.').last().map(|r| r.to_string());
884+
let rev = build_metadata.split('.').next_back().map(|r| r.to_string());
885885

886886
// If some revision is available and parsed from the 'nightly' build metadata,
887887
// we always prefer the revision over the tag.

forc-pkg/src/pkg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl MemberFilter {
397397
TreeType::Predicate => self.build_predicates,
398398
TreeType::Script => self.build_scripts,
399399
TreeType::Contract => self.build_contracts,
400-
TreeType::Library { .. } => self.build_libraries,
400+
TreeType::Library => self.build_libraries,
401401
},
402402
Err(_) => true,
403403
}
@@ -1035,7 +1035,7 @@ fn validate_dep_manifest(
10351035
// Check if the dependency is either a library or a contract declared as a contract dependency
10361036
match (&dep_program_type, &dep_edge.kind) {
10371037
(TreeType::Contract, DepKind::Contract { salt: _ })
1038-
| (TreeType::Library { .. }, DepKind::Library) => {}
1038+
| (TreeType::Library, DepKind::Library) => {}
10391039
_ => bail!(
10401040
"\"{}\" is declared as a {} dependency, but is actually a {}",
10411041
dep.name,

forc-util/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ pub fn path_lock<X: AsRef<Path>>(path: X) -> Result<fd_lock::RwLock<File>> {
379379

380380
pub fn program_type_str(ty: &TreeType) -> &'static str {
381381
match ty {
382-
TreeType::Script {} => "script",
383-
TreeType::Contract {} => "contract",
384-
TreeType::Predicate {} => "predicate",
385-
TreeType::Library { .. } => "library",
382+
TreeType::Script => "script",
383+
TreeType::Contract => "contract",
384+
TreeType::Predicate => "predicate",
385+
TreeType::Library => "library",
386386
}
387387
}
388388

sway-ast/src/path.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ impl PathExpr {
2222
self.suffix
2323
.iter()
2424
.map(|s| &s.1)
25-
.last()
25+
.next_back()
2626
.unwrap_or(&self.prefix)
2727
}
2828

2929
pub fn last_segment_mut(&mut self) -> &mut PathExprSegment {
3030
self.suffix
3131
.iter_mut()
3232
.map(|s| &mut s.1)
33-
.last()
33+
.next_back()
3434
.unwrap_or(&mut self.prefix)
3535
}
3636
}
@@ -87,15 +87,15 @@ impl PathType {
8787
self.suffix
8888
.iter()
8989
.map(|s| &s.1)
90-
.last()
90+
.next_back()
9191
.unwrap_or(&self.prefix)
9292
}
9393

9494
pub fn last_segment_mut(&mut self) -> &mut PathTypeSegment {
9595
self.suffix
9696
.iter_mut()
9797
.map(|s| &mut s.1)
98-
.last()
98+
.next_back()
9999
.unwrap_or(&mut self.prefix)
100100
}
101101
}

sway-core/src/asm_generation/fuel/data_section.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use sway_ir::{
33
size_bytes_round_up_to_word_alignment, ConstantContent, ConstantValue, Context, Padding,
44
};
55

6-
use std::{fmt, iter::repeat};
6+
use std::fmt;
77

88
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
99
pub enum EntryName {
@@ -178,8 +178,12 @@ impl Entry {
178178

179179
let final_padding = self.padding.target_size().saturating_sub(bytes.len());
180180
match self.padding {
181-
Padding::Left { .. } => [repeat(0u8).take(final_padding).collect(), bytes].concat(),
182-
Padding::Right { .. } => [bytes, repeat(0u8).take(final_padding).collect()].concat(),
181+
Padding::Left { .. } => {
182+
[std::iter::repeat_n(0u8, final_padding).collect(), bytes].concat()
183+
}
184+
Padding::Right { .. } => {
185+
[bytes, std::iter::repeat_n(0u8, final_padding).collect()].concat()
186+
}
183187
}
184188
}
185189

sway-core/src/asm_generation/fuel/register_allocator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl RegisterPool {
118118
/// ===============================================================================================
119119
/// 1. create a graph node for every virtual register used.
120120
/// 2. for a MOVE "v <= c" with live_out virtual registers b1, ... bn for v:
121-
/// add edges (v, b_1), ..., (v, b_n) for any b_i different from c.
121+
/// add edges (v, b_1), ..., (v, b_n) for any b_i different from c.
122122
/// 3. for non-MOVE def of virtual register v with live_out virtual registers b_1, ..., b_n:
123-
/// add edges (v, b_1), ..., (v, b_n)
123+
/// add edges (v, b_1), ..., (v, b_n)
124124
///
125125
/// ===============================================================================================
126126
pub(crate) fn create_interference_graph(
@@ -384,8 +384,8 @@ fn compute_def_use_points(ops: &[Op]) -> FxHashMap<VirtualRegister, (Vec<usize>,
384384
/// 2. Remove node n and all its edges from the graph
385385
/// - This may make some new nodes have fewer than k neighbours which is nice.
386386
/// 3. If some vertex n still has k or more neighbors, then the graph may not be k colorable.
387-
/// We still add it to the stack as is, as a potential spill. When popping, if we still
388-
/// can't colour it, then it becomes an actual spill.
387+
/// We still add it to the stack as is, as a potential spill. When popping, if we still
388+
/// can't colour it, then it becomes an actual spill.
389389
///
390390
/// ===============================================================================================
391391
///

sway-core/src/asm_lang/allocated_ops.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,7 @@ impl AllocatedOp {
793793
/* Non-VM Instructions */
794794
BLOB(a) => {
795795
return FuelAsmData::Instructions(
796-
std::iter::repeat(op::NOOP::new().into())
797-
.take(a.value() as usize)
798-
.collect(),
796+
std::iter::repeat_n(op::NOOP::new().into(), a.value() as usize).collect(),
799797
)
800798
}
801799
ConfigurablesOffsetPlaceholder => {

sway-core/src/control_flow_analysis/dead_code_analysis.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn is_entry_point(node: &TyAstNode, decl_engine: &DeclEngine, tree_type: &TreeTy
4444
_ => false,
4545
}
4646
}
47-
TreeType::Contract | TreeType::Library { .. } => match node {
47+
TreeType::Contract | TreeType::Library => match node {
4848
TyAstNode {
4949
content:
5050
TyAstNodeContent::Declaration(TyDecl::FunctionDecl(FunctionDecl { decl_id })),
@@ -707,7 +707,7 @@ fn connect_struct_declaration<'eng: 'cfg, 'cfg>(
707707
//
708708
// this is important because if the struct is public, you want to be able to signal that all
709709
// fields are accessible by just adding an edge to the struct declaration node
710-
if matches!(tree_type, TreeType::Contract | TreeType::Library { .. })
710+
if matches!(tree_type, TreeType::Contract | TreeType::Library)
711711
&& *visibility == Visibility::Public
712712
{
713713
for (_name, node) in &field_nodes {
@@ -791,7 +791,7 @@ fn connect_impl_trait<'eng: 'cfg, 'cfg>(
791791
if let Some(trait_entry) = trait_entry.clone() {
792792
matches!(
793793
trait_entry.module_tree_type,
794-
TreeType::Library { .. } | TreeType::Contract
794+
TreeType::Library | TreeType::Contract
795795
)
796796
} else {
797797
// trait_entry not found which means it is an external trait.
@@ -800,7 +800,7 @@ fn connect_impl_trait<'eng: 'cfg, 'cfg>(
800800
true
801801
}
802802
} else {
803-
matches!(tree_type, TreeType::Library { .. } | TreeType::Contract)
803+
matches!(tree_type, TreeType::Library | TreeType::Contract)
804804
};
805805
if add_edge_to_fn_decl {
806806
graph.add_edge(entry_node, fn_decl_entry_node, "".into());

sway-core/src/ir_generation/compile.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,11 @@ fn compile_fn(
591591
// Convert the name.
592592
param.name.as_str().into(),
593593
// Convert the type further to a pointer if it's a reference.
594-
param
595-
.is_reference
596-
.then(|| Type::new_ptr(context, ty))
597-
.unwrap_or(ty),
594+
if param.is_reference {
595+
Type::new_ptr(context, ty)
596+
} else {
597+
ty
598+
},
598599
// Convert the span to a metadata index.
599600
md_mgr.span_to_md(context, &param.name.span()),
600601
)

sway-core/src/ir_generation/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ impl<'eng> FnCompiler<'eng> {
729729
}),
730730
}
731731
}
732-
ty::TyExpressionVariant::Continue { .. } => match self.block_to_continue_to {
732+
ty::TyExpressionVariant::Continue => match self.block_to_continue_to {
733733
// If `self.block_to_continue_to` is not None, then it has been set inside
734734
// a loop and the use of `continue` here is legal, so create a branch
735735
// instruction. Error out otherwise.

sway-core/src/ir_generation/storage.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ fn hash_storage_key_string(storage_key_string: String) -> Bytes32 {
100100
use uint::construct_uint;
101101

102102
#[allow(
103-
// These two warnings are generated by the `construct_uint!()` macro below.
103+
// These warnings are generated by the `construct_uint!()` macro below.
104104
clippy::assign_op_pattern,
105-
clippy::ptr_offset_with_cast
105+
clippy::ptr_offset_with_cast,
106+
clippy::manual_div_ceil
106107
)]
107108
pub(super) fn add_to_b256(x: Bytes32, y: u64) -> Bytes32 {
108109
construct_uint! {
@@ -228,7 +229,7 @@ pub fn serialize_to_storage_slots(
228229
);
229230
packed.extend(vec![
230231
Bytes8::new([0; 8]);
231-
((packed.len() + 3) / 4) * 4 - packed.len()
232+
packed.len().div_ceil(4) * 4 - packed.len()
232233
]);
233234

234235
assert!(packed.len() % 4 == 0);
@@ -251,7 +252,7 @@ pub fn serialize_to_storage_slots(
251252
);
252253

253254
let storage_key = get_storage_key(storage_field_names, key);
254-
(0..(type_size_in_bytes + 31) / 32)
255+
(0..type_size_in_bytes.div_ceil(32))
255256
.map(|i| add_to_b256(storage_key, i))
256257
.zip((0..packed.len() / 4).map(|i| {
257258
Bytes32::new(
@@ -304,7 +305,7 @@ fn serialize_to_words(
304305
ConstantValue::String(s) if ty.is_string_array(context) => {
305306
// Turn the bytes into serialized words (Bytes8) and right pad it to the word boundary.
306307
let mut s = s.clone();
307-
s.extend(vec![0; ((s.len() + 7) / 8) * 8 - s.len()]);
308+
s.extend(vec![0; s.len().div_ceil(8) * 8 - s.len()]);
308309

309310
assert!(s.len() % 8 == 0);
310311

sway-core/src/language/ty/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl TyProgram {
240240
// Some checks that are specific to non-contracts
241241
if kind != parsed::TreeType::Contract {
242242
// impure functions are disallowed in non-contracts
243-
if !matches!(kind, parsed::TreeType::Library { .. }) {
243+
if !matches!(kind, parsed::TreeType::Library) {
244244
for err in disallow_impure_functions(decl_engine, &declarations, &entries) {
245245
handler.emit_err(err);
246246
}

sway-core/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ pub(crate) fn is_ty_module_cache_up_to_date(
645645
.and_then(|x| x.lsp_mode.as_ref())
646646
.and_then(|lsp| lsp.file_versions.get(path.as_ref()))
647647
.is_none_or(|version| {
648-
version.map_or(true, |v| typed.version.is_some_and(|tv| v <= tv))
648+
version.is_none_or(|v| typed.version.is_some_and(|tv| v <= tv))
649649
});
650650

651651
// If the cache is up to date, recursively check all dependencies
@@ -695,7 +695,7 @@ pub(crate) fn is_parse_module_cache_up_to_date(
695695
// - If there's no cached version (entry.parsed.version is None), the cache is outdated.
696696
// - If there's a cached version, compare them: cache is up-to-date if the LSP file version
697697
// is not greater than the cached version.
698-
version.map_or(true, |v| entry.parsed.version.is_some_and(|ev| v <= ev))
698+
version.is_none_or(|v| entry.parsed.version.is_some_and(|ev| v <= ev))
699699
},
700700
);
701701

sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,9 @@ impl TyImplSelfOrTrait {
757757
);
758758

759759
// Do a topological sort to compute an ordered list of nodes (by function calls).
760-
let sorted = match petgraph::algo::toposort(&sub_graph, None) {
761-
Ok(value) => Some(value),
762-
// If the dependency graph contains cycles, then this means there are recursive
763-
// function calls, which we will report later.
764-
Err(_) => None,
765-
};
760+
// If the dependency graph contains cycles, then this means there are recursive
761+
// function calls, which we will report later.
762+
let sorted = petgraph::algo::toposort(&sub_graph, None).ok();
766763

767764
Ok(sorted)
768765
})

sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/range.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ where
281281
/// 1. Sort the intervals based on increasing order of starting time.
282282
/// 2. Push the first interval on to a stack.
283283
/// 3. For each interval do the following
284-
/// 3a. If the current interval does not overlap with the stack
285-
/// top, push it.
286-
/// 3b. If the current interval overlaps with stack top (or is within ± 1)
287-
/// and ending time of current interval is more than that of stack top,
288-
/// update stack top with the ending time of current interval.
284+
/// 3a. If the current interval does not overlap with the stack
285+
/// top, push it.
286+
/// 3b. If the current interval overlaps with stack top (or is within ± 1)
287+
/// and ending time of current interval is more than that of stack top,
288+
/// update stack top with the ending time of current interval.
289289
/// 4. At the end stack contains the merged intervals.
290290
fn condense_ranges(
291291
handler: &Handler,

sway-core/src/semantic_analysis/namespace/trait_map.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,11 @@ impl TraitMap {
839839
///
840840
/// Notes:
841841
/// - equivalency is defined (1) based on whether the types contains types
842-
/// that are dynamic and can change and (2) whether the types hold
843-
/// equivalency after (1) is fulfilled
842+
/// that are dynamic and can change and (2) whether the types hold
843+
/// equivalency after (1) is fulfilled
844844
/// - this method does not translate types from the found entries to the
845-
/// `type_id` (like in `filter_by_type()`). This is because the only
846-
/// entries that qualify as hits are equivalents of `type_id`
845+
/// `type_id` (like in `filter_by_type()`). This is because the only
846+
/// entries that qualify as hits are equivalents of `type_id`
847847
pub(crate) fn get_items_for_type(
848848
module: &Module,
849849
engines: &Engines,
@@ -901,11 +901,11 @@ impl TraitMap {
901901
///
902902
/// Notes:
903903
/// - equivalency is defined (1) based on whether the types contains types
904-
/// that are dynamic and can change and (2) whether the types hold
905-
/// equivalency after (1) is fulfilled
904+
/// that are dynamic and can change and (2) whether the types hold
905+
/// equivalency after (1) is fulfilled
906906
/// - this method does not translate types from the found entries to the
907-
/// `type_id` (like in `filter_by_type()`). This is because the only
908-
/// entries that qualify as hits are equivalents of `type_id`
907+
/// `type_id` (like in `filter_by_type()`). This is because the only
908+
/// entries that qualify as hits are equivalents of `type_id`
909909
pub fn get_impl_spans_for_type(
910910
module: &Module,
911911
engines: &Engines,
@@ -994,11 +994,11 @@ impl TraitMap {
994994
///
995995
/// Notes:
996996
/// - equivalency is defined (1) based on whether the types contains types
997-
/// that are dynamic and can change and (2) whether the types hold
998-
/// equivalency after (1) is fulfilled
997+
/// that are dynamic and can change and (2) whether the types hold
998+
/// equivalency after (1) is fulfilled
999999
/// - this method does not translate types from the found entries to the
1000-
/// `type_id` (like in `filter_by_type()`). This is because the only
1001-
/// entries that qualify as hits are equivalents of `type_id`
1000+
/// `type_id` (like in `filter_by_type()`). This is because the only
1001+
/// entries that qualify as hits are equivalents of `type_id`
10021002
pub(crate) fn get_items_for_type_and_trait_name_and_trait_type_arguments(
10031003
module: &Module,
10041004
engines: &Engines,
@@ -1066,11 +1066,11 @@ impl TraitMap {
10661066
///
10671067
/// Notes:
10681068
/// - equivalency is defined (1) based on whether the types contains types
1069-
/// that are dynamic and can change and (2) whether the types hold
1070-
/// equivalency after (1) is fulfilled
1069+
/// that are dynamic and can change and (2) whether the types hold
1070+
/// equivalency after (1) is fulfilled
10711071
/// - this method does not translate types from the found entries to the
1072-
/// `type_id` (like in `filter_by_type()`). This is because the only
1073-
/// entries that qualify as hits are equivalents of `type_id`
1072+
/// `type_id` (like in `filter_by_type()`). This is because the only
1073+
// entries that qualify as hits are equivalents of `type_id`
10741074
pub(crate) fn get_items_for_type_and_trait_name_and_trait_type_arguments_typed(
10751075
module: &Module,
10761076
engines: &Engines,

sway-core/src/type_system/ast_elements/binding.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ use sway_types::{Span, Spanned};
7070
/// Each of these 4 examples generates a valid struct expression for `Data`
7171
/// and passes type checking. But each does so in a unique way:
7272
/// - `data1` has no type ascription and no type arguments in the `TypeBinding`,
73-
/// so both are inferred from the value passed to `value`
73+
/// so both are inferred from the value passed to `value`
7474
/// - `data2` has no type ascription but does have type arguments in the
75-
/// `TypeBinding`, so the type ascription and type of the value passed to
76-
/// `value` are both unified to the `TypeBinding`
75+
/// `TypeBinding`, so the type ascription and type of the value passed to
76+
/// `value` are both unified to the `TypeBinding`
7777
/// - `data3` has a type ascription but no type arguments in the `TypeBinding`,
78-
/// so the type arguments in the `TypeBinding` and the type of the value
79-
/// passed to `value` are both unified to the type ascription
78+
/// so the type arguments in the `TypeBinding` and the type of the value
79+
/// passed to `value` are both unified to the type ascription
8080
/// - `data4` has a type ascription and has type arguments in the `TypeBinding`,
81-
/// so, with the type from the value passed to `value`, all three are unified
82-
/// together
81+
/// so, with the type from the value passed to `value`, all three are unified
82+
/// together
8383
#[derive(Debug, Clone, Serialize, Deserialize)]
8484
pub struct TypeBinding<T> {
8585
pub inner: T,

0 commit comments

Comments
 (0)