diff --git a/src/lib.rs b/src/lib.rs index d05414c2..66267cbb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -381,7 +381,7 @@ impl Optional for (T,) { /// /// Handling multiple properties for `strip_option` /// -/// ```no_run +/// ```compile_fail /// use typed_builder::TypedBuilder; /// /// #[derive(TypedBuilder)] @@ -402,16 +402,4 @@ impl Optional for (T,) { /// value: Option, /// } /// ``` -/// -/// Handling empty properties for `strip_option` -/// -/// ```no_run -/// use typed_builder::TypedBuilder; -/// -/// #[derive(TypedBuilder)] -/// struct Foo { -/// #[builder(setter(strip_option()))] -/// value: Option, -/// } -/// ``` fn _compile_fail_tests() {} diff --git a/typed-builder-macro/src/field_info.rs b/typed-builder-macro/src/field_info.rs index 4d18370e..8d03bc10 100644 --- a/typed-builder-macro/src/field_info.rs +++ b/typed-builder-macro/src/field_info.rs @@ -341,11 +341,12 @@ impl ApplyMeta for SetterSettings { match expr { AttrArg::Sub(sub) => { let span = sub.span(); - let mut strip_option = Strip::new(span); if self.strip_option.is_none() { + let mut strip_option = Strip::new(span); strip_option.apply_sub_attr(sub)?; self.strip_option = Some(strip_option); + Ok(()) } else { Err(Error::new(span, format!("Illegal setting - field is already {caption}"))) @@ -394,6 +395,13 @@ impl ApplyMeta for Strip { fn apply_meta(&mut self, expr: AttrArg) -> Result<(), Error> { match expr.name().to_string().as_str() { "fallback" => { + if self.fallback.is_some() { + return Err(Error::new_spanned( + expr.name(), + format!("Duplicate fallback parameter {:?}", expr.name().to_string()), + )); + } + let ident: syn::Ident = expr.key_value().map(|kv| kv.parse_value())??; self.fallback = Some(ident); Ok(())