fix: clippy warnings

This commit is contained in:
Shunsuke Shibayama 2024-09-06 13:56:28 +09:00
parent 9d684d33cc
commit cd2a741fc6
7 changed files with 36 additions and 65 deletions

View file

@ -236,7 +236,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
Some("quickfix") => self.send_quick_fix(&params)?,
None => self.send_normal_action(&params)?,
Some(other) => {
self.send_log(&format!("Unknown code action requested: {other}"))?;
self.send_log(format!("Unknown code action requested: {other}"))?;
vec![]
}
};

View file

@ -580,7 +580,7 @@ fn format_context<E: ErrorDisplay + ?Sized>(
let (vbreak, vbar) = chars.gutters();
let offset = format!("{} {} ", &" ".repeat(max_digit), vbreak);
for (i, lineno) in (ln_begin..=ln_end).enumerate() {
context.push_str_with_color(&format!("{lineno:<max_digit$} {vbar} "), gutter_color);
context.push_str_with_color(format!("{lineno:<max_digit$} {vbar} "), gutter_color);
let not_found = "???".to_string();
let code = codes.get(i).unwrap_or(&not_found);
context.push_str(code);
@ -745,11 +745,11 @@ impl SubMessage {
let codes = e.input().reread_lines(ln_begin as usize, ln_end as usize);
let mark = mark.to_string();
for (i, lineno) in (ln_begin..=ln_end).enumerate() {
cxt.push_str_with_color(&format!("{lineno} {vbar} "), gutter_color);
cxt.push_str_with_color(format!("{lineno} {vbar} "), gutter_color);
cxt.push_str(codes.get(i).unwrap_or(&String::new()));
cxt.push_str("\n");
cxt.push_str_with_color(
&format!("{} {}", &" ".repeat(lineno.to_string().len()), vbreak),
format!("{} {}", &" ".repeat(lineno.to_string().len()), vbreak),
gutter_color,
);
cxt.push_str(&" ".repeat(lineno.to_string().len()));
@ -774,7 +774,7 @@ impl SubMessage {
let default = "???".to_string();
let code = codes.first().unwrap_or(&default);
let mut cxt = StyledStrings::default();
cxt.push_str_with_color(&format!(" {lineno} {vbar} "), gutter_color);
cxt.push_str_with_color(format!(" {lineno} {vbar} "), gutter_color);
cxt.push_str(code);
cxt.push_str("\n");
for msg in self.msg.iter() {
@ -793,7 +793,7 @@ impl SubMessage {
_other => {
let (_, vbar) = chars.gutters();
let mut cxt = StyledStrings::default();
cxt.push_str_with_color(&format!(" ? {vbar} "), gutter_color);
cxt.push_str_with_color(format!(" ? {vbar} "), gutter_color);
cxt.push_str(&e.input().reread());
cxt.push_str("\n");
for msg in self.msg.iter() {

View file

@ -883,9 +883,8 @@ impl Context {
// TODO: set params
let kind = ContextKind::from(def);
self.grow(__name__, kind, vis, tv_cache);
let obj = self.eval_const_block(&def.body.block).map_err(|errs| {
let obj = self.eval_const_block(&def.body.block).inspect_err(|_| {
self.pop();
errs
})?;
let call = if let Some(Expr::Call(call)) = &def.body.block.first() {
Some(call)
@ -3369,10 +3368,7 @@ impl Context {
if lhs != coerced {
let proj = proj_call(coerced, attr_name, args);
self.eval_t_params(proj, level, t_loc)
.map(|t| {
lhs.destructive_coerce();
t
})
.inspect(|_t| lhs.destructive_coerce())
.map_err(|(_, errs)| errs)
} else {
let proj = proj_call(lhs, attr_name, args);

View file

@ -1244,46 +1244,36 @@ impl<'c, 'q, 'l, L: Locational> Dereferencer<'c, 'q, 'l, L> {
);
for param in subr.non_default_params.iter_mut() {
_self.push_variance(Contravariant);
*param.typ_mut() = _self.deref_tyvar(mem::take(param.typ_mut())).map_err(|e| {
_self.pop_variance();
e
})?;
*param.typ_mut() = _self
.deref_tyvar(mem::take(param.typ_mut()))
.inspect_err(|_e| _self.pop_variance())?;
_self.pop_variance();
}
if let Some(var_args) = &mut subr.var_params {
_self.push_variance(Contravariant);
*var_args.typ_mut() =
_self
.deref_tyvar(mem::take(var_args.typ_mut()))
.map_err(|e| {
_self.pop_variance();
e
})?;
*var_args.typ_mut() = _self
.deref_tyvar(mem::take(var_args.typ_mut()))
.inspect_err(|_e| _self.pop_variance())?;
_self.pop_variance();
}
for d_param in subr.default_params.iter_mut() {
_self.push_variance(Contravariant);
*d_param.typ_mut() = _self
.deref_tyvar(mem::take(d_param.typ_mut()))
.map_err(|e| {
.inspect_err(|_e| {
_self.pop_variance();
e
})?;
if let Some(default) = d_param.default_typ_mut() {
*default = _self.deref_tyvar(mem::take(default)).map_err(|e| {
_self.pop_variance();
e
})?;
*default = _self
.deref_tyvar(mem::take(default))
.inspect_err(|_e| _self.pop_variance())?;
}
_self.pop_variance();
}
_self.push_variance(Covariant);
*subr.return_t = _self
.deref_tyvar(mem::take(&mut subr.return_t))
.map_err(|e| {
_self.pop_variance();
e
})?;
.inspect_err(|_e| _self.pop_variance())?;
_self.pop_variance();
let subr = Type::Subr(subr);
if subr.has_qvar() {

View file

@ -1319,11 +1319,9 @@ impl Context {
ty
}
};
self.sub_unify(&const_t, &spec_t, &def.body, None)
.map_err(|errs| {
self.pop();
errs
})?;
if let Err(es) = self.sub_unify(&const_t, &spec_t, &def.body, None) {
errs.extend(es);
}
}
self.pop();
if let Err(es) = self.register_gen_const(
@ -1384,11 +1382,9 @@ impl Context {
ty
}
};
self.sub_unify(&const_t, &spec_t, &def.body, None)
.map_err(|errs| {
self.pop();
errs
})?;
if let Err(es) = self.sub_unify(&const_t, &spec_t, &def.body, None) {
errs.extend(es);
}
}
self.pop();
if let Some(ident) = sig.ident() {

View file

@ -977,10 +977,8 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
log!(info "no-op:\nmaybe_sub: {maybe_sub}\nmaybe_sup: {maybe_sup}");
return Ok(());
}
self.occur(maybe_sub, maybe_sup).map_err(|err| {
log!(err "occur error: {maybe_sub} / {maybe_sup}");
err
})?;
self.occur(maybe_sub, maybe_sup)
.inspect_err(|_e| log!(err "occur error: {maybe_sub} / {maybe_sup}"))?;
let maybe_sub_is_sub = self.ctx.subtype_of(maybe_sub, maybe_sup);
if !maybe_sub_is_sub {
log!(err "{maybe_sub} !<: {maybe_sup}");
@ -1030,10 +1028,9 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
sub_fv.dummy_link();
if lsub.qual_name() == rsub.qual_name() {
for (lps, rps) in lsub.typarams().iter().zip(rsub.typarams().iter()) {
self.sub_unify_tp(lps, rps, None, false).map_err(|errs| {
self.sub_unify_tp(lps, rps, None, false).inspect_err(|_e| {
sup_fv.undo();
sub_fv.undo();
errs
})?;
}
}
@ -1041,10 +1038,9 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
// => lsup: Add(?X(:> Int)), rsup: Add((?X(:> Int)))
if lsup.qual_name() == rsup.qual_name() {
for (lps, rps) in lsup.typarams().iter().zip(rsup.typarams().iter()) {
self.sub_unify_tp(lps, rps, None, false).map_err(|errs| {
self.sub_unify_tp(lps, rps, None, false).inspect_err(|_e| {
sup_fv.undo();
sub_fv.undo();
errs
})?;
}
}
@ -1138,20 +1134,16 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
sup_fv.dummy_link();
if lsub.qual_name() == rsub.qual_name() {
for (lps, rps) in lsub.typarams().iter().zip(rsub.typarams().iter()) {
self.sub_unify_tp(lps, rps, None, false).map_err(|errs| {
sup_fv.undo();
errs
})?;
self.sub_unify_tp(lps, rps, None, false)
.inspect_err(|_e| sup_fv.undo())?;
}
}
// lsup: Add(?X(:> Int)), rsup: Add(?Y(:> Nat))
// => lsup: Add(?X(:> Int)), rsup: Add((?X(:> Int)))
if lsup.qual_name() == rsup.qual_name() {
for (lps, rps) in lsup.typarams().iter().zip(rsup.typarams().iter()) {
self.sub_unify_tp(lps, rps, None, false).map_err(|errs| {
sup_fv.undo();
errs
})?;
self.sub_unify_tp(lps, rps, None, false)
.inspect_err(|_e| sup_fv.undo())?;
}
}
sup_fv.undo();
@ -1302,10 +1294,8 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
for (sup_field, sup_ty) in self.ctx.fields(struct_sup) {
sub_fv.dummy_link();
if let Some((_, sub_ty)) = sub_fields.get_key_value(&sup_field) {
self.sub_unify(sub_ty, &sup_ty).map_err(|errs| {
sub_fv.undo();
errs
})?;
self.sub_unify(sub_ty, &sup_ty)
.inspect_err(|_e| sub_fv.undo())?;
} else if !self.ctx.subtype_of(&sub, &Never) {
sub_fv.undo();
maybe_sub.coerce(self.undoable);

View file

@ -1041,10 +1041,9 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
let imp = self.module.context.register_trait_impl(&class, sup, ident);
imp.and(tmp.register_trait(&self.module.context, sup.clone()))
};
res.map_err(|err| {
res.inspect_err(|_err| {
let ctx = self.module.context.rec_get_mut_type(&name).unwrap();
mem::swap(ctx, &mut tmp);
err
})?;
let ctx = self.module.context.rec_get_mut_type(&name).unwrap();
mem::swap(ctx, &mut tmp);