Skip to content

Commit

Permalink
Fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Dec 20, 2024
1 parent 10da66d commit 30dfde7
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 57 deletions.
3 changes: 1 addition & 2 deletions core/src/bytecode/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,7 @@ impl<'ast> TraverseAlloc<'ast, Ast<'ast>> for MatchBranch<'ast> {
.or_else(|| {
self.guard
.as_ref()
.map(|guard| guard.traverse_ref(f, scope))
.flatten()
.and_then(|guard| guard.traverse_ref(f, scope))
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/bytecode/ast/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'ast> TraverseAlloc<'ast, Ast<'ast>> for FieldDef<'ast> {
.path
.iter()
.map(|elem| match elem {
FieldPathElem::Ident(ident) => Ok(FieldPathElem::Ident(ident.clone())),
FieldPathElem::Ident(ident) => Ok(FieldPathElem::Ident(*ident)),
FieldPathElem::Expr(expr) => expr
.clone()
.traverse(alloc, f, order)
Expand Down
6 changes: 3 additions & 3 deletions core/src/bytecode/typecheck/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ where
}
}

impl<'a, 'ast, T> TypeEqBounded<'ast> for &'a T
impl<'ast, T> TypeEqBounded<'ast> for &T
where
T: TypeEqBounded<'ast>,
{
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<'ast> TypeEqBounded<'ast> for Annotation<'ast> {
self.typ.type_eq_bounded(&other.typ, state, env1, env2)
&& self
.contracts
.type_eq_bounded(&other.contracts, state, env1, env2)
.type_eq_bounded(other.contracts, state, env1, env2)
}
}

Expand Down Expand Up @@ -544,7 +544,7 @@ impl<'ast> TypeEqBounded<'ast> for FieldDef<'ast> {
) -> bool {
self.metadata
.type_eq_bounded(&other.metadata, state, env1, env2)
&& self.path.type_eq_bounded(&other.path, state, env1, env2)
&& self.path.type_eq_bounded(other.path, state, env1, env2)
&& self.value.type_eq_bounded(&other.value, state, env1, env2)
}
}
Expand Down
60 changes: 32 additions & 28 deletions core/src/bytecode/typecheck/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ impl<'ast> UnifError<'ast> {
match self {
UnifError::TypeMismatch { expected, inferred } => TypecheckError::TypeMismatch {
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
Expand All @@ -304,10 +304,10 @@ impl<'ast> UnifError<'ast> {
} => TypecheckError::RecordRowMismatch {
id,
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
cause: Box::new((*cause).into_typecheck_err_(state, names_reg, TermPos::None)),
pos,
Expand All @@ -320,10 +320,10 @@ impl<'ast> UnifError<'ast> {
} => TypecheckError::EnumRowMismatch {
id,
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
cause: cause.map(|err| {
Box::new((*err).into_typecheck_err_(state, names_reg, TermPos::None))
Expand All @@ -339,10 +339,10 @@ impl<'ast> UnifError<'ast> {
inferred_const_id,
} => TypecheckError::TypeMismatch {
expected: UnifType::from_constant_of_kind(expected_const_id, var_kind)
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: UnifType::from_constant_of_kind(inferred_const_id, var_kind)
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
Expand All @@ -352,10 +352,10 @@ impl<'ast> UnifError<'ast> {
inferred,
} => TypecheckError::TypeMismatch {
expected: UnifType::Constant(expected_const_id)
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
Expand All @@ -366,10 +366,10 @@ impl<'ast> UnifError<'ast> {
} => TypecheckError::ForallParametricityViolation {
kind: var_kind,
tail: UnifType::from_constant_of_kind(expected_const_id, var_kind)
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
violating_type: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
Expand All @@ -380,19 +380,19 @@ impl<'ast> UnifError<'ast> {
} => TypecheckError::MissingRow {
id,
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
UnifError::MissingDynTail { expected, inferred } => TypecheckError::MissingDynTail {
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
Expand All @@ -403,49 +403,53 @@ impl<'ast> UnifError<'ast> {
} => TypecheckError::ExtraRow {
id,
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
UnifError::ExtraDynTail { expected, inferred } => TypecheckError::ExtraDynTail {
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
#[allow(unused_variables)]
#[allow(unreachable_code)]
UnifError::RecordRowConflict {
row,
row: _,
expected,
inferred,
} => TypecheckError::RecordRowConflict {
// We won't convert to mainline when we'll plug-in the migrated typechecker, so it doesn't make sense to try to fix this line now - the error will go away.
row: todo!(), //row.to_type(&state.ast_alloc, names_reg, state.table),
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
#[allow(unused_variables)]
#[allow(unreachable_code)]
UnifError::EnumRowConflict {
row,
row: _,
expected,
inferred,
} => TypecheckError::EnumRowConflict {
// We won't convert to mainline when we'll plug-in the migrated typechecker, so it doesn't make sense to try to fix this line now - the error will go away.
row: todo!(),
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
pos,
},
Expand All @@ -454,10 +458,10 @@ impl<'ast> UnifError<'ast> {
let (expected, inferred, type_path, err_final) = err.into_type_path().unwrap();
TypecheckError::ArrowTypeMismatch {
expected: expected
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
inferred: inferred
.to_type(&state.ast_alloc, names_reg, state.table)
.to_type(state.ast_alloc, names_reg, state.table)
.to_mainline(),
type_path,
cause: Box::new(err_final.into_typecheck_err_(state, names_reg, TermPos::None)),
Expand Down
29 changes: 14 additions & 15 deletions core/src/bytecode/typecheck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ use crate::{
use std::{
cmp::max,
collections::{HashMap, HashSet},
convert::TryInto,
num::NonZeroU16,
};

Expand Down Expand Up @@ -1135,7 +1134,7 @@ impl<'a, 'ast> Iterator for RecordRowsIterator<'a, UnifType<'ast>, UnifRecordRow
}
RecordRowsF::TailVar(id) => {
self.rrows = None;
Some(RecordRowsElt::TailVar(&id))
Some(RecordRowsElt::TailVar(id))
}
RecordRowsF::Extend { row, tail } => {
self.rrows = Some(tail);
Expand Down Expand Up @@ -1180,7 +1179,7 @@ impl<'a, 'ast> Iterator for EnumRowsIterator<'a, UnifType<'ast>, UnifEnumRows<'a
}
EnumRowsF::TailVar(id) => {
self.erows = None;
Some(EnumRowsElt::TailVar(&id))
Some(EnumRowsElt::TailVar(id))
}
EnumRowsF::Extend { row, tail } => {
self.erows = Some(tail);
Expand Down Expand Up @@ -1236,7 +1235,7 @@ pub struct Context<'ast> {
pub var_level: VarLevel,
}

impl<'ast> Context<'ast> {
impl Context<'_> {
pub fn new() -> Self {
Context {
type_env: TypeEnv::new(),
Expand All @@ -1246,7 +1245,7 @@ impl<'ast> Context<'ast> {
}
}

impl<'ast> Default for Context<'ast> {
impl Default for Context<'_> {
fn default() -> Self {
Self::new()
}
Expand Down Expand Up @@ -1477,7 +1476,7 @@ fn walk<'ast, V: TypecheckVisitor<'ast>>(
ast,
UnifType::from_apparent_type(
apparent_type(
&state.ast_alloc,
state.ast_alloc,
node,
Some(&ctxt.type_env),
Some(state.resolver),
Expand Down Expand Up @@ -1713,8 +1712,8 @@ fn walk_rrows<'ast, V: TypecheckVisitor<'ast>>(
// don't check here for unbound type variables again.
| RecordRowsF::TailVar(_)
| RecordRowsF::TailDyn => Ok(()),
RecordRowsF::Extend { ref row, ref tail } => {
walk_type(state, ctxt.clone(), visitor, &row.typ)?;
RecordRowsF::Extend { ref row, tail } => {
walk_type(state, ctxt.clone(), visitor, row.typ)?;
walk_rrows(state, ctxt, visitor, tail)
}
}
Expand Down Expand Up @@ -1756,7 +1755,7 @@ fn walk_with_annot<'ast, V: TypecheckVisitor<'ast>>(
) -> Result<(), TypecheckError> {
annot
.iter()
.try_for_each(|ty| walk_type(state, ctxt.clone(), visitor, &ty))?;
.try_for_each(|ty| walk_type(state, ctxt.clone(), visitor, ty))?;

match (annot, value) {
(Annotation { typ: Some(ty2), .. }, Some(value)) => {
Expand Down Expand Up @@ -2251,7 +2250,7 @@ fn check<'ast, V: TypecheckVisitor<'ast>>(
// .map_err(|err| err.into_typecheck_err(state, ast.pos))
// }
Node::Type(typ) => {
if let Some(contract) = typ.find_contract() {
if let Some(_contract) = typ.find_contract() {
todo!("needs to update `error::TypecheckError` first, but not ready to switch to the new typechecker yet")
// Err(TypecheckError::CtrTypeInTermPos {
// contract,
Expand Down Expand Up @@ -2496,7 +2495,7 @@ fn binding_type<'ast>(
apparent_or_infer(
state,
apparent_type(
&state.ast_alloc,
state.ast_alloc,
ast,
Some(&ctxt.type_env),
Some(state.resolver),
Expand All @@ -2515,7 +2514,7 @@ fn field_type<'ast>(
) -> UnifType<'ast> {
apparent_or_infer(
state,
field_def.apparent_type(&state.ast_alloc, Some(&ctxt.type_env), Some(state.resolver)),
field_def.apparent_type(state.ast_alloc, Some(&ctxt.type_env), Some(state.resolver)),
ctxt,
strict,
)
Expand Down Expand Up @@ -2670,7 +2669,7 @@ impl<'ast> HasApparentType<'ast> for FieldDef<'ast> {
.annotation
.first()
.cloned()
.map(|ty| ApparentType::Annotated(ty))
.map(ApparentType::Annotated)
.or_else(|| {
self.value
.as_ref()
Expand Down Expand Up @@ -2720,7 +2719,7 @@ pub fn apparent_type<'ast>(
node: &Node<'ast>,
env: Option<&TypeEnv<'ast>>,
resolver: Option<&dyn ImportResolver>,
mut imports_seen: HashSet<FileId>,
_imports_seen: HashSet<FileId>,
) -> ApparentType<'ast> {
match node {
Node::Annotated { annot, inner } => annot
Expand Down Expand Up @@ -2977,4 +2976,4 @@ pub trait TypecheckVisitor<'ast> {
}

/// A do-nothing `TypeCheckVisitor` for when you don't want one.
impl<'ast> TypecheckVisitor<'ast> for () {}
impl TypecheckVisitor<'_> for () {}
6 changes: 3 additions & 3 deletions core/src/bytecode/typecheck/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl PrimOpType for PrimOp {
/// 'Error { message | String | optional, notes | Array String | optional }
/// |]
/// ```
pub fn custom_contract_type<'ast>(alloc: &'ast AstAlloc) -> UnifType<'ast> {
pub fn custom_contract_type(alloc: &AstAlloc) -> UnifType<'_> {
mk_buty_arrow!(
mk_uniftype::dynamic(),
mk_uniftype::dynamic(),
Expand All @@ -596,7 +596,7 @@ pub fn custom_contract_type<'ast>(alloc: &'ast AstAlloc) -> UnifType<'ast> {
/// 'Error { message | String | optional, notes | Array String | optional }
/// |]
/// ```
pub fn custom_contract_ret_type<'ast>(alloc: &'ast AstAlloc) -> UnifType<'ast> {
pub fn custom_contract_ret_type(alloc: &AstAlloc) -> UnifType<'_> {
mk_buty_enum!(
("Ok", mk_uniftype::dynamic()),
("Error", error_data_type(alloc))
Expand All @@ -615,7 +615,7 @@ pub fn custom_contract_ret_type<'ast>(alloc: &'ast AstAlloc) -> UnifType<'ast> {
/// | optional
/// }
/// ```
fn error_data_type<'ast>(alloc: &'ast AstAlloc) -> UnifType<'ast> {
fn error_data_type(alloc: &AstAlloc) -> UnifType<'_> {
let error_data = builder::Record::new()
.field("message")
.optional(true)
Expand Down
Loading

0 comments on commit 30dfde7

Please sign in to comment.