Skip to content

Commit

Permalink
Fix unit test & add an ignore for useless question mark
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Sep 21, 2023
1 parent 969e32f commit 7de1892
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,24 @@ class ErrorCorrectionTest {
rustTemplate(
"""
let builder = #{correct_errors}(#{Shape}::builder().foo("abcd"));
let shape = builder.build();
let shape = builder.build().unwrap();
// don't override a field already set
assert_eq!(shape.foo(), Some("abcd"));
assert_eq!(shape.foo(), "abcd");
// set nested fields
assert_eq!(shape.nested().unwrap().a(), Some(""));
assert_eq!(shape.nested().a(), "");
// don't default non-required fields
assert_eq!(shape.not_required(), None);
// set defaults for everything else
assert_eq!(shape.blob().unwrap().as_ref(), &[]);
assert_eq!(shape.blob().as_ref(), &[]);
assert_eq!(shape.list_value(), Some(&[][..]));
assert!(shape.map_value().unwrap().is_empty());
assert_eq!(shape.double_list_value(), Some(&[][..]));
assert!(shape.list_value().is_empty());
assert!(shape.map_value().is_empty());
assert!(shape.double_list_value().is_empty());
// enums and unions become unknown variants
assert!(matches!(shape.r##enum(), Some(crate::types::Enum::Unknown(_))));
assert!(shape.union().unwrap().is_unknown());
assert!(matches!(shape.r##enum(), crate::types::Enum::Unknown(_)));
assert!(shape.union().is_unknown());
""",
*codegenCtx,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ class Attribute(val inner: Writable, val isDeriveHelper: Boolean = false) {
}

companion object {
val AllowNeedlessQuestionMark = Attribute(allow("clippy::needless_question_mark"))
val AllowClippyBoxedLocal = Attribute(allow("clippy::boxed_local"))
val AllowClippyLetAndReturn = Attribute(allow("clippy::let_and_return"))
val AllowClippyNeedlessBorrow = Attribute(allow("clippy::needless_borrow"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class XmlBindingTraitParserGenerator(
private fun RustWriter.parseStructure(shape: StructureShape, ctx: Ctx) {
val symbol = symbolProvider.toSymbol(shape)
val nestedParser = protocolFunctions.deserializeFn(shape) { fnName ->
Attribute.AllowNeedlessQuestionMark.render(this)
rustBlockTemplate(
"pub fn $fnName(decoder: &mut #{ScopedDecoder}) -> Result<#{Shape}, #{XmlDecodeError}>",
*codegenScope, "Shape" to symbol,
Expand Down

0 comments on commit 7de1892

Please sign in to comment.