X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=rust%2Fsrc%2Fformat.rs;h=34798ed65af54c5072f717de94381fdd74827414;hb=6165ed413d9aa818e3246d0a063c646dc4efc7e5;hp=0fc82a3987670b0cf08b79e1d386df78057d0a5d;hpb=4a37f273df6dc6a1ed9788986ce7d9908445a458;p=pspp diff --git a/rust/src/format.rs b/rust/src/format.rs index 0fc82a3987..34798ed65a 100644 --- a/rust/src/format.rs +++ b/rust/src/format.rs @@ -12,7 +12,7 @@ use crate::{ #[derive(ThisError, Debug)] pub enum Error { - #[error("Unknown format type {value}")] + #[error("Unknown format type {value}.")] UnknownFormat { value: u16 }, #[error("Output format {0} specifies width {}, but {} requires an even width.", .0.w, .0.format)] @@ -39,12 +39,6 @@ pub enum Error { #[error("Numeric variable is not compatible with string format {0}.")] UnnamedVariableNotCompatibleWithStringFormat(Format), - #[error("String variable {variable} is not compatible with numeric format {format}.")] - NamedVariableNotCompatibleWithNumericFormat { variable: String, format: Format }, - - #[error("Numeric variable {variable} is not compatible with string format {format}.")] - NamedVariableNotCompatibleWithStringFormat { variable: String, format: Format }, - #[error("String variable {variable} with width {width} is not compatible with format {bad_spec}. Use format {good_spec} instead.")] NamedStringVariableBadSpecWidth { variable: String, @@ -312,32 +306,14 @@ impl Format { /// Checks whether this format is valid for a variable with the given /// `var_type`. - pub fn check_type_compatibility( - self, - variable: Option<&str>, - var_type: VarType, - ) -> Result<(), Error> { + pub fn check_type_compatibility(self, var_type: VarType) -> Result<(), Error> { let my_type = self.var_type(); match (my_type, var_type) { (VarType::Numeric, VarType::String) => { - if let Some(variable) = variable { - Err(Error::NamedVariableNotCompatibleWithNumericFormat { - variable: variable.into(), - format: self, - }) - } else { - Err(Error::UnnamedVariableNotCompatibleWithNumericFormat(self)) - } + Err(Error::UnnamedVariableNotCompatibleWithNumericFormat(self)) } (VarType::String, VarType::Numeric) => { - if let Some(variable) = variable { - Err(Error::NamedVariableNotCompatibleWithStringFormat { - variable: variable.into(), - format: self, - }) - } else { - Err(Error::UnnamedVariableNotCompatibleWithStringFormat(self)) - } + Err(Error::UnnamedVariableNotCompatibleWithStringFormat(self)) } _ => Ok(()), } @@ -450,14 +426,10 @@ impl Spec { /// Checks whether this format specification is valid for a variable with /// width `var_width`. - pub fn check_width_compatibility( - self, - variable: Option<&str>, - var_width: VarWidth, - ) -> Result { + pub fn check_width_compatibility(self, var_width: VarWidth) -> Result { // Verify that the format is right for the variable's type. self.format - .check_type_compatibility(variable, var_width.into())?; + .check_type_compatibility(var_width.into())?; if let VarWidth::String(w) = var_width { if var_width != self.var_width() { @@ -467,20 +439,11 @@ impl Spec { } else { Spec { w: w * 2, ..self } }; - if let Some(variable) = variable { - return Err(Error::NamedStringVariableBadSpecWidth { - variable: variable.into(), - width: w, - bad_spec, - good_spec, - }); - } else { - return Err(Error::UnnamedStringVariableBadSpecWidth { - width: w, - bad_spec, - good_spec, - }); - } + return Err(Error::UnnamedStringVariableBadSpecWidth { + width: w, + bad_spec, + good_spec, + }); } }