fix: clippy warnings

This commit is contained in:
Shunsuke Shibayama 2024-11-29 11:08:25 +09:00
parent e4489e5f41
commit 24dd989466
11 changed files with 39 additions and 38 deletions

View file

@ -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;
}
@ -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)
}
@ -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
@ -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);
}
@ -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
@ -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);
@ -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
@ -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()
@ -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);
@ -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);
@ -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))
@ -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)
{
@ -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);
@ -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);
@ -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);
@ -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);
@ -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: `)`
@ -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() {

View file

@ -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);

View file

@ -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;
@ -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 \"{}\"",
@ -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")
}
}

View file

@ -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),

View file

@ -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

View file

@ -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
@ -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

View file

@ -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

View file

@ -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) => {

View file

@ -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()
}

View file

@ -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

View file

@ -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...");