many clippy fixes

This commit is contained in:
Anton-4 2023-04-24 16:21:46 +02:00
parent 7bbb37a843
commit 9748e4a4dc
No known key found for this signature in database
GPG key ID: 0971D718C0A9B937
17 changed files with 455 additions and 600 deletions

View file

@ -65,13 +65,7 @@ impl Newlines {
pub trait Formattable {
fn is_multiline(&self) -> bool;
fn format_with_options(
&self,
buf: &mut Buf,
_parens: Parens,
_newlines: Newlines,
indent: u16,
);
fn format_with_options(&self, buf: &mut Buf, _parens: Parens, _newlines: Newlines, indent: u16);
fn format(&self, buf: &mut Buf, indent: u16) {
self.format_with_options(buf, Parens::NotNeeded, Newlines::No, indent);
@ -87,13 +81,7 @@ where
(*self).is_multiline()
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
(*self).format_with_options(buf, parens, newlines, indent)
}
@ -120,13 +108,7 @@ where
self.value.is_multiline()
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
self.value
.format_with_options(buf, parens, newlines, indent)
}
@ -206,13 +188,7 @@ impl<'a> Formattable for TypeAnnotation<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
use roc_parse::ast::TypeAnnotation::*;
let self_is_multiline = self.is_multiline();
@ -424,13 +400,7 @@ impl<'a> Formattable for AssignedField<'a, TypeAnnotation<'a>> {
is_multiline_assigned_field_help(self)
}
fn format_with_options(
&self,
buf: &mut Buf,
_parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, _parens: Parens, newlines: Newlines, indent: u16) {
// we abuse the `Newlines` type to decide between multiline or single-line layout
format_assigned_field_help(self, buf, indent, 1, newlines == Newlines::Yes);
}
@ -441,13 +411,7 @@ impl<'a> Formattable for AssignedField<'a, Expr<'a>> {
is_multiline_assigned_field_help(self)
}
fn format_with_options(
&self,
buf: &mut Buf,
_parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, _parens: Parens, newlines: Newlines, indent: u16) {
// we abuse the `Newlines` type to decide between multiline or single-line layout
format_assigned_field_help(self, buf, indent, 0, newlines == Newlines::Yes);
}
@ -592,13 +556,7 @@ impl<'a> Formattable for HasClause<'a> {
false
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
buf.push_str(self.var.value.extract_spaces().item);
buf.spaces(1);
buf.push_str("has");
@ -623,13 +581,7 @@ impl<'a> Formattable for HasImpls<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
match self {
HasImpls::HasImpls(impls) => {
if newlines == Newlines::Yes {
@ -662,13 +614,7 @@ impl<'a> Formattable for HasAbility<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
match self {
HasAbility::HasAbility { ability, impls } => {
if newlines == Newlines::Yes {
@ -703,13 +649,7 @@ impl<'a> Formattable for HasAbilities<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
match self {
HasAbilities::Has(has_abilities) => {
if newlines == Newlines::Yes {

View file

@ -57,13 +57,7 @@ impl<'a> Formattable for TypeDef<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
_parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, _parens: Parens, newlines: Newlines, indent: u16) {
use roc_parse::ast::TypeDef::*;
match self {
@ -205,13 +199,7 @@ impl<'a> Formattable for ValueDef<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
_parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, _parens: Parens, newlines: Newlines, indent: u16) {
use roc_parse::ast::ValueDef::*;
match self {
Annotation(loc_pattern, loc_annotation) => {
@ -335,12 +323,7 @@ fn fmt_dbg_in_def<'a>(
condition.format(buf, return_indent);
}
fn fmt_expect<'a>(
buf: &mut Buf,
condition: &'a Loc<Expr<'a>>,
is_multiline: bool,
indent: u16,
) {
fn fmt_expect<'a>(buf: &mut Buf, condition: &'a Loc<Expr<'a>>, is_multiline: bool, indent: u16) {
buf.ensure_ends_with_newline();
buf.indent(indent);
buf.push_str("expect");
@ -356,12 +339,7 @@ fn fmt_expect<'a>(
condition.format(buf, return_indent);
}
fn fmt_expect_fx<'a>(
buf: &mut Buf,
condition: &'a Loc<Expr<'a>>,
is_multiline: bool,
indent: u16,
) {
fn fmt_expect_fx<'a>(buf: &mut Buf, condition: &'a Loc<Expr<'a>>, is_multiline: bool, indent: u16) {
buf.ensure_ends_with_newline();
buf.indent(indent);
buf.push_str("expect-fx");
@ -377,11 +355,7 @@ fn fmt_expect_fx<'a>(
condition.format(buf, return_indent);
}
pub fn fmt_value_def(
buf: &mut Buf,
def: &roc_parse::ast::ValueDef,
indent: u16,
) {
pub fn fmt_value_def(buf: &mut Buf, def: &roc_parse::ast::ValueDef, indent: u16) {
def.format(buf, indent);
}
@ -393,12 +367,7 @@ pub fn fmt_defs(buf: &mut Buf, defs: &Defs, indent: u16) {
defs.format(buf, indent);
}
pub fn fmt_body<'a>(
buf: &mut Buf,
pattern: &'a Pattern<'a>,
body: &'a Expr<'a>,
indent: u16,
) {
pub fn fmt_body<'a>(buf: &mut Buf, pattern: &'a Pattern<'a>, body: &'a Expr<'a>, indent: u16) {
pattern.format_with_options(buf, Parens::InApply, Newlines::No, indent);
buf.indent(indent);
buf.push_str(" =");

View file

@ -103,13 +103,7 @@ impl<'a> Formattable for Expr<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
use self::Expr::*;
let apply_needs_parens = parens == Parens::InApply;
@ -704,12 +698,7 @@ fn fmt_binops<'a>(
loc_right_side.format_with_options(buf, Parens::InOperator, Newlines::Yes, indent);
}
fn format_spaces(
buf: &mut Buf,
spaces: &[CommentOrNewline],
newlines: Newlines,
indent: u16,
) {
fn format_spaces(buf: &mut Buf, spaces: &[CommentOrNewline], newlines: Newlines, indent: u16) {
match newlines {
Newlines::Yes => {
fmt_spaces(buf, spaces.iter(), indent);

View file

@ -164,13 +164,7 @@ impl<'a, K: Formattable, V: Formattable> Formattable for KeywordItem<'a, K, V> {
self.keyword.is_multiline() || self.item.is_multiline()
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
self.keyword
.format_with_options(buf, parens, newlines, indent);
self.item.format_with_options(buf, parens, newlines, indent);

View file

@ -4,12 +4,7 @@ use crate::spaces::{fmt_comments_only, fmt_spaces, NewlineAt, INDENT};
use crate::Buf;
use roc_parse::ast::{Base, CommentOrNewline, Pattern, PatternAs};
pub fn fmt_pattern<'a>(
buf: &mut Buf,
pattern: &'a Pattern<'a>,
indent: u16,
parens: Parens,
) {
pub fn fmt_pattern<'a>(buf: &mut Buf, pattern: &'a Pattern<'a>, indent: u16, parens: Parens) {
pattern.format_with_options(buf, parens, Newlines::No, indent);
}
@ -85,13 +80,7 @@ impl<'a> Formattable for Pattern<'a> {
}
}
fn format_with_options(
&self,
buf: &mut Buf,
parens: Parens,
newlines: Newlines,
indent: u16,
) {
fn format_with_options(&self, buf: &mut Buf, parens: Parens, newlines: Newlines, indent: u16) {
use self::Pattern::*;
match self {

View file

@ -21,22 +21,14 @@ use crate::{Ast, Buf};
/// The number of spaces to indent.
pub const INDENT: u16 = 4;
pub fn fmt_default_spaces(
buf: &mut Buf,
spaces: &[CommentOrNewline],
indent: u16,
) {
pub fn fmt_default_spaces(buf: &mut Buf, spaces: &[CommentOrNewline], indent: u16) {
if spaces.is_empty() {
buf.spaces(1);
} else {
fmt_spaces(buf, spaces.iter(), indent);
}
}
pub fn fmt_default_newline(
buf: &mut Buf,
spaces: &[CommentOrNewline],
indent: u16,
) {
pub fn fmt_default_newline(buf: &mut Buf, spaces: &[CommentOrNewline], indent: u16) {
if spaces.is_empty() {
buf.newline();
} else {