diff --git a/core/src/bytecode/ast/mod.rs b/core/src/bytecode/ast/mod.rs index 018519d89..3c584f4d8 100644 --- a/core/src/bytecode/ast/mod.rs +++ b/core/src/bytecode/ast/mod.rs @@ -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)) }) } } diff --git a/core/src/bytecode/ast/record.rs b/core/src/bytecode/ast/record.rs index 00579415e..79f8324a0 100644 --- a/core/src/bytecode/ast/record.rs +++ b/core/src/bytecode/ast/record.rs @@ -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) diff --git a/core/src/bytecode/typecheck/eq.rs b/core/src/bytecode/typecheck/eq.rs index d8f166624..4a76b144d 100644 --- a/core/src/bytecode/typecheck/eq.rs +++ b/core/src/bytecode/typecheck/eq.rs @@ -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>, { @@ -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) } } @@ -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) } } diff --git a/core/src/bytecode/typecheck/error.rs b/core/src/bytecode/typecheck/error.rs index 2402cb949..94329fb34 100644 --- a/core/src/bytecode/typecheck/error.rs +++ b/core/src/bytecode/typecheck/error.rs @@ -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, }, @@ -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, @@ -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)) @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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)), diff --git a/core/src/bytecode/typecheck/mod.rs b/core/src/bytecode/typecheck/mod.rs index 635dce726..2c9989553 100644 --- a/core/src/bytecode/typecheck/mod.rs +++ b/core/src/bytecode/typecheck/mod.rs @@ -72,7 +72,6 @@ use crate::{ use std::{ cmp::max, collections::{HashMap, HashSet}, - convert::TryInto, num::NonZeroU16, }; @@ -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); @@ -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); @@ -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(), @@ -1246,7 +1245,7 @@ impl<'ast> Context<'ast> { } } -impl<'ast> Default for Context<'ast> { +impl Default for Context<'_> { fn default() -> Self { Self::new() } @@ -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), @@ -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) } } @@ -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)) => { @@ -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, @@ -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), @@ -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, ) @@ -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() @@ -2720,7 +2719,7 @@ pub fn apparent_type<'ast>( node: &Node<'ast>, env: Option<&TypeEnv<'ast>>, resolver: Option<&dyn ImportResolver>, - mut imports_seen: HashSet, + _imports_seen: HashSet, ) -> ApparentType<'ast> { match node { Node::Annotated { annot, inner } => annot @@ -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 () {} diff --git a/core/src/bytecode/typecheck/operation.rs b/core/src/bytecode/typecheck/operation.rs index fcdfbb235..d651a356d 100644 --- a/core/src/bytecode/typecheck/operation.rs +++ b/core/src/bytecode/typecheck/operation.rs @@ -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(), @@ -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)) @@ -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) diff --git a/core/src/bytecode/typecheck/record.rs b/core/src/bytecode/typecheck/record.rs index cea2396b0..e5e77ab47 100644 --- a/core/src/bytecode/typecheck/record.rs +++ b/core/src/bytecode/typecheck/record.rs @@ -156,7 +156,7 @@ impl<'ast> ResolvedRecord<'ast> { for (id, field) in &self.stat_fields { let uty_apprt = field.apparent_type( - &state.ast_alloc, + state.ast_alloc, Some(&ctxt.type_env), Some(state.resolver), ); @@ -255,7 +255,7 @@ impl<'ast> Combine for ResolvedRecord<'ast> { let dyn_fields = this .dyn_fields .into_iter() - .chain(other.dyn_fields.into_iter()) + .chain(other.dyn_fields) .collect(); let pos = match (this.pos, other.pos) { @@ -400,7 +400,7 @@ impl<'ast> ResolvedField<'ast> { } } -impl<'ast> Combine for ResolvedField<'ast> { +impl Combine for ResolvedField<'_> { fn combine(this: Self, other: Self) -> Self { let mut defs = this.defs; defs.extend(other.defs); @@ -536,7 +536,7 @@ impl<'ast> HasApparentType<'ast> for ResolvedField<'ast> { [def] => def.apparent_type(ast_alloc, env, resolver), _ => self .first_annot() - .map(|ty| ApparentType::Annotated(ty)) + .map(ApparentType::Annotated) .unwrap_or(ApparentType::Approximated(Type::from(TypeF::Dyn))), } } diff --git a/core/src/bytecode/typecheck/unif.rs b/core/src/bytecode/typecheck/unif.rs index 3d229a80f..68df32d0f 100644 --- a/core/src/bytecode/typecheck/unif.rs +++ b/core/src/bytecode/typecheck/unif.rs @@ -1247,7 +1247,7 @@ impl<'ast> Unify<'ast> for UnifType<'ast> { }) } (TypeF::Contract((t1, env1)), TypeF::Contract((t2, env2))) - if t1.type_eq(&t2, &env1, &env2) => + if t1.type_eq(t2, &env1, &env2) => { Ok(()) }