Skip to content

Commit

Permalink
fmt and clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Apr 9, 2024
1 parent e5ed216 commit 8a9ae0b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
7 changes: 5 additions & 2 deletions sway-core/src/ir_generation/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,26 @@ pub(crate) fn compile_constant_expression_to_constant(
lookup: compile_const_decl,
};

let err = match &const_expr.expression {
let err = |inner| match &const_expr.expression {
// Special case functions because the span in `const_expr` is to the inlined function
// definition, rather than the actual call site.
ty::TyExpressionVariant::FunctionApplication { call_path, .. } => {
Err(CompileError::NonConstantDeclValue {
span: call_path.span(),
inner,
})
}
_otherwise => Err(CompileError::NonConstantDeclValue {
span: const_expr.span.clone(),
inner,
}),
};
let mut known_consts = MappedStack::<Ident, Constant>::new();

match const_eval_typed_expr(lookup, &mut known_consts, const_expr, allow_configurables) {
Ok(Some(constant)) => Ok(constant),
_ => err,
Err(ConstEvalError::CompileError(inner)) => err(Some(Box::new(inner))),
_ => err(None),
}
}

Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/language/ty/declaration/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl SubstTypes for TyTraitDecl {
false
}
}
});
} || has_changes);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions sway-core/src/semantic_analysis/ast_node/declaration/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ impl TyTraitDecl {
let mut const_decl = (*decl_engine.get_constant(&decl_ref)).clone();
let name = const_decl.call_path.suffix.clone();
let r = if const_decl.subst(&type_mapping, engines) {
let new_ref = decl_engine.insert(const_decl);
new_ref
decl_engine.insert(const_decl)
} else {
decl_ref.clone()
};
Expand All @@ -385,8 +384,7 @@ impl TyTraitDecl {
let mut t = (*decl_engine.get_type(&decl_ref)).clone();
let name = t.name.clone();
let r = if t.subst(&type_mapping, engines) {
let new_ref = decl_engine.insert(t);
new_ref
decl_engine.insert(t)
} else {
decl_ref.clone()
};
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/type_system/substitute/subst_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<T: SubstTypes> SubstTypes for Option<T> {

impl<T: SubstTypes> SubstTypes for Vec<T> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) -> bool {
self.iter_mut().fold(false, |mut has_change, x| {
self.iter_mut().fold(false, |has_change, x| {
x.subst(type_mapping, engines) || has_change
})
}
Expand Down
7 changes: 5 additions & 2 deletions sway-error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,10 @@ pub enum CompileError {
#[error("{}", error)]
Parse { error: ParseError },
#[error("Could not evaluate initializer to a const declaration.")]
NonConstantDeclValue { span: Span },
NonConstantDeclValue {
span: Span,
inner: Option<Box<CompileError>>,
},
#[error("Declaring storage in a {program_kind} is not allowed.")]
StorageDeclarationInNonContract { program_kind: String, span: Span },
#[error("Unsupported argument type to intrinsic \"{name}\".{}", if hint.is_empty() { "".to_string() } else { format!(" Hint: {hint}") })]
Expand Down Expand Up @@ -1037,7 +1040,7 @@ impl Spanned for CompileError {
Parse { error } => error.span.clone(),
EnumNotFound { span, .. } => span.clone(),
TupleIndexOutOfBounds { span, .. } => span.clone(),
NonConstantDeclValue { span } => span.clone(),
NonConstantDeclValue { span, .. } => span.clone(),
StorageDeclarationInNonContract { span, .. } => span.clone(),
IntrinsicUnsupportedArgType { span, .. } => span.clone(),
IntrinsicIncorrectNumArgs { span, .. } => span.clone(),
Expand Down
9 changes: 4 additions & 5 deletions sway-ir/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ mod ir_builder {
(ty, cv)
}
/ ty:ast_ty() "undef" _ {
(ty.clone(), IrAstConst { value: IrAstConstValue::Undef(ty), meta_idx: None })
(ty.clone(), IrAstConst { value: IrAstConstValue::Undef, meta_idx: None })
}

rule ast_ty() -> IrAstTy
Expand Down Expand Up @@ -764,8 +764,7 @@ mod ir_builder {

#[derive(Debug)]
enum IrAstConstValue {
#[allow(dead_code)]
Undef(IrAstTy),
Undef,
Unit,
Bool(bool),
Hex256([u8; 32]),
Expand All @@ -792,7 +791,7 @@ mod ir_builder {
impl IrAstConstValue {
fn as_constant_value(&self, context: &mut Context, val_ty: IrAstTy) -> ConstantValue {
match self {
IrAstConstValue::Undef(_) => ConstantValue::Undef,
IrAstConstValue::Undef => ConstantValue::Undef,
IrAstConstValue::Unit => ConstantValue::Unit,
IrAstConstValue::Bool(b) => ConstantValue::Bool(*b),
IrAstConstValue::Hex256(bs) => match val_ty {
Expand Down Expand Up @@ -834,7 +833,7 @@ mod ir_builder {

fn as_value(&self, context: &mut Context, val_ty: IrAstTy) -> Value {
match self {
IrAstConstValue::Undef(_) => unreachable!("Can't convert 'undef' to a value."),
IrAstConstValue::Undef => unreachable!("Can't convert 'undef' to a value."),
IrAstConstValue::Unit => Constant::get_unit(context),
IrAstConstValue::Bool(b) => Constant::get_bool(context, *b),
IrAstConstValue::Hex256(bs) => match val_ty {
Expand Down

0 comments on commit 8a9ae0b

Please sign in to comment.