diff --git a/src/builtin.rs b/src/builtin.rs index 8a489fa1..66c8ec5a 100644 --- a/src/builtin.rs +++ b/src/builtin.rs @@ -57,7 +57,7 @@ macro_rules! reg_op_result1 { impl Engine<'_> { /// Register the core built-in library. pub(crate) fn register_core_lib(&mut self) { - /// Checked add + // Checked add #[cfg(not(feature = "unchecked"))] fn add(x: T, y: T) -> Result { x.checked_add(&y).ok_or_else(|| { @@ -67,7 +67,7 @@ impl Engine<'_> { ) }) } - /// Checked subtract + // Checked subtract #[cfg(not(feature = "unchecked"))] fn sub(x: T, y: T) -> Result { x.checked_sub(&y).ok_or_else(|| { @@ -77,7 +77,7 @@ impl Engine<'_> { ) }) } - /// Checked multiply + // Checked multiply #[cfg(not(feature = "unchecked"))] fn mul(x: T, y: T) -> Result { x.checked_mul(&y).ok_or_else(|| { @@ -87,7 +87,7 @@ impl Engine<'_> { ) }) } - /// Checked divide + // Checked divide #[cfg(not(feature = "unchecked"))] fn div(x: T, y: T) -> Result where @@ -108,7 +108,7 @@ impl Engine<'_> { ) }) } - /// Checked negative - e.g. -(i32::MIN) will overflow i32::MAX + // Checked negative - e.g. -(i32::MIN) will overflow i32::MAX #[cfg(not(feature = "unchecked"))] fn neg(x: T) -> Result { x.checked_neg().ok_or_else(|| { @@ -118,7 +118,7 @@ impl Engine<'_> { ) }) } - /// Checked absolute + // Checked absolute #[cfg(not(feature = "unchecked"))] fn abs(x: T) -> Result { // FIX - We don't use Signed::abs() here because, contrary to documentation, it panics @@ -134,32 +134,32 @@ impl Engine<'_> { }) } } - /// Unchecked add - may panic on overflow + // Unchecked add - may panic on overflow #[cfg(any(feature = "unchecked", not(feature = "no_float")))] fn add_u(x: T, y: T) -> ::Output { x + y } - /// Unchecked subtract - may panic on underflow + // Unchecked subtract - may panic on underflow #[cfg(any(feature = "unchecked", not(feature = "no_float")))] fn sub_u(x: T, y: T) -> ::Output { x - y } - /// Unchecked multiply - may panic on overflow + // Unchecked multiply - may panic on overflow #[cfg(any(feature = "unchecked", not(feature = "no_float")))] fn mul_u(x: T, y: T) -> ::Output { x * y } - /// Unchecked divide - may panic when dividing by zero + // Unchecked divide - may panic when dividing by zero #[cfg(any(feature = "unchecked", not(feature = "no_float")))] fn div_u(x: T, y: T) -> ::Output { x / y } - /// Unchecked negative - may panic on overflow + // Unchecked negative - may panic on overflow #[cfg(any(feature = "unchecked", not(feature = "no_float")))] fn neg_u(x: T) -> ::Output { -x } - /// Unchecked absolute - may panic on overflow + // Unchecked absolute - may panic on overflow #[cfg(any(feature = "unchecked", not(feature = "no_float")))] fn abs_u(x: T) -> ::Output where @@ -174,7 +174,6 @@ impl Engine<'_> { } // Comparison operators - fn lt(x: T, y: T) -> bool { x < y } @@ -195,7 +194,6 @@ impl Engine<'_> { } // Logic operators - fn and(x: bool, y: bool) -> bool { x && y } @@ -207,7 +205,6 @@ impl Engine<'_> { } // Bit operators - fn binary_and(x: T, y: T) -> ::Output { x & y } @@ -218,7 +215,7 @@ impl Engine<'_> { x ^ y } - /// Checked left-shift + // Checked left-shift #[cfg(not(feature = "unchecked"))] fn shl(x: T, y: INT) -> Result { // Cannot shift by a negative number of bits @@ -236,7 +233,7 @@ impl Engine<'_> { ) }) } - /// Checked right-shift + // Checked right-shift #[cfg(not(feature = "unchecked"))] fn shr(x: T, y: INT) -> Result { // Cannot shift by a negative number of bits @@ -254,17 +251,17 @@ impl Engine<'_> { ) }) } - /// Unchecked left-shift - may panic if shifting by a negative number of bits + // Unchecked left-shift - may panic if shifting by a negative number of bits #[cfg(feature = "unchecked")] fn shl_u>(x: T, y: T) -> >::Output { x.shl(y) } - /// Unchecked right-shift - may panic if shifting by a negative number of bits + // Unchecked right-shift - may panic if shifting by a negative number of bits #[cfg(feature = "unchecked")] fn shr_u>(x: T, y: T) -> >::Output { x.shr(y) } - /// Checked modulo + // Checked modulo #[cfg(not(feature = "unchecked"))] fn modulo(x: T, y: T) -> Result { x.checked_rem(&y).ok_or_else(|| { @@ -274,12 +271,12 @@ impl Engine<'_> { ) }) } - /// Unchecked modulo - may panic if dividing by zero + // Unchecked modulo - may panic if dividing by zero #[cfg(any(feature = "unchecked", not(feature = "no_float")))] fn modulo_u(x: T, y: T) -> ::Output { x % y } - /// Checked power + // Checked power #[cfg(not(feature = "unchecked"))] fn pow_i_i(x: INT, y: INT) -> Result { #[cfg(not(feature = "only_i32"))] @@ -321,17 +318,17 @@ impl Engine<'_> { } } } - /// Unchecked integer power - may panic on overflow or if the power index is too high (> u32::MAX) + // Unchecked integer power - may panic on overflow or if the power index is too high (> u32::MAX) #[cfg(feature = "unchecked")] fn pow_i_i_u(x: INT, y: INT) -> INT { x.pow(y as u32) } - /// Floating-point power - always well-defined + // Floating-point power - always well-defined #[cfg(not(feature = "no_float"))] fn pow_f_f(x: FLOAT, y: FLOAT) -> FLOAT { x.powf(y) } - /// Checked power + // Checked power #[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "no_float"))] fn pow_f_i(x: FLOAT, y: INT) -> Result { @@ -345,7 +342,7 @@ impl Engine<'_> { Ok(x.powi(y as i32)) } - /// Unchecked power - may be incorrect if the power index is too high (> i32::MAX) + // Unchecked power - may be incorrect if the power index is too high (> i32::MAX) #[cfg(feature = "unchecked")] #[cfg(not(feature = "no_float"))] fn pow_f_i_u(x: FLOAT, y: INT) -> FLOAT { @@ -432,7 +429,8 @@ impl Engine<'_> { } } - // `&&` and `||` are treated specially as they short-circuit + // `&&` and `||` are treated specially as they short-circuit. + // They are implemented as special `Expr` instances, not function calls. //reg_op!(self, "||", or, bool); //reg_op!(self, "&&", and, bool); diff --git a/src/error.rs b/src/error.rs index 8937ffb1..e1b41510 100644 --- a/src/error.rs +++ b/src/error.rs @@ -96,9 +96,12 @@ pub enum ParseErrorType { } impl ParseErrorType { + /// Make a `ParseError` using the current type and position. pub(crate) fn into_err(self, pos: Position) -> ParseError { ParseError(self, pos) } + + /// Make a `ParseError` using the current type and EOF position. pub(crate) fn into_err_eof(self) -> ParseError { ParseError(self, Position::eof()) }