mirror of
https://github.com/Noratrieb/mono-fmt.git
synced 2026-01-14 15:25:08 +01:00
clippy
This commit is contained in:
parent
81f0b8d9cd
commit
db1f1a5ad7
4 changed files with 25 additions and 22 deletions
|
|
@ -53,7 +53,7 @@ impl Parse for Input {
|
||||||
|
|
||||||
enum FmtPart {
|
enum FmtPart {
|
||||||
Literal(Ident, String),
|
Literal(Ident, String),
|
||||||
Spec(Ident, FmtSpec, Expr),
|
Spec(Ident, FmtSpec, Box<Expr>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for FmtPart {
|
impl std::fmt::Debug for FmtPart {
|
||||||
|
|
@ -101,7 +101,7 @@ where
|
||||||
let argument = self.fmt_spec()?;
|
let argument = self.fmt_spec()?;
|
||||||
let expr = self.expect_expr();
|
let expr = self.expect_expr();
|
||||||
self.fmt_parts
|
self.fmt_parts
|
||||||
.push(FmtPart::Spec(self.crate_ident.clone(), argument, expr));
|
.push(FmtPart::Spec(self.crate_ident.clone(), argument, Box::new(expr)));
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
next_string.push(other);
|
next_string.push(other);
|
||||||
|
|
@ -230,6 +230,11 @@ mod tests {
|
||||||
syn::parse_str("1").unwrap()
|
syn::parse_str("1").unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn fake_expr_box() -> Box<Expr> {
|
||||||
|
Box::new(syn::parse_str("1").unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
fn fake_exprs(count: usize) -> Vec<Expr> {
|
fn fake_exprs(count: usize) -> Vec<Expr> {
|
||||||
vec![fake_expr(); count]
|
vec![fake_expr(); count]
|
||||||
}
|
}
|
||||||
|
|
@ -258,7 +263,7 @@ mod tests {
|
||||||
FmtSpec {
|
FmtSpec {
|
||||||
..FmtSpec::default()
|
..FmtSpec::default()
|
||||||
},
|
},
|
||||||
fake_expr()
|
fake_expr_box()
|
||||||
)]
|
)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -274,7 +279,7 @@ mod tests {
|
||||||
kind: FmtType::Debug,
|
kind: FmtType::Debug,
|
||||||
..FmtSpec::default()
|
..FmtSpec::default()
|
||||||
},
|
},
|
||||||
fake_expr()
|
fake_expr_box()
|
||||||
)]
|
)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -295,7 +300,7 @@ mod tests {
|
||||||
kind: FmtType::Debug,
|
kind: FmtType::Debug,
|
||||||
..FmtSpec::default()
|
..FmtSpec::default()
|
||||||
},
|
},
|
||||||
fake_expr()
|
fake_expr_box()
|
||||||
)]
|
)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ impl Error {
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Alignment {
|
pub enum Alignment {
|
||||||
Left,
|
Left,
|
||||||
Center,
|
Center,
|
||||||
|
|
@ -33,13 +33,13 @@ impl Alignment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct Align {
|
pub struct Align {
|
||||||
pub kind: Alignment,
|
pub kind: Alignment,
|
||||||
pub fill: Option<char>,
|
pub fill: Option<char>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
#[derive(Debug, PartialEq, Eq, Default)]
|
||||||
pub enum Argument {
|
pub enum Argument {
|
||||||
#[default]
|
#[default]
|
||||||
Positional,
|
Positional,
|
||||||
|
|
@ -47,7 +47,7 @@ pub enum Argument {
|
||||||
Keyword(String),
|
Keyword(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
#[derive(Debug, PartialEq, Eq, Default)]
|
||||||
pub enum FmtType {
|
pub enum FmtType {
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
|
@ -57,13 +57,13 @@ pub enum FmtType {
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Precision {
|
pub enum Precision {
|
||||||
Num(usize),
|
Num(usize),
|
||||||
Asterisk,
|
Asterisk,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
#[derive(Debug, PartialEq, Eq, Default)]
|
||||||
pub struct FmtSpec {
|
pub struct FmtSpec {
|
||||||
pub arg: Argument,
|
pub arg: Argument,
|
||||||
pub align: Option<Align>,
|
pub align: Option<Align>,
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,10 @@ mod numfmt {
|
||||||
} else {
|
} else {
|
||||||
3
|
3
|
||||||
}
|
}
|
||||||
|
} else if v < 10_000 {
|
||||||
|
4
|
||||||
} else {
|
} else {
|
||||||
if v < 10_000 {
|
5
|
||||||
4
|
|
||||||
} else {
|
|
||||||
5
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Part::Copy(buf) => buf.len(),
|
Part::Copy(buf) => buf.len(),
|
||||||
|
|
@ -223,15 +221,15 @@ impl<W: Write, O: FmtOpts> Formatter<W, O> {
|
||||||
|
|
||||||
// remaining parts go through the ordinary padding process.
|
// remaining parts go through the ordinary padding process.
|
||||||
let len = formatted.len();
|
let len = formatted.len();
|
||||||
let ret = if width <= len {
|
|
||||||
|
if width <= len {
|
||||||
// no padding
|
// no padding
|
||||||
self.write_formatted_parts(&formatted)
|
self.write_formatted_parts(&formatted)
|
||||||
} else {
|
} else {
|
||||||
let post_padding = self.padding(width - len, the_align, the_fill, the_align)?;
|
let post_padding = self.padding(width - len, the_align, the_fill, the_align)?;
|
||||||
self.write_formatted_parts(&formatted)?;
|
self.write_formatted_parts(&formatted)?;
|
||||||
post_padding.write(self)
|
post_padding.write(self)
|
||||||
};
|
}
|
||||||
ret
|
|
||||||
} else {
|
} else {
|
||||||
// this is the common case and we take a shortcut
|
// this is the common case and we take a shortcut
|
||||||
self.write_formatted_parts(formatted)
|
self.write_formatted_parts(formatted)
|
||||||
|
|
|
||||||
|
|
@ -502,7 +502,7 @@ fn parse_u64_into<const N: usize>(mut n: u64, buf: &mut [MaybeUninit<u8>; N], cu
|
||||||
|
|
||||||
*curr -= 16;
|
*curr -= 16;
|
||||||
|
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr + 0), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr), 2);
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2);
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d3 as isize), buf_ptr.offset(*curr + 4), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d3 as isize), buf_ptr.offset(*curr + 4), 2);
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d4 as isize), buf_ptr.offset(*curr + 6), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d4 as isize), buf_ptr.offset(*curr + 6), 2);
|
||||||
|
|
@ -522,7 +522,7 @@ fn parse_u64_into<const N: usize>(mut n: u64, buf: &mut [MaybeUninit<u8>; N], cu
|
||||||
let d4 = ((to_parse / 1e0 as u64) % 100) << 1;
|
let d4 = ((to_parse / 1e0 as u64) % 100) << 1;
|
||||||
*curr -= 8;
|
*curr -= 8;
|
||||||
|
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr + 0), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr), 2);
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2);
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d3 as isize), buf_ptr.offset(*curr + 4), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d3 as isize), buf_ptr.offset(*curr + 4), 2);
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d4 as isize), buf_ptr.offset(*curr + 6), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d4 as isize), buf_ptr.offset(*curr + 6), 2);
|
||||||
|
|
@ -537,7 +537,7 @@ fn parse_u64_into<const N: usize>(mut n: u64, buf: &mut [MaybeUninit<u8>; N], cu
|
||||||
let d2 = (to_parse % 100) << 1;
|
let d2 = (to_parse % 100) << 1;
|
||||||
*curr -= 4;
|
*curr -= 4;
|
||||||
|
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr + 0), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr), 2);
|
||||||
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2);
|
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue