treewide: enforce strict clippy check
This commit is contained in:
@@ -8,3 +8,6 @@ ere = { workspace = true }
|
||||
gc-arena = { workspace = true }
|
||||
num_enum = { workspace = true }
|
||||
string-interner = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
+42
-6
@@ -8,7 +8,7 @@ use num_enum::TryFromPrimitive;
|
||||
|
||||
macro_rules! define_builtins {
|
||||
($(($name:literal, $variant:ident, $arity:expr)),* $(,)?) => {
|
||||
pub const BUILTINS: &[(&str, u8)] = &[
|
||||
const BUILTINS: &[(&str, u8)] = &[
|
||||
$(($name, $arity),)*
|
||||
];
|
||||
|
||||
@@ -18,6 +18,10 @@ macro_rules! define_builtins {
|
||||
pub enum BuiltinId {
|
||||
$($variant,)*
|
||||
}
|
||||
|
||||
impl BuiltinId {
|
||||
pub const ALL: [Self; BUILTINS.len()] = [$(Self::$variant,)*];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,6 +131,36 @@ define_builtins! {
|
||||
("__zipAttrsWith", ZipAttrsWith, 2),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct BuiltinInfo {
|
||||
pub name: &'static str,
|
||||
pub global_name: &'static str,
|
||||
pub global: bool,
|
||||
pub arity: u8,
|
||||
}
|
||||
|
||||
impl BuiltinId {
|
||||
pub const TOTAL: usize = BUILTINS.len();
|
||||
|
||||
#[expect(
|
||||
clippy::indexing_slicing,
|
||||
reason = "a `BuiltinId` discriminant is always a valid index into the `BUILTINS` table"
|
||||
)]
|
||||
#[inline(always)]
|
||||
pub fn info(self) -> BuiltinInfo {
|
||||
let (global_name, arity) = BUILTINS[self as usize];
|
||||
let (name, global) = global_name
|
||||
.strip_prefix("__")
|
||||
.map_or((global_name, true), |name| (name, false));
|
||||
BuiltinInfo {
|
||||
name,
|
||||
global_name,
|
||||
global,
|
||||
arity,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Collect)]
|
||||
#[collect(require_static)]
|
||||
@@ -427,6 +461,10 @@ fn fmt_nix_float(f: &mut Formatter<'_>, x: f64) -> FmtResult {
|
||||
let precision: i32 = 6;
|
||||
let exp = x.abs().log10().floor() as i32;
|
||||
|
||||
#[expect(
|
||||
clippy::cast_sign_loss,
|
||||
reason = "this branch runs only when exp < precision, so precision-1-exp and precision-1 are non-negative"
|
||||
)]
|
||||
let formatted = if exp >= -4 && exp < precision {
|
||||
let decimal_places = (precision - 1 - exp) as usize;
|
||||
format!("{x:.decimal_places$}")
|
||||
@@ -451,11 +489,9 @@ fn fmt_nix_float(f: &mut Formatter<'_>, x: f64) -> FmtResult {
|
||||
};
|
||||
|
||||
if formatted.contains('.') {
|
||||
if let Some(e_pos) = formatted.find('e') {
|
||||
let trimmed = formatted[..e_pos]
|
||||
.trim_end_matches('0')
|
||||
.trim_end_matches('.');
|
||||
write!(f, "{}{}", trimmed, &formatted[e_pos..])
|
||||
if let Some((head, tail)) = formatted.split_once('e') {
|
||||
let trimmed = head.trim_end_matches('0').trim_end_matches('.');
|
||||
write!(f, "{trimmed}e{tail}")
|
||||
} else {
|
||||
let trimmed = formatted.trim_end_matches('0').trim_end_matches('.');
|
||||
write!(f, "{trimmed}")
|
||||
|
||||
Reference in New Issue
Block a user