From 891e0c5fa6cd9200c24011c33b6f2115d84d4d74 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 10 Jul 2021 20:42:28 +0200 Subject: Remove warnings from parsing and casting --- src/eval/function.rs | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'src/eval/function.rs') diff --git a/src/eval/function.rs b/src/eval/function.rs index c986d71a..28a62873 100644 --- a/src/eval/function.rs +++ b/src/eval/function.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Formatter}; use std::ops::Deref; use std::rc::Rc; -use super::{Cast, CastResult, EvalContext, Value}; +use super::{Cast, EvalContext, Value}; use crate::eco::EcoString; use crate::syntax::{Span, Spanned}; @@ -76,7 +76,7 @@ pub struct FuncArg { impl FuncArgs { /// Find and consume the first castable positional argument. - pub fn eat(&mut self, ctx: &mut EvalContext) -> Option + pub fn eat(&mut self) -> Option where T: Cast>, { @@ -87,19 +87,12 @@ impl FuncArgs { } let value = std::mem::replace(&mut slot.value, Spanned::zero(Value::None)); - let span = value.span; - match T::cast(value) { - CastResult::Ok(t) => { - self.items.remove(index); - Some(t) - } - CastResult::Warn(t, m) => { + Ok(t) => { self.items.remove(index); - ctx.diag(warning!(span, "{}", m)); Some(t) } - CastResult::Err(value) => { + Err(value) => { slot.value = value; None } @@ -113,7 +106,7 @@ impl FuncArgs { where T: Cast>, { - let found = self.eat(ctx); + let found = self.eat(); if found.is_none() { ctx.diag(error!(self.span, "missing argument: {}", what)); } @@ -121,16 +114,11 @@ impl FuncArgs { } /// Find, consume and collect all castable positional arguments. - /// - /// This function returns a vector instead of an iterator because the - /// iterator would require unique access to the context, rendering it rather - /// unusable. If you need to process arguments one-by-one, you probably want - /// to use a while-let loop together with [`eat()`](Self::eat). - pub fn all(&mut self, ctx: &mut EvalContext) -> Vec + pub fn all(&mut self) -> impl Iterator + '_ where T: Cast>, { - std::iter::from_fn(|| self.eat(ctx)).collect() + std::iter::from_fn(move || self.eat()) } /// Cast and remove the value for the given named argument, producing an @@ -148,12 +136,8 @@ impl FuncArgs { let span = value.span; match T::cast(value) { - CastResult::Ok(t) => Some(t), - CastResult::Warn(t, m) => { - ctx.diag(warning!(span, "{}", m)); - Some(t) - } - CastResult::Err(value) => { + Ok(t) => Some(t), + Err(value) => { ctx.diag(error!( span, "expected {}, found {}", -- cgit v1.2.3