mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-31 15:48:23 +00:00
chore: eliminate clippy warns
This commit is contained in:
parent
1b04cbe802
commit
936b6e2f95
26 changed files with 231 additions and 98 deletions
|
@ -142,7 +142,11 @@ impl Parser {
|
|||
|
||||
fn convert_def_to_var_record_attr(&mut self, mut attr: Def) -> ParseResult<VarRecordAttr> {
|
||||
debug_call_info!(self);
|
||||
let Signature::Var(VarSignature{ pat: VarPattern::Ident(lhs), .. }) = attr.sig else {
|
||||
let Signature::Var(VarSignature {
|
||||
pat: VarPattern::Ident(lhs),
|
||||
..
|
||||
}) = attr.sig
|
||||
else {
|
||||
let err = ParseError::simple_syntax_error(line!() as usize, attr.sig.loc());
|
||||
self.errs.push(err);
|
||||
return Err(());
|
||||
|
@ -293,7 +297,11 @@ impl Parser {
|
|||
let sig = self
|
||||
.convert_rhs_to_sig(*t_app.obj)
|
||||
.map_err(|_| self.stack_dec(fn_name!()))?;
|
||||
let Signature::Var(VarSignature { pat: VarPattern::Ident(ident), .. }) = sig else {
|
||||
let Signature::Var(VarSignature {
|
||||
pat: VarPattern::Ident(ident),
|
||||
..
|
||||
}) = sig
|
||||
else {
|
||||
let err = ParseError::simple_syntax_error(line!() as usize, sig.loc());
|
||||
self.errs.push(err);
|
||||
debug_exit_info!(self);
|
||||
|
@ -343,7 +351,11 @@ impl Parser {
|
|||
let lhs = self
|
||||
.convert_rhs_to_sig(*tasc.expr)
|
||||
.map_err(|_| self.stack_dec(fn_name!()))?;
|
||||
let Signature::Var(VarSignature{ pat: VarPattern::Ident(lhs), .. }) = lhs else {
|
||||
let Signature::Var(VarSignature {
|
||||
pat: VarPattern::Ident(lhs),
|
||||
..
|
||||
}) = lhs
|
||||
else {
|
||||
let err = ParseError::simple_syntax_error(line!() as usize, lhs.loc());
|
||||
self.errs.push(err);
|
||||
return Err(());
|
||||
|
@ -541,7 +553,11 @@ impl Parser {
|
|||
}
|
||||
|
||||
fn convert_def_to_param_record_attr(&mut self, mut attr: Def) -> ParseResult<ParamRecordAttr> {
|
||||
let Signature::Var(VarSignature{ pat: VarPattern::Ident(lhs), .. }) = attr.sig else {
|
||||
let Signature::Var(VarSignature {
|
||||
pat: VarPattern::Ident(lhs),
|
||||
..
|
||||
}) = attr.sig
|
||||
else {
|
||||
let err = ParseError::simple_syntax_error(line!() as usize, attr.sig.loc());
|
||||
self.errs.push(err);
|
||||
debug_exit_info!(self);
|
||||
|
|
|
@ -149,7 +149,9 @@ impl Desugarer {
|
|||
},
|
||||
Expr::DataPack(pack) => {
|
||||
let class = desugar(*pack.class);
|
||||
let Expr::Record(args) = desugar(Expr::Record(pack.args)) else { unreachable!() };
|
||||
let Expr::Record(args) = desugar(Expr::Record(pack.args)) else {
|
||||
unreachable!()
|
||||
};
|
||||
Expr::DataPack(DataPack::new(class, pack.connector, args))
|
||||
}
|
||||
Expr::Array(array) => match array {
|
||||
|
@ -273,7 +275,9 @@ impl Desugarer {
|
|||
Expr::Def(Def::new(def.sig, body))
|
||||
}
|
||||
Expr::ClassDef(class_def) => {
|
||||
let Expr::Def(def) = desugar(Expr::Def(class_def.def)) else { unreachable!() };
|
||||
let Expr::Def(def) = desugar(Expr::Def(class_def.def)) else {
|
||||
unreachable!()
|
||||
};
|
||||
let methods = class_def
|
||||
.methods_list
|
||||
.into_iter()
|
||||
|
@ -282,7 +286,9 @@ impl Desugarer {
|
|||
Expr::ClassDef(ClassDef::new(def, methods))
|
||||
}
|
||||
Expr::PatchDef(class_def) => {
|
||||
let Expr::Def(def) = desugar(Expr::Def(class_def.def)) else { unreachable!() };
|
||||
let Expr::Def(def) = desugar(Expr::Def(class_def.def)) else {
|
||||
unreachable!()
|
||||
};
|
||||
let methods = class_def
|
||||
.methods_list
|
||||
.into_iter()
|
||||
|
@ -401,7 +407,9 @@ impl Desugarer {
|
|||
if let Some(Expr::Def(previous)) = new.last() {
|
||||
if previous.is_subr() && previous.sig.name_as_str() == def.sig.name_as_str()
|
||||
{
|
||||
let Some(Expr::Def(previous)) = new.pop() else { unreachable!() };
|
||||
let Some(Expr::Def(previous)) = new.pop() else {
|
||||
unreachable!()
|
||||
};
|
||||
let name = def.sig.ident().unwrap().clone();
|
||||
let id = def.body.id;
|
||||
let op = def.body.op.clone();
|
||||
|
@ -479,8 +487,12 @@ impl Desugarer {
|
|||
|
||||
fn add_arg_to_match_call(&self, mut previous: Def, def: Def) -> (Call, Option<TypeSpecWithOp>) {
|
||||
let op = Token::from_str(TokenKind::FuncArrow, "->");
|
||||
let Expr::Call(mut call) = previous.body.block.remove(0) else { unreachable!() };
|
||||
let Signature::Subr(sig) = def.sig else { unreachable!() };
|
||||
let Expr::Call(mut call) = previous.body.block.remove(0) else {
|
||||
unreachable!()
|
||||
};
|
||||
let Signature::Subr(sig) = def.sig else {
|
||||
unreachable!()
|
||||
};
|
||||
let return_t_spec = sig.return_t_spec;
|
||||
let first_arg = sig.params.non_defaults.first().unwrap();
|
||||
// 最後の定義の引数名を関数全体の引数名にする
|
||||
|
@ -509,7 +521,9 @@ impl Desugarer {
|
|||
// TODO: procedural match
|
||||
fn gen_match_call(&self, previous: Def, def: Def) -> (Call, Option<TypeSpecWithOp>) {
|
||||
let op = Token::from_str(TokenKind::FuncArrow, "->");
|
||||
let Signature::Subr(prev_sig) = previous.sig else { unreachable!() };
|
||||
let Signature::Subr(prev_sig) = previous.sig else {
|
||||
unreachable!()
|
||||
};
|
||||
let params_len = prev_sig.params.len();
|
||||
let params = if params_len == 1 {
|
||||
prev_sig.params
|
||||
|
@ -520,7 +534,9 @@ impl Desugarer {
|
|||
let match_symbol = Expr::static_local("match");
|
||||
let sig = LambdaSignature::new(params, prev_sig.return_t_spec, prev_sig.bounds);
|
||||
let first_branch = Lambda::new(sig, op.clone(), previous.body.block, previous.body.id);
|
||||
let Signature::Subr(sig) = def.sig else { unreachable!() };
|
||||
let Signature::Subr(sig) = def.sig else {
|
||||
unreachable!()
|
||||
};
|
||||
let params = if sig.params.len() == 1 {
|
||||
sig.params
|
||||
} else {
|
||||
|
@ -588,10 +604,13 @@ impl Desugarer {
|
|||
}
|
||||
|
||||
fn desugar_pattern_in_module(&mut self, module: Module) -> Module {
|
||||
// https://github.com/rust-lang/rust-clippy/issues/11300
|
||||
#[allow(clippy::useless_conversion)]
|
||||
Module::new(self.desugar_pattern(module.into_iter()))
|
||||
}
|
||||
|
||||
fn desugar_pattern_in_block(&mut self, block: Block) -> Block {
|
||||
#[allow(clippy::useless_conversion)]
|
||||
Block::new(self.desugar_pattern(block.into_iter()))
|
||||
}
|
||||
|
||||
|
|
|
@ -3470,18 +3470,26 @@ impl Parser {
|
|||
.try_reduce_call_or_acc(false)
|
||||
.map_err(|_| self.stack_dec(fn_name!()))?;
|
||||
let Expr::Call(mut call) = expect_call else {
|
||||
let caused_by = caused_by!();
|
||||
log!(err "error caused by: {caused_by}");
|
||||
let err = self.get_stream_op_syntax_error(line!() as usize, expect_call.loc(), caused_by!());
|
||||
let caused_by = caused_by!();
|
||||
log!(err "error caused by: {caused_by}");
|
||||
let err = self.get_stream_op_syntax_error(
|
||||
line!() as usize,
|
||||
expect_call.loc(),
|
||||
caused_by!(),
|
||||
);
|
||||
self.errs.push(err);
|
||||
debug_exit_info!(self);
|
||||
return Err(());
|
||||
};
|
||||
let ExprOrOp::Expr(first_arg) = stack.pop().unwrap() else {
|
||||
let caused_by = caused_by!();
|
||||
log!(err "error caused by: {caused_by}");
|
||||
self.errs
|
||||
.push(ParseError::compiler_bug(line!() as usize, call.loc(), fn_name!(), line!()));
|
||||
let caused_by = caused_by!();
|
||||
log!(err "error caused by: {caused_by}");
|
||||
self.errs.push(ParseError::compiler_bug(
|
||||
line!() as usize,
|
||||
call.loc(),
|
||||
fn_name!(),
|
||||
line!(),
|
||||
));
|
||||
debug_exit_info!(self);
|
||||
return Err(());
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue