Skip to content

Commit 27cbf5a

Browse files
committed
clippy and fmt issues
1 parent c295006 commit 27cbf5a

File tree

7 files changed

+45
-20
lines changed

7 files changed

+45
-20
lines changed

sway-core/src/language/parsed/declaration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Declaration {
123123
TypeAliasDeclaration(decl_id) => pe.get_type_alias(decl_id).span(),
124124
TraitTypeDeclaration(decl_id) => pe.get_trait_type(decl_id).span(),
125125
TraitFnDeclaration(decl_id) => pe.get_trait_fn(decl_id).span(),
126-
ConstGenericDeclaration(decl_id) => {
126+
ConstGenericDeclaration(_) => {
127127
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
128128
}
129129
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl TyDecl {
570570
TyDecl::VariableDecl(_decl) => None,
571571
TyDecl::ConstantDecl(decl) => decl_engine.get_parsed_decl(&decl.decl_id),
572572
TyDecl::ConfigurableDecl(decl) => decl_engine.get_parsed_decl(&decl.decl_id),
573-
TyDecl::ConstGenericDecl(decl) => {
573+
TyDecl::ConstGenericDecl(_) => {
574574
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
575575
}
576576
TyDecl::TraitTypeDecl(decl) => decl_engine.get_parsed_decl(&decl.decl_id),

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,14 +1125,7 @@ impl ConstGenericExpr {
11251125

11261126
impl PartialOrd for ConstGenericExpr {
11271127
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
1128-
match (self, other) {
1129-
(Self::Literal { val: l, .. }, Self::Literal { val: r, .. }) => l.partial_cmp(r),
1130-
(
1131-
Self::AmbiguousVariableExpression { ident: l, .. },
1132-
Self::AmbiguousVariableExpression { ident: r, .. },
1133-
) => l.partial_cmp(r),
1134-
_ => None,
1135-
}
1128+
Some(self.cmp(other))
11361129
}
11371130
}
11381131

@@ -1283,7 +1276,7 @@ impl Eq for ConstGenericParameter {}
12831276

12841277
impl PartialOrd for ConstGenericParameter {
12851278
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
1286-
self.name.as_str().partial_cmp(other.name.as_str())
1279+
Some(self.cmp(other))
12871280
}
12881281
}
12891282

sway-lsp/src/capabilities/document_symbol.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ fn collect_enum_variants(decl: &TyEnumDecl) -> Vec<DocumentSymbol> {
375375
// Check for the presence of a CallPathTree, and if it exists, use the type information as the detail.
376376
let detail = variant
377377
.type_argument
378-
.call_path_tree()
378+
.as_type_argument()
379+
.unwrap()
380+
.call_path_tree
379381
.as_ref()
380382
.map(|_| Some(variant.type_argument.span().as_str().to_string()))
381383
.unwrap_or(None);
@@ -428,7 +430,10 @@ fn fn_decl_detail(parameters: &[TyFunctionParameter], return_type: &GenericArgum
428430

429431
// Check for the presence of a CallPathTree, and if it exists, add it to the return type.
430432
let return_type = return_type
431-
.call_path_tree()
433+
.as_type_argument()
434+
.unwrap()
435+
.call_path_tree
436+
.as_ref()
432437
.map(|_| format!(" -> {}", return_type.span().as_str()))
433438
.unwrap_or_default();
434439
format!("fn({params}){return_type}")

sway-lsp/src/capabilities/inlay_hints.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ pub fn inlay_hints(
7474
}
7575

7676
// Variable declaration hints
77-
if var.type_ascription.call_path_tree().is_none() {
77+
if var
78+
.type_ascription
79+
.as_type_argument()
80+
.unwrap()
81+
.call_path_tree
82+
.is_none()
83+
{
7884
let type_info = engines.te().get(var.type_ascription.type_id());
7985
if !matches!(
8086
*type_info,

sway-lsp/src/traverse/parsed_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ impl Parse for GenericArgument {
11221122
}
11231123
_ => {
11241124
let symbol_kind = type_info_to_symbol_kind(ctx.engines.te(), &type_info, None);
1125-
if let Some(tree) = &self.call_path_tree() {
1125+
if let Some(tree) = &self.as_type_argument().unwrap().call_path_tree.as_ref() {
11261126
let token =
11271127
Token::from_parsed(ParsedAstToken::TypeArgument(self.clone()), symbol_kind);
11281128
collect_call_path_tree(ctx, tree, &token, ctx.tokens);

sway-lsp/src/traverse/typed_tree.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,13 @@ impl Parse for ty::TyVariableDecl {
655655
));
656656
token.type_def = Some(TypeDefinition::Ident(self.name.clone()));
657657
}
658-
if let Some(call_path_tree) = &self.type_ascription.call_path_tree() {
658+
if let Some(call_path_tree) = &self
659+
.type_ascription
660+
.as_type_argument()
661+
.unwrap()
662+
.call_path_tree
663+
.as_ref()
664+
{
659665
collect_call_path_tree(ctx, call_path_tree, &self.type_ascription);
660666
}
661667
self.body.parse(ctx);
@@ -879,7 +885,10 @@ impl Parse for ty::ImplSelfOrTrait {
879885
implementing_for.type_id(),
880886
&typed_token,
881887
implementing_for
882-
.call_path_tree()
888+
.as_type_argument()
889+
.unwrap()
890+
.call_path_tree
891+
.as_ref()
883892
.map(|tree| tree.qualified_call_path.call_path.suffix.span())
884893
.unwrap_or(implementing_for.span()),
885894
);
@@ -1367,7 +1376,13 @@ fn collect_const_decl(ctx: &ParseContext, const_decl: &ty::TyConstantDecl, ident
13671376
TokenAstNode::Typed(TypedAstToken::TypedConstantDeclaration(const_decl.clone()));
13681377
token.type_def = Some(TypeDefinition::Ident(const_decl.call_path.suffix.clone()));
13691378
}
1370-
if let Some(call_path_tree) = &const_decl.type_ascription.call_path_tree() {
1379+
if let Some(call_path_tree) = &const_decl
1380+
.type_ascription
1381+
.as_type_argument()
1382+
.unwrap()
1383+
.call_path_tree
1384+
.as_ref()
1385+
{
13711386
collect_call_path_tree(ctx, call_path_tree, &const_decl.type_ascription);
13721387
}
13731388
if let Some(value) = &const_decl.value {
@@ -1387,7 +1402,13 @@ fn collect_configurable_decl(
13871402
TokenAstNode::Typed(TypedAstToken::TypedConfigurableDeclaration(decl.clone()));
13881403
token.type_def = Some(TypeDefinition::Ident(decl.call_path.suffix.clone()));
13891404
}
1390-
if let Some(call_path_tree) = &decl.type_ascription.call_path_tree() {
1405+
if let Some(call_path_tree) = &decl
1406+
.type_ascription
1407+
.as_type_argument()
1408+
.unwrap()
1409+
.call_path_tree
1410+
.as_ref()
1411+
{
13911412
collect_call_path_tree(ctx, call_path_tree, &decl.type_ascription);
13921413
}
13931414
if let Some(value) = &decl.value {
@@ -1516,7 +1537,7 @@ fn collect_type_id(
15161537
}
15171538

15181539
fn collect_type_argument(ctx: &ParseContext, type_arg: &GenericArgument) {
1519-
if let Some(call_path_tree) = type_arg.call_path_tree() {
1540+
if let Some(call_path_tree) = type_arg.as_type_argument().unwrap().call_path_tree.as_ref() {
15201541
collect_call_path_tree(ctx, call_path_tree, type_arg);
15211542
} else {
15221543
collect_type_id(

0 commit comments

Comments
 (0)