Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix new clippy warnings #681

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dedup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait DeduplicateConstants: Sized {
fn deduplicate_constants(self) -> Result<Self, Error>;
}

impl<'ast> DeduplicateConstants for Fir<FlattenData<'ast>> {
impl DeduplicateConstants for Fir<FlattenData<'_>> {
fn deduplicate_constants(self) -> Result<Self, Error> {
let mut ctx = ConstantDeduplicator(HashMap::new());

Expand Down
2 changes: 1 addition & 1 deletion flatten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub enum AstInfo<'ast> {
Helper(Symbol, SpanTuple),
}

impl<'ast> AstInfo<'ast> {
impl AstInfo<'_> {
pub fn location(&self) -> &SpanTuple {
match self {
AstInfo::Node(Ast { location, .. })
Expand Down
6 changes: 2 additions & 4 deletions name_resolve/src/declarator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum DefinitionKind {

pub(crate) struct Declarator<'ctx, 'enclosing>(pub(crate) &'ctx mut NameResolveCtx<'enclosing>);

impl<'ctx, 'enclosing> Declarator<'ctx, 'enclosing> {
impl Declarator<'_, '_> {
fn define(
&mut self,
kind: DefinitionKind,
Expand Down Expand Up @@ -41,9 +41,7 @@ impl<'ctx, 'enclosing> Declarator<'ctx, 'enclosing> {
}
}

impl<'ast, 'ctx, 'enclosing> Traversal<FlattenData<'ast>, NameResolutionError>
for Declarator<'ctx, 'enclosing>
{
impl<'ast> Traversal<FlattenData<'ast>, NameResolutionError> for Declarator<'_, '_> {
// TODO: Can we factor these three functions?

fn traverse_function(
Expand Down
12 changes: 5 additions & 7 deletions name_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<'scope, 'enclosing> LookupIterator<'scope, 'enclosing> for FlatScope<'enclo
}
}

impl<'scope, 'enclosing> Iterator for FlatIterator<'scope, 'enclosing> {
impl<'scope> Iterator for FlatIterator<'scope, '_> {
type Item = &'scope Bindings;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -125,7 +125,7 @@ impl<'scope, 'enclosing> Iterator for FlatIterator<'scope, 'enclosing> {
}
}

impl<'enclosing> FlatScope<'enclosing> {
impl FlatScope<'_> {
fn lookup(&self, name: &Symbol, starting_scope: Scope) -> Option<&OriginIdx> {
self.lookup_iterator(starting_scope)
.find_map(|bindings| bindings.get(name))
Expand Down Expand Up @@ -163,7 +163,7 @@ struct NameResolveCtx<'enclosing> {
}

impl<'enclosing> NameResolveCtx<'enclosing> {
fn new(enclosing_scope: EnclosingScope<'enclosing>) -> NameResolveCtx {
fn new(enclosing_scope: EnclosingScope<'enclosing>) -> NameResolveCtx<'enclosing> {
let empty_scope_map: HashMap<Scope, Bindings> = enclosing_scope
.0
.values()
Expand Down Expand Up @@ -314,7 +314,7 @@ impl NameResolutionError {
}
}

impl<'enclosing> NameResolveCtx<'enclosing> {
impl NameResolveCtx<'_> {
fn scope(fir: &Fir<FlattenData>) -> HashMap<OriginIdx, Scope> {
let root = fir.nodes.last_key_value().unwrap();

Expand Down Expand Up @@ -346,9 +346,7 @@ impl<'enclosing> NameResolveCtx<'enclosing> {
}
}

impl<'ast, 'enclosing> Pass<FlattenData<'ast>, FlattenData<'ast>, Error>
for NameResolveCtx<'enclosing>
{
impl<'ast> Pass<FlattenData<'ast>, FlattenData<'ast>, Error> for NameResolveCtx<'_> {
fn pre_condition(_fir: &Fir<FlattenData>) {}

fn post_condition(_fir: &Fir<FlattenData>) {}
Expand Down
6 changes: 2 additions & 4 deletions name_resolve/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Display for ResolveKind {

pub(crate) struct Resolver<'ctx, 'enclosing>(pub(crate) &'ctx mut NameResolveCtx<'enclosing>);

impl<'ctx, 'enclosing> Resolver<'ctx, 'enclosing> {
impl Resolver<'_, '_> {
fn get_definition(
&self,
kind: ResolveKind,
Expand Down Expand Up @@ -54,9 +54,7 @@ impl<'ctx, 'enclosing> Resolver<'ctx, 'enclosing> {
}
}

impl<'ast, 'ctx, 'enclosing> Mapper<FlattenData<'ast>, FlattenData<'ast>, NameResolutionError>
for Resolver<'ctx, 'enclosing>
{
impl<'ast> Mapper<FlattenData<'ast>, FlattenData<'ast>, NameResolutionError> for Resolver<'_, '_> {
fn map_call(
&mut self,
data: FlattenData<'ast>,
Expand Down
2 changes: 1 addition & 1 deletion src/context/scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<V, F, T> ScopeMap<V, F, T> {
&'map self,
key: &Q,
map_extractor: impl Fn(&Scope<V, F, T>) -> &HashMap<K, U>,
) -> Option<&U>
) -> Option<&'map U>
where
K: Borrow<Q> + Hash + Eq + 'map,
Q: Hash + Eq + ?Sized,
Expand Down
6 changes: 3 additions & 3 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
let call = call.downcast_ref::<FunctionCall>().unwrap();

assert_eq!(
execute(&dec, &call, &mut i),
execute(dec, call, &mut i),
Ok(Some(JkInt::from(15).to_instance()))
);
}
Expand All @@ -264,12 +264,12 @@ mod tests {
let call = constructs::expr(span!("print_something()")).unwrap().1;
let call = call.downcast_ref::<FunctionCall>().unwrap();

assert_eq!(execute(&dec, &call, &mut i), Ok(None));
assert_eq!(execute(dec, call, &mut i), Ok(None));
}

#[test]
fn load_libs_stress() {
let ld_library_path = std::env::var("LD_LIBRARY_PATH").unwrap_or(String::new());
let ld_library_path = std::env::var("LD_LIBRARY_PATH").unwrap_or_default();
let pwd = std::env::var("PWD").unwrap();
std::env::set_var(
"LD_LIBRARY_PATH",
Expand Down
10 changes: 5 additions & 5 deletions src/instruction/binary_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ mod tests {
fn comparison_precedence() {
assert_bool(
"1 + 4 * 2 - 1 + 2 * (14 + (2 - 17) * 1) - 12 + 3 / 2 < 45",
1 + 4 * 2 - 1 + 2 * (14 + (2 - 17) * 1) - 12 + 3 / 2 < 45,
1 + 4 * 2 - 1 + 2 * (14 + (2 - 17)) - 12 + 3 / 2 < 45,
);
}

Expand Down Expand Up @@ -375,17 +375,17 @@ mod tests {

#[test]
fn binop_execute_valid_mul() {
binop_assert!(1 * 2);
binop_assert!(2);
}

#[test]
fn binop_execute_valid_normal_priority() {
binop_assert!(1 * 2 + 3);
binop_assert!(2 + 3);
}

#[test]
fn binop_execute_valid_back_priority() {
binop_assert!(3 + 1 * 2);
binop_assert!(3 + 2);
}

#[test]
Expand All @@ -410,6 +410,6 @@ mod tests {

#[test]
fn binop_execute_valid_extremely_complex_expr() {
binop_assert!(1 + 4 * 2 - 1 + 2 * (14 + (2 - 17) * 1) - 12 + 3 / 2);
binop_assert!(1 + 4 * 2 - 1 + 2 * (14 + (2 - 17)) - 12 + 3 / 2);
}
}
6 changes: 2 additions & 4 deletions src/instruction/field_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,11 @@ mod tests {
use crate::{jinko, jinko_fail, span};

fn setup() -> Context {
let ctx = jinko! {
jinko! {
type Point(x: int, y:int);
func basic() -> Point { Point ( x : 15, y : 14 )}
b = basic();
};

ctx
}
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/parser/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,9 @@ fn generic_func_or_type_inst_args(
func_or_type_inst_args(next(input), id, generics, start_loc)
}

///
/// ARGS
///
//
// ARGS
//

/// args = expr ( ',' expr )* ')'
/// | ')'
Expand Down
4 changes: 2 additions & 2 deletions typecheck/src/actual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ChainEnd {
final_type: Type,
}

impl<'ctx> TypeLinkResolver<'ctx> {
impl TypeLinkResolver<'_> {
/// Recursively try and resolve a type link within the type context. This will update the given node's type
/// within the type context.
fn resolve_link(&mut self, to_resolve: OriginIdx, fir: &Fir<FlattenData>) -> OriginIdx {
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<'ctx> TypeLinkResolver<'ctx> {
}
}

impl<'ctx> Traversal<FlattenData<'_>, Error> for TypeLinkResolver<'ctx> {
impl Traversal<FlattenData<'_>, Error> for TypeLinkResolver<'_> {
fn traverse_node(
&mut self,
fir: &Fir<FlattenData>,
Expand Down
6 changes: 3 additions & 3 deletions typecheck/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{Type, TypeCtx};
// as it's used for conditions for multiple nodes
pub(crate) struct Checker<'ctx>(pub(crate) &'ctx mut TypeCtx<TypeMap>);

impl<'ctx> Checker<'ctx> {
impl Checker<'_> {
fn get_type(&self, of: &RefIdx) -> &Type {
// if at this point, the reference is unresolved, or if we haven't seen that node yet, it's
// an interpreter error
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<'ctx> Checker<'ctx> {

struct Fmt<'fir, 'ast>(&'fir Fir<FlattenData<'ast>>);

impl<'fir, 'ast> Fmt<'fir, 'ast> {
impl Fmt<'_, '_> {
pub fn number(value: usize) -> String {
match value {
0 => format!("{}", "no".purple()),
Expand Down Expand Up @@ -207,7 +207,7 @@ fn unexpected_arithmetic_type(
.with_loc(loc.clone())
}

impl<'ctx> Traversal<FlattenData<'_>, Error> for Checker<'ctx> {
impl Traversal<FlattenData<'_>, Error> for Checker<'_> {
fn traverse_function(
&mut self,
fir: &Fir<FlattenData>,
Expand Down
4 changes: 2 additions & 2 deletions typecheck/src/typer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{TypeCtx, TypeLinkMap, TypeVariable};
/// in the documentation for [`Typer::ty`].
pub(crate) struct Typer<'ctx>(pub(crate) &'ctx mut TypeCtx<TypeLinkMap>);

impl<'ctx> Typer<'ctx> {
impl Typer<'_> {
fn assign_type(&mut self, node: OriginIdx, ty: TypeVariable) {
// Having non-unique ids in the Fir is an interpreter error
// Or should we return an error here?
Expand Down Expand Up @@ -58,7 +58,7 @@ impl<'ctx> Typer<'ctx> {
}
}

impl<'ast, 'ctx> Mapper<FlattenData<'ast>, FlattenData<'ast>, Error> for Typer<'ctx> {
impl<'ast> Mapper<FlattenData<'ast>, FlattenData<'ast>, Error> for Typer<'_> {
fn map_constant(
&mut self,
data: FlattenData<'ast>,
Expand Down
6 changes: 3 additions & 3 deletions xparser/src/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,9 @@ fn generic_func_or_type_inst_args(
func_or_type_inst_args(next(input), id, generics, start_loc)
}

///
/// ARGS
///
//
// ARGS
//

/// args = expr ( ',' expr )* ')'
/// | ')'
Expand Down
4 changes: 2 additions & 2 deletions xparser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum Error<'i> {
Mult(Vec<Error<'i>>),
}

impl<'i> Error<'i> {
impl Error<'_> {
pub fn emit(&self) {
match self {
Error::Msg(m) => eprintln!("parsing error: {m}"),
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'i> From<nom::Err<Error<'i>>> for Error<'i> {
}

impl<'i> nom::error::ParseError<ParseInput<'i>> for Error<'i> {
fn from_error_kind(span: ParseInput<'i>, k: nom::error::ErrorKind) -> Error {
fn from_error_kind(span: ParseInput<'i>, k: nom::error::ErrorKind) -> Error<'i> {
// FIXME: Add better location here in order to print whole line and
// display specific hint about parse error
// Error::new(ErrKind::Parsing).with_loc(Some(SpanTuple::with_source_ref(
Expand Down
Loading