From 252b8951034821553fd216c12a0236b996ae3a18 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 23 Jul 2022 12:03:17 -0700 Subject: [PATCH] Add must_use to Success --- src/api.rs | 14 -------------- src/dumper.rs | 3 --- src/emitter.rs | 1 - src/loader.rs | 1 - src/parser.rs | 11 +++++------ src/scanner.rs | 45 ++++++++++++++++++++++----------------------- src/success.rs | 1 + src/writer.rs | 1 - 8 files changed, 28 insertions(+), 49 deletions(-) diff --git a/src/api.rs b/src/api.rs index 1308af1..3668628 100644 --- a/src/api.rs +++ b/src/api.rs @@ -203,7 +203,6 @@ pub(crate) unsafe fn yaml_queue_extend( /// /// This function creates a new parser object. An application is responsible /// for destroying the object using the yaml_parser_delete() function. -#[must_use] pub unsafe fn yaml_parser_initialize(parser: *mut yaml_parser_t) -> Success { __assert!(!parser.is_null()); memset( @@ -353,7 +352,6 @@ pub unsafe fn yaml_parser_set_encoding(mut parser: *mut yaml_parser_t, encoding: /// /// This function creates a new emitter object. An application is responsible /// for destroying the object using the yaml_emitter_delete() function. -#[must_use] pub unsafe fn yaml_emitter_initialize(mut emitter: *mut yaml_emitter_t) -> Success { __assert!(!emitter.is_null()); memset( @@ -618,7 +616,6 @@ unsafe fn yaml_check_utf8(start: *const yaml_char_t, length: size_t) -> Success } /// Create the STREAM-START event. -#[must_use] pub unsafe fn yaml_stream_start_event_initialize( mut event: *mut yaml_event_t, encoding: yaml_encoding_t, @@ -642,7 +639,6 @@ pub unsafe fn yaml_stream_start_event_initialize( } /// Create the STREAM-END event. -#[must_use] pub unsafe fn yaml_stream_end_event_initialize(mut event: *mut yaml_event_t) -> Success { let mark = yaml_mark_t { index: 0_u64, @@ -665,7 +661,6 @@ pub unsafe fn yaml_stream_end_event_initialize(mut event: *mut yaml_event_t) -> /// /// The `implicit` argument is considered as a stylistic parameter and may be /// ignored by the emitter. -#[must_use] pub unsafe fn yaml_document_start_event_initialize( mut event: *mut yaml_event_t, version_directive: *mut yaml_version_directive_t, @@ -810,7 +805,6 @@ pub unsafe fn yaml_document_start_event_initialize( /// /// The `implicit` argument is considered as a stylistic parameter and may be /// ignored by the emitter. -#[must_use] pub unsafe fn yaml_document_end_event_initialize( mut event: *mut yaml_event_t, implicit: libc::c_int, @@ -834,7 +828,6 @@ pub unsafe fn yaml_document_end_event_initialize( } /// Create an ALIAS event. -#[must_use] pub unsafe fn yaml_alias_event_initialize( mut event: *mut yaml_event_t, anchor: *const yaml_char_t, @@ -976,7 +969,6 @@ pub unsafe fn yaml_scalar_event_initialize( /// The `style` argument may be ignored by the emitter. /// /// Either the `tag` attribute or the `implicit` flag must be set. -#[must_use] pub unsafe fn yaml_sequence_start_event_initialize( mut event: *mut yaml_event_t, anchor: *const yaml_char_t, @@ -1052,7 +1044,6 @@ pub unsafe fn yaml_sequence_start_event_initialize( } /// Create a SEQUENCE-END event. -#[must_use] pub unsafe fn yaml_sequence_end_event_initialize(mut event: *mut yaml_event_t) -> Success { let mark = yaml_mark_t { index: 0_u64, @@ -1076,7 +1067,6 @@ pub unsafe fn yaml_sequence_end_event_initialize(mut event: *mut yaml_event_t) - /// The `style` argument may be ignored by the emitter. /// /// Either the `tag` attribute or the `implicit` flag must be set. -#[must_use] pub unsafe fn yaml_mapping_start_event_initialize( mut event: *mut yaml_event_t, anchor: *const yaml_char_t, @@ -1152,7 +1142,6 @@ pub unsafe fn yaml_mapping_start_event_initialize( } /// Create a MAPPING-END event. -#[must_use] pub unsafe fn yaml_mapping_end_event_initialize(mut event: *mut yaml_event_t) -> Success { let mark = yaml_mark_t { index: 0_u64, @@ -1212,7 +1201,6 @@ pub unsafe fn yaml_event_delete(event: *mut yaml_event_t) { } /// Create a YAML document. -#[must_use] pub unsafe fn yaml_document_initialize( mut document: *mut yaml_document_t, version_directive: *mut yaml_version_directive_t, @@ -1652,7 +1640,6 @@ pub unsafe fn yaml_document_add_mapping( } /// Add an item to a SEQUENCE node. -#[must_use] pub unsafe fn yaml_document_append_sequence_item( document: *mut yaml_document_t, sequence: libc::c_int, @@ -1691,7 +1678,6 @@ pub unsafe fn yaml_document_append_sequence_item( } /// Add a pair of a key and a value to a MAPPING node. -#[must_use] pub unsafe fn yaml_document_append_mapping_pair( document: *mut yaml_document_t, mapping: libc::c_int, diff --git a/src/dumper.rs b/src/dumper.rs index e504543..bb2560c 100644 --- a/src/dumper.rs +++ b/src/dumper.rs @@ -16,7 +16,6 @@ use core::ptr::{self, addr_of_mut}; /// Start a YAML stream. /// /// This function should be used before yaml_emitter_dump() is called. -#[must_use] pub unsafe fn yaml_emitter_open(mut emitter: *mut yaml_emitter_t) -> Success { let mut event = MaybeUninit::::uninit(); let event = event.as_mut_ptr(); @@ -46,7 +45,6 @@ pub unsafe fn yaml_emitter_open(mut emitter: *mut yaml_emitter_t) -> Success { /// Finish a YAML stream. /// /// This function should be used after yaml_emitter_dump() is called. -#[must_use] pub unsafe fn yaml_emitter_close(mut emitter: *mut yaml_emitter_t) -> Success { let mut event = MaybeUninit::::uninit(); let event = event.as_mut_ptr(); @@ -81,7 +79,6 @@ pub unsafe fn yaml_emitter_close(mut emitter: *mut yaml_emitter_t) -> Success { /// the yaml_document_initialize() function. The emitter takes the /// responsibility for the document object and destroys its content after it is /// emitted. The document object is destroyed even if the function fails. -#[must_use] pub unsafe fn yaml_emitter_dump( emitter: *mut yaml_emitter_t, document: *mut yaml_document_t, diff --git a/src/emitter.rs b/src/emitter.rs index 684f448..cc68112 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -124,7 +124,6 @@ unsafe fn yaml_emitter_set_emitter_error( /// The emitter takes the responsibility for the event object and destroys its /// content after it is emitted. The event object is destroyed even if the /// function fails. -#[must_use] pub unsafe fn yaml_emitter_emit( mut emitter: *mut yaml_emitter_t, event: *mut yaml_event_t, diff --git a/src/loader.rs b/src/loader.rs index 32e4127..7e67043 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -33,7 +33,6 @@ struct loader_ctx { /// An application must not alternate the calls of yaml_parser_load() with the /// calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break /// the parser. -#[must_use] pub unsafe fn yaml_parser_load( mut parser: *mut yaml_parser_t, document: *mut yaml_document_t, diff --git a/src/parser.rs b/src/parser.rs index e0d5e0d..ff23eb1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -63,7 +63,6 @@ unsafe fn SKIP_TOKEN(parser: *mut yaml_parser_t) { /// An application must not alternate the calls of yaml_parser_parse() with the /// calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the /// parser. -#[must_use] pub unsafe fn yaml_parser_parse(parser: *mut yaml_parser_t, event: *mut yaml_event_t) -> Success { __assert!(!parser.is_null()); __assert!(!event.is_null()); @@ -276,7 +275,7 @@ unsafe fn yaml_parser_parse_document_start( if (*token).type_ as libc::c_uint != YAML_DOCUMENT_START_TOKEN as libc::c_int as libc::c_uint { - yaml_parser_set_parser_error( + let _ = yaml_parser_set_parser_error( parser, b"did not find expected \0" as *const u8 as *const libc::c_char, (*token).start_mark, @@ -541,7 +540,7 @@ unsafe fn yaml_parser_parse_node( 17786380918591080555 => {} _ => { if tag.is_null() { - yaml_parser_set_parser_error_context( + let _ = yaml_parser_set_parser_error_context( parser, b"while parsing a node\0" as *const u8 as *const libc::c_char, @@ -735,7 +734,7 @@ unsafe fn yaml_parser_parse_node( return OK; } } else { - yaml_parser_set_parser_error_context( + let _ = yaml_parser_set_parser_error_context( parser, if block != 0 { b"while parsing a block node\0" as *const u8 @@ -1352,7 +1351,7 @@ unsafe fn yaml_parser_process_directives( == YAML_VERSION_DIRECTIVE_TOKEN as libc::c_int as libc::c_uint { if !version_directive.is_null() { - yaml_parser_set_parser_error( + let _ = yaml_parser_set_parser_error( parser, b"found duplicate %YAML directive\0" as *const u8 as *const libc::c_char, @@ -1364,7 +1363,7 @@ unsafe fn yaml_parser_process_directives( || (*token).data.version_directive.minor != 1_i32 && (*token).data.version_directive.minor != 2_i32 { - yaml_parser_set_parser_error( + let _ = yaml_parser_set_parser_error( parser, b"found incompatible YAML document\0" as *const u8 as *const libc::c_char, diff --git a/src/scanner.rs b/src/scanner.rs index d80791a..2c2336c 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -142,7 +142,6 @@ macro_rules! READ_LINE { /// An application must not alternate the calls of yaml_parser_scan() with the /// calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break /// the parser. -#[must_use] pub unsafe fn yaml_parser_scan( mut parser: *mut yaml_parser_t, token: *mut yaml_token_t, @@ -1081,7 +1080,7 @@ unsafe fn yaml_parser_scan_directive( current_block = 17407779659766490442; } } else { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a directive\0" as *const u8 as *const libc::c_char, start_mark, @@ -1126,7 +1125,7 @@ unsafe fn yaml_parser_scan_directive( 11397968426844348457 => {} _ => { if !IS_BREAKZ!((*parser).buffer) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a directive\0" as *const u8 as *const libc::c_char, @@ -1195,7 +1194,7 @@ unsafe fn yaml_parser_scan_directive_name( 8318012024179131575 => {} _ => { if string.start == string.pointer { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a directive\0" as *const u8 as *const libc::c_char, start_mark, @@ -1203,7 +1202,7 @@ unsafe fn yaml_parser_scan_directive_name( as *const libc::c_char, ); } else if !IS_BLANKZ!((*parser).buffer) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a directive\0" as *const u8 as *const libc::c_char, start_mark, @@ -1340,7 +1339,7 @@ unsafe fn yaml_parser_scan_tag_directive_value( continue; } if !IS_BLANK!((*parser).buffer) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a %TAG directive\0" as *const u8 as *const libc::c_char, @@ -1374,7 +1373,7 @@ unsafe fn yaml_parser_scan_tag_directive_value( continue; } if !IS_BLANKZ!((*parser).buffer) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a %TAG directive\0" as *const u8 as *const libc::c_char, @@ -1439,7 +1438,7 @@ unsafe fn yaml_parser_scan_anchor( || CHECK!((*parser).buffer, b'@') || CHECK!((*parser).buffer, b'`')) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, if type_ as libc::c_uint == YAML_ANCHOR_TOKEN as libc::c_int as libc::c_uint @@ -1516,7 +1515,7 @@ unsafe fn yaml_parser_scan_tag( { current_block = 17708497480799081542; } else if !CHECK!((*parser).buffer, b'>') { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a tag\0" as *const u8 as *const libc::c_char, start_mark, @@ -1583,7 +1582,7 @@ unsafe fn yaml_parser_scan_tag( if !(CACHE(parser, 1_u64) == 0) { if !IS_BLANKZ!((*parser).buffer) { if (*parser).flow_level == 0 || !CHECK!((*parser).buffer, b',') { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a tag\0" as *const u8 as *const libc::c_char, start_mark, @@ -1636,7 +1635,7 @@ unsafe fn yaml_parser_scan_tag_handle( if !(STRING_INIT!(parser, string) == 0) { if !(CACHE(parser, 1_u64) == 0) { if !CHECK!((*parser).buffer, b'!') { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, if directive != 0 { b"while scanning a tag directive\0" as *const u8 as *const libc::c_char @@ -1676,7 +1675,7 @@ unsafe fn yaml_parser_scan_tag_handle( && *string.start.wrapping_offset(1_isize) as libc::c_int == '\0' as i32) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while parsing a tag directive\0" as *const u8 as *const libc::c_char, @@ -1812,7 +1811,7 @@ unsafe fn yaml_parser_scan_tag_uri( current_block = 15265153392498847348; continue; } - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, if directive != 0 { b"while parsing a %TAG directive\0" as *const u8 @@ -1946,7 +1945,7 @@ unsafe fn yaml_parser_scan_block_scalar( current_block = 14984465786483313892; } else if IS_DIGIT!((*parser).buffer) { if CHECK!((*parser).buffer, b'0') { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a block scalar\0" as *const u8 as *const libc::c_char, @@ -1965,7 +1964,7 @@ unsafe fn yaml_parser_scan_block_scalar( } } else if IS_DIGIT!((*parser).buffer) { if CHECK!((*parser).buffer, b'0') { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a block scalar\0" as *const u8 as *const libc::c_char, @@ -2032,7 +2031,7 @@ unsafe fn yaml_parser_scan_block_scalar( 14984465786483313892 => {} _ => { if !IS_BREAKZ!((*parser).buffer) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a block scalar\0" as *const u8 as *const libc::c_char, @@ -2309,7 +2308,7 @@ unsafe fn yaml_parser_scan_flow_scalar( && CHECK_AT!((*parser).buffer, b'.', 2)) && IS_BLANKZ_AT!((*parser).buffer, 3) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a quoted scalar\0" as *const u8 as *const libc::c_char, @@ -2320,7 +2319,7 @@ unsafe fn yaml_parser_scan_flow_scalar( current_block = 8114179180390253173; break; } else if IS_Z!((*parser).buffer) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a quoted scalar\0" as *const u8 as *const libc::c_char, @@ -2491,7 +2490,7 @@ unsafe fn yaml_parser_scan_flow_scalar( code_length = 8_u64; } _ => { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while parsing a quoted scalar\0" as *const u8 as *const libc::c_char, @@ -2515,7 +2514,7 @@ unsafe fn yaml_parser_scan_flow_scalar( k = 0_u64; while k < code_length { if !IS_HEX_AT!((*parser).buffer, k as isize) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while parsing a quoted scalar\0" as *const u8 @@ -2539,7 +2538,7 @@ unsafe fn yaml_parser_scan_flow_scalar( && value <= 0xdfff_i32 as libc::c_uint || value > 0x10ffff_i32 as libc::c_uint { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while parsing a quoted scalar\0" as *const u8 as *const libc::c_char, @@ -2819,7 +2818,7 @@ unsafe fn yaml_parser_scan_plain_scalar( || CHECK_AT!((*parser).buffer, b'{', 1) || CHECK_AT!((*parser).buffer, b'}', 1)) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a plain scalar\0" as *const u8 as *const libc::c_char, @@ -2906,7 +2905,7 @@ unsafe fn yaml_parser_scan_plain_scalar( && ((*parser).mark.column as libc::c_int) < indent && IS_TAB!((*parser).buffer) { - yaml_parser_set_scanner_error( + let _ = yaml_parser_set_scanner_error( parser, b"while scanning a plain scalar\0" as *const u8 as *const libc::c_char, diff --git a/src/success.rs b/src/success.rs index 2cd1ab4..12fe630 100644 --- a/src/success.rs +++ b/src/success.rs @@ -1,6 +1,7 @@ pub const OK: Success = Success { ok: true }; pub const FAIL: Success = Success { ok: false }; +#[must_use] pub struct Success { pub ok: bool, } diff --git a/src/writer.rs b/src/writer.rs index 615d16a..f5d728d 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -16,7 +16,6 @@ unsafe fn yaml_emitter_set_writer_error( } /// Flush the accumulated characters to the output. -#[must_use] pub unsafe fn yaml_emitter_flush(emitter: *mut yaml_emitter_t) -> Success { __assert!(!emitter.is_null()); __assert!(((*emitter).write_handler).is_some());