Skip to content

Commit

Permalink
improve some derive diagnostics
Browse files Browse the repository at this point in the history
* don't double-panic, which can complicate understanding the original
  error cause
* fill out `todo!` text
  • Loading branch information
scottlamb committed Dec 11, 2024
1 parent 4197d35 commit d95ef15
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions static-xml-derive/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Errors {

impl Drop for Errors {
fn drop(&mut self) {
if self.0.borrow().is_some() {
if self.0.borrow().is_some() && !std::thread::panicking() {
panic!("Errors dropped without take_compile_errors call");
}
}
Expand Down Expand Up @@ -304,7 +304,7 @@ impl Namespaces {
if prefix == "xml" && url == "http://www.w3.org/XML/1998/namespace" {
return;
}
todo!()
todo!("unsupported special namespace combo prefix={prefix:?} url={url:?}")
}
self.add_internal(errors, nv, prefix_untrimmed.trim(), url_untrimmed);
} else {
Expand Down
6 changes: 3 additions & 3 deletions static-xml-derive/src/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ fn finalize_visitor_fields(struct_: &ElementStruct) -> Vec<TokenStream> {
let span = field.inner.span();
let ty = &field.inner.ty;
let default = field.default.then(|| {
Some(quote_spanned! {span=>
quote_spanned! {span=>
<#ty as ::std::default::Default>::default
})
}
});
match field.mode {
ElementFieldMode::Element { sorted_elements_pos: p } => {
Expand Down Expand Up @@ -140,7 +140,7 @@ fn finalize_visitor_fields(struct_: &ElementStruct) -> Vec<TokenStream> {
<#ty as ::static_xml::de::RawDeserialize>::Visitor::finalize(self.#field_visitor, #d)?;
}
}
ElementFieldMode::Text => todo!(),
ElementFieldMode::Text => todo!("text fields unimplemented"),
}
}).collect()
}
Expand Down
3 changes: 1 addition & 2 deletions static-xml/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,6 @@ impl<T: ParseText> DeserializeAttrField for Option<T> {
}
}


impl ParseText for bool {
fn parse(text: String) -> Result<Self, crate::BoxedStdError> {
// [https://www.w3.org/TR/xmlschema11-2/#boolean] "For all ·atomic· datatypes other than
Expand Down Expand Up @@ -1094,7 +1093,7 @@ mod tests {
}
}
/// An element which expects a single attribute of arbitrary name and
/// An element which expects a single attribute of arbitrary name and
/// value type `T`.
#[derive(Debug, Default, Eq, PartialEq)]
struct AttrWrapper<T: DeserializeAttrField>(T);
Expand Down

0 comments on commit d95ef15

Please sign in to comment.