Clippy fixes

This commit is contained in:
Olivier 'reivilibre' 2025-05-14 21:37:38 +01:00
parent d08a088257
commit 845a05b720
7 changed files with 48 additions and 52 deletions

View File

@ -58,7 +58,7 @@ pub(crate) fn start_hot_reloader(
let default_locale = default_locale;
loop {
let _ = notif_rx.recv().unwrap();
notif_rx.recv().unwrap();
// Debounce, because editors often make a series of modifications and we don't
// want to reload before it's ready.

View File

@ -1,4 +1,4 @@
#![allow(non_snake_case)]
#![allow(non_snake_case, clippy::result_large_err)]
use crate::ast::{
Binding, Block, ComponentElement, DefineExpandSlot, DefineFragment, ElementAttributeFlags,
@ -78,7 +78,7 @@ impl HornbeamParser {
let mut supply_slots = Vec::new();
let mut blocks = Vec::new();
while let Some(next) = children.next() {
for next in children {
match next.as_rule() {
Rule::CssClass => {
classes.push(HornbeamParser::CssClass(next)?);
@ -570,7 +570,7 @@ impl HornbeamParser {
Ok(result)
}
fn helper_block<'a>(input: Node) -> PCResult<Option<Block>> {
fn helper_block(input: Node) -> PCResult<Option<Block>> {
Ok(match input.as_rule() {
Rule::Element => Some(HornbeamParser::Element(input)?),
Rule::Text => Some(HornbeamParser::Text(input)?),

View File

@ -222,7 +222,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
.map_err(|underlying| InterpreterError::OutputError { underlying })?;
} else {
self.output
.write(&text)
.write(text)
.await
.map_err(|underlying| InterpreterError::OutputError { underlying })?;
}
@ -294,7 +294,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
} else {
for val in list {
let mut binder = Binder::new();
binder.bind(&mut self.scopes[scope_idx].variables, &binding, val);
binder.bind(&mut self.scopes[scope_idx].variables, binding, val);
self.run_steps(scope_idx, body_steps).await?;
binder.unbind(&mut self.scopes[scope_idx].variables);
}
@ -312,7 +312,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
let mut binder = Binder::new();
binder.bind(
&mut self.scopes[scope_idx].variables,
&binding,
binding,
Value::from_reflect(val),
);
self.run_steps(scope_idx, body_steps).await?;
@ -488,7 +488,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
return if !optional {
Err(InterpreterError::TypeError {
context: format!("Required slot '{name}' not filled"),
conflict: format!("slot was left empty."),
conflict: "slot was left empty.".to_string(),
location: step.locator.clone(),
})
} else {
@ -513,8 +513,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
) -> Result<Value, InterpreterError<LS::Error, O::Error>> {
match expr {
Expression::Add { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Int(lint), Value::Int(rint)) => Ok(Value::Int(lint + rint)),
@ -526,8 +526,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::Sub { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Int(lint), Value::Int(rint)) => Ok(Value::Int(lint - rint)),
@ -539,8 +539,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::Mul { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Int(lint), Value::Int(rint)) => Ok(Value::Int(lint * rint)),
@ -552,8 +552,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::Div { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Int(lint), Value::Int(rint)) => Ok(Value::Int(lint / rint)),
@ -565,7 +565,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::Negate { sub } => {
let sval = self.evaluate_expression(scope_idx, &sub, loc)?;
let sval = self.evaluate_expression(scope_idx, sub, loc)?;
match sval {
Value::Int(sint) => Ok(Value::Int(-sint)),
@ -577,8 +577,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::BAnd { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Bool(lbool), Value::Bool(rbool)) => Ok(Value::Bool(lbool && rbool)),
@ -590,8 +590,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::BOr { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Bool(lbool), Value::Bool(rbool)) => Ok(Value::Bool(lbool || rbool)),
@ -603,7 +603,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::BNot { sub } => {
let sval = self.evaluate_expression(scope_idx, &sub, loc)?;
let sval = self.evaluate_expression(scope_idx, sub, loc)?;
match sval {
Value::Bool(sbool) => Ok(Value::Bool(!sbool)),
@ -615,8 +615,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::Equals { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Bool(lbool), Value::Bool(rbool)) => Ok(Value::Bool(lbool == rbool)),
@ -641,8 +641,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::LessThan { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Int(lint), Value::Int(rint)) => Ok(Value::Bool(lint < rint)),
@ -655,8 +655,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::LessThanOrEquals { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::Int(lint), Value::Int(rint)) => Ok(Value::Bool(lint <= rint)),
@ -669,8 +669,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
}
}
Expression::ListAdd { left, right } => {
let lval = self.evaluate_expression(scope_idx, &left, loc)?;
let rval = self.evaluate_expression(scope_idx, &right, loc)?;
let lval = self.evaluate_expression(scope_idx, left, loc)?;
let rval = self.evaluate_expression(scope_idx, right, loc)?;
match (lval, rval) {
(Value::List(mut llist), Value::List(rlist)) => {
@ -758,7 +758,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
let Some(method) = self.methods.get(ident.as_str()) else {
return Err(InterpreterError::TypeError {
context: format!("method call to {ident:?}"),
conflict: format!("No method by that name!"),
conflict: "No method by that name!".to_string(),
location: loc.clone(),
});
};
@ -838,9 +838,8 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
// too dodgy! We might want to allow this in the future, but for now let's not.
Err(InterpreterError::TypeError {
context: "String Interpolation".to_string(),
conflict: format!(
"Don't know how to write List[...] as a sensible string output."
),
conflict: "Don't know how to write List[...] as a sensible string output."
.to_string(),
location: loc.clone(),
})
}
@ -856,7 +855,7 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
) -> Result<(), InterpreterError<LS::Error, O::Error>> {
match piece {
StringPiece::Literal(lit) => {
output.push_str(&lit);
output.push_str(lit);
Ok(())
}
StringPiece::Interpolation(expr) => {

View File

@ -24,7 +24,7 @@ impl LocalisationSystem for NoLocalisation {
}
}
///
/// Localisation system that dumps debug output.
#[derive(Copy, Clone)]
pub struct DebugLocalisationSystem;

View File

@ -17,7 +17,7 @@ use thiserror::Error;
fn interpreter_value_to_fluent_value(v: &Value) -> Option<FluentValue> {
match v {
Value::Str(str) => Some(FluentValue::String(Cow::Borrowed(&str))),
Value::Str(str) => Some(FluentValue::String(Cow::Borrowed(str))),
Value::Int(int) => {
// This is an unstyled number
// TODO Support fancier numbers
@ -97,12 +97,10 @@ impl LocalisationSystem for FluentLocalisationSystem {
}
match self.fluent.lookup_with_args(&li, trans_key, &mapped_params) {
Some(val) => Ok(Cow::Owned(val)),
None => {
return Err(FluentLocalisationError::NoTranslation {
trans_key: String::from(trans_key),
lang_id: li.to_string(),
});
}
None => Err(FluentLocalisationError::NoTranslation {
trans_key: String::from(trans_key),
lang_id: li.to_string(),
}),
}
}
}

View File

@ -11,7 +11,7 @@ use std::ops::Deref;
use thiserror::Error;
/// List of all void (self-closing) HTML tags.
const VOID_TAGS: &'static [&'static str] = &[
const VOID_TAGS: &[&str] = &[
"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "menuitem", "meta",
"param", "source", "track", "wbr",
];
@ -33,7 +33,7 @@ pub enum AstToIrError {
///
/// Fragments are extracted to `{template_name}__{fragment_name}`.
/// The top-level template is extracted to `{template_name}`.
pub(crate) fn pull_out_entrypoints<'a>(
pub(crate) fn pull_out_entrypoints(
mut template: Template,
template_name: &str,
) -> Result<BTreeMap<String, Vec<Block>>, AstToIrError> {
@ -63,7 +63,7 @@ pub(crate) fn pull_out_entrypoints<'a>(
/// Extract entrypoints (template fragments) from a block (recursively), replacing them with
/// calls to that entrypoint.
fn pull_out_entrypoints_from_block<'a>(
fn pull_out_entrypoints_from_block(
block: &mut Block,
template_name: &str,
target: &mut BTreeMap<String, Vec<Block>>,

View File

@ -6,15 +6,15 @@ use crate::ir::{Step, StepDef};
use hornbeam_grammar::ast::{Expression, StringPiece};
use hornbeam_grammar::intern;
//// Peephole Machinery
/// Peephole Machinery
fn peephole<T, F: FnMut(&mut [T]) -> ()>(steps: &mut [T], peephole_width: usize, mut f: F) {
fn peephole<T, F: FnMut(&mut [T])>(steps: &mut [T], peephole_width: usize, mut f: F) {
for peephole_start in 0..(steps.len() - peephole_width + 1) {
f(&mut steps[peephole_start..peephole_start + peephole_width]);
}
}
fn peephole_opt<T, F: FnMut(&mut [Option<T>]) -> ()>(
fn peephole_opt<T, F: FnMut(&mut [Option<T>])>(
steps: &mut Vec<T>,
peephole_width: usize,
mut f: F,
@ -86,7 +86,7 @@ fn apply_peephole_pass<F: Fn(&mut Vec<Step>)>(steps: &mut Vec<Step>, pass: &F) {
}
}
//// Peephole Passes
///// Peephole Passes
/// Given a WriteEval step that just writes literals, convert it to a WriteLiteral step.
fn pass_write_eval_literal_to_write_literal(steps: &mut Vec<Step>) {
@ -157,8 +157,7 @@ fn pass_combine_write_literals(steps: &mut Vec<Step>) {
});
}
//// Apply all passes in the preferred order
/// Apply all passes in the preferred order
pub fn apply_all_peephole_passes(steps: &mut Vec<Step>) {
apply_peephole_pass(steps, &pass_write_eval_literal_to_write_literal);
apply_peephole_pass(steps, &pass_write_literal_preescape);