Skip to content

Commit

Permalink
fix: clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Nov 29, 2024
1 parent e4489e5 commit 24dd989
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 38 deletions.
40 changes: 20 additions & 20 deletions crates/els/hir_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
l: &impl Locational,
r: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
if !self.search.matches(expr) {
return None;
}
Expand All @@ -263,7 +263,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
pos: Position,
loc: &impl Locational,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
(loc.loc().contains(pos.loc()) && self.search.matches(expr)).then_some(expr)
}

Expand Down Expand Up @@ -301,7 +301,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
acc: &'e Accessor,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
match acc {
Accessor::Ident(ident) => self.return_expr_if_same(expr, ident.raw.name.token(), pos),
Accessor::Attr(attr) => self
Expand All @@ -315,7 +315,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
bin: &'e BinOp,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
if bin.op.loc().contains(pos.loc()) && self.search.matches(expr) {
return Some(expr);
}
Expand All @@ -328,7 +328,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
call: &'e Call,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
// args: `(1, 2)`, pos: `)`
call.args
.paren
Expand All @@ -344,7 +344,7 @@ impl<'a> HIRVisitor<'a> {
.or_else(|| self.return_expr_if_contains(expr, pos, call))
}

fn get_expr_from_args<'e>(&'e self, args: &'e Args, pos: Position) -> Option<&Expr> {
fn get_expr_from_args<'e>(&'e self, args: &'e Args, pos: Position) -> Option<&'e Expr> {
for arg in args.pos_args.iter() {
if let Some(expr) = self.get_expr(&arg.expr, pos) {
return Some(expr);
Expand All @@ -368,7 +368,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
def: &'e Def,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
self.return_expr_if_same(expr, def.sig.ident().raw.name.token(), pos)
.or_else(|| {
def.sig
Expand All @@ -384,7 +384,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
class_def: &'e ClassDef,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
class_def
.require_or_sup
.as_ref()
Expand All @@ -397,7 +397,7 @@ impl<'a> HIRVisitor<'a> {
&'e self,
block: impl Iterator<Item = &'e Expr>,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
for chunk in block {
if let Some(expr) = self.get_expr(chunk, pos) {
return Some(expr);
Expand All @@ -411,12 +411,12 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
redef: &'e ReDef,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
self.get_expr_from_acc(expr, &redef.attr, pos)
.or_else(|| self.get_expr_from_block(redef.block.iter(), pos))
}

fn get_expr_from_dummy<'e>(&'e self, dummy: &'e Dummy, pos: Position) -> Option<&Expr> {
fn get_expr_from_dummy<'e>(&'e self, dummy: &'e Dummy, pos: Position) -> Option<&'e Expr> {
for chunk in dummy.iter() {
if let Some(expr) = self.get_expr(chunk, pos) {
return Some(expr);
Expand All @@ -430,7 +430,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
patch_def: &'e PatchDef,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
self.return_expr_if_same(expr, patch_def.sig.name().token(), pos)
.or_else(|| self.get_expr(&patch_def.base, pos))
.or_else(|| self.get_expr_from_block(patch_def.methods.iter(), pos))
Expand All @@ -442,7 +442,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
lambda: &'e Lambda,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
if util::pos_in_loc(&lambda.params, util::loc_to_pos(pos.loc())?)
&& self.search.matches(expr)
{
Expand All @@ -456,7 +456,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
lis: &'e List,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
if lis.ln_end() == pos.ln_end() && self.search.matches(expr) {
// arr: `[1, 2]`, pos: `]`
return Some(expr);
Expand All @@ -472,7 +472,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
dict: &'e Dict,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
if dict.ln_end() == pos.ln_end() && self.search.matches(expr) {
// arr: `{...}`, pos: `}`
return Some(expr);
Expand All @@ -498,7 +498,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
record: &'e Record,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
if record.ln_end() == pos.ln_end() && self.search.matches(expr) {
// arr: `{...}`, pos: `}`
return Some(expr);
Expand All @@ -516,7 +516,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
set: &'e Set,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
if set.ln_end() == pos.ln_end() && self.search.matches(expr) {
// arr: `{...}`, pos: `}`
return Some(expr);
Expand All @@ -532,7 +532,7 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
tuple: &'e Tuple,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
match tuple {
Tuple::Normal(tuple) => {
// arr: `(1, 2)`, pos: `)`
Expand All @@ -551,14 +551,14 @@ impl<'a> HIRVisitor<'a> {
expr: &'e Expr,
type_asc: &'e TypeAscription,
pos: Position,
) -> Option<&Expr> {
) -> Option<&'e Expr> {
self.get_expr(&type_asc.expr, pos)
.or_else(|| self.get_expr(&type_asc.spec.expr, pos))
.or_else(|| self.return_expr_if_contains(expr, pos, type_asc))
}
}

impl<'a> HIRVisitor<'a> {
impl HIRVisitor<'_> {
/// Returns the smallest expression containing `token`. Literals, accessors, containers, etc. are returned.
pub fn get_info(&self, token: &Token) -> Option<VarInfo> {
for chunk in self.hir.module.iter() {
Expand Down
2 changes: 1 addition & 1 deletion crates/els/inlay_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct InlayHintGenerator<'s, C: BuildRunnable, P: Parsable> {
uri: Value,
}

impl<'s, C: BuildRunnable, P: Parsable> InlayHintGenerator<'s, C, P> {
impl<C: BuildRunnable, P: Parsable> InlayHintGenerator<'_, C, P> {
fn anot(&self, ln: u32, col: u32, cont: String) -> InlayHint {
let position = Position::new(ln - 1, col);
let label = InlayHintLabel::String(cont);
Expand Down
14 changes: 7 additions & 7 deletions crates/erg_common/python_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env::{current_dir, set_current_dir, temp_dir};
use std::fs::{canonicalize, remove_file, File};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, ExitStatus, Stdio};
use std::process::{Child, Command, ExitStatus, Stdio};

use crate::env::opt_which_python;
use crate::fn_name_full;
Expand Down Expand Up @@ -942,30 +942,30 @@ pub fn exec_py(file: impl AsRef<Path>, args: &[&str]) -> std::io::Result<ExitSta
child.wait()
}

pub fn env_spawn_py(code: &str) {
pub fn env_spawn_py(code: &str) -> Child {
if cfg!(windows) {
Command::new(which_python())
.arg("-c")
.arg(code)
.spawn()
.expect("cannot execute python");
.expect("cannot execute python")
} else {
let exec_command = format!("{} -c \"{}\"", which_python(), escape_py_code(code));
Command::new("sh")
.arg("-c")
.arg(exec_command)
.spawn()
.expect("cannot execute python");
.expect("cannot execute python")
}
}

pub fn spawn_py(py_command: Option<&str>, code: &str) {
pub fn spawn_py(py_command: Option<&str>, code: &str) -> Child {
if cfg!(windows) {
Command::new(py_command.unwrap_or(which_python()))
.arg("-c")
.arg(code)
.spawn()
.expect("cannot execute python");
.expect("cannot execute python")
} else {
let exec_command = format!(
"{} -c \"{}\"",
Expand All @@ -976,7 +976,7 @@ pub fn spawn_py(py_command: Option<&str>, code: &str) {
.arg("-c")
.arg(exec_command)
.spawn()
.expect("cannot execute python");
.expect("cannot execute python")
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/erg_common/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl From<Str> for String {
}
}

impl<'a> From<Str> for Cow<'a, str> {
impl From<Str> for Cow<'_, str> {
fn from(s: Str) -> Self {
match s {
Str::Static(s) => Cow::Borrowed(s),
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/inquire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3916,7 +3916,7 @@ impl Context {
candidates: &'m [MethodPair],
namespace: &Context,
) -> Triple<&'m MethodPair, TyCheckError> {
if candidates.first().is_none() {
if candidates.is_empty() {
return Triple::None;
}
let matches = candidates
Expand Down
4 changes: 2 additions & 2 deletions crates/erg_compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ impl Context {
}

/// enumerates all the variables/methods in the current context & super contexts.
pub(crate) fn type_dir<'t>(&'t self, namespace: &'t Context) -> Dict<&VarName, &VarInfo> {
pub(crate) fn type_dir<'t>(&'t self, namespace: &'t Context) -> Dict<&'t VarName, &'t VarInfo> {
let mut attrs = self.locals.iter().collect::<Dict<_, _>>();
attrs.guaranteed_extend(
self.params
Expand Down Expand Up @@ -1450,7 +1450,7 @@ impl Context {
attrs
}

fn type_impl_dir<'t>(&'t self, namespace: &'t Context) -> Dict<&VarName, &VarInfo> {
fn type_impl_dir<'t>(&'t self, namespace: &'t Context) -> Dict<&'t VarName, &'t VarInfo> {
let mut attrs = self.locals.iter().collect::<Dict<_, _>>();
attrs.guaranteed_extend(
self.methods_list
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
}
}

impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
impl<L: Locational> Unifier<'_, '_, '_, L> {
/// ```erg
/// occur(?T, ?T) ==> OK
/// occur(?T(<: ?U), ?U) ==> OK
Expand Down
4 changes: 2 additions & 2 deletions crates/erg_compiler/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,14 +1655,14 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
}
other => {
let expr = other.map_or("nothing", |expr| expr.name());
return Err(LowerErrors::from(LowerError::syntax_error(
Err(LowerErrors::from(LowerError::syntax_error(
self.input().clone(),
line!() as usize,
other.loc(),
self.module.context.caused_by(),
format!("expected identifier, but found {expr}"),
None,
)));
)))
}
},
Some(OperationKind::Return | OperationKind::Yield) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/module/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::varinfo::{AbsLocation, VarInfo};

pub struct Members<'a>(MappedRwLockReadGuard<'a, Dict<AbsLocation, ModuleIndexValue>>);

impl<'a> Members<'a> {
impl Members<'_> {
pub fn iter(&self) -> Iter<AbsLocation, ModuleIndexValue> {
self.0.iter()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ impl SubrType {
let non_defaults = self
.non_default_params
.iter()
.filter(|pt| !pt.name().is_some_and(|n| &n[..] == "self"));
.filter(|pt| pt.name().is_none_or(|n| &n[..] != "self"));
let defaults = self.default_params.iter();
if let Some(var_params) = self.var_params.as_ref() {
non_defaults
Expand Down
3 changes: 2 additions & 1 deletion src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ impl New for DummyVM {
let code = include_str!("scripts/repl_server.py")
.replace("__PORT__", port.to_string().as_str())
.replace("__MODULE__", &cfg.dump_filename().replace('/', "."));
spawn_py(cfg.py_command, &code);
#[allow(clippy::zombie_processes)]
let _ = spawn_py(cfg.py_command, &code);
let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, port);
if !cfg.quiet_repl {
println!("Connecting to the REPL server...");
Expand Down

0 comments on commit 24dd989

Please sign in to comment.