html-to-markdown 2.23.4 → 2.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/README.md +9 -7
- data/ext/html-to-markdown-rb/native/Cargo.lock +21 -21
- data/ext/html-to-markdown-rb/native/Cargo.toml +1 -3
- data/lib/html_to_markdown/cli_proxy.rb +5 -2
- data/lib/html_to_markdown/version.rb +1 -1
- data/rust-vendor/cc/.cargo-checksum.json +1 -1
- data/rust-vendor/cc/.cargo_vcs_info.json +1 -1
- data/rust-vendor/cc/CHANGELOG.md +7 -0
- data/rust-vendor/cc/Cargo.lock +1 -1
- data/rust-vendor/cc/Cargo.toml +1 -1
- data/rust-vendor/cc/Cargo.toml.orig +1 -1
- data/rust-vendor/cc/src/target/generated.rs +1 -0
- data/rust-vendor/cc/src/target/parser.rs +4 -0
- data/rust-vendor/html-to-markdown-rs/README.md +1 -1
- data/rust-vendor/html-to-markdown-rs/src/convert_api.rs +90 -15
- data/rust-vendor/html-to-markdown-rs/src/converter/block/preformatted.rs +15 -4
- data/rust-vendor/html-to-markdown-rs/src/converter/handlers/graphic.rs +5 -3
- data/rust-vendor/html-to-markdown-rs/src/converter/media/svg.rs +5 -1
- data/rust-vendor/html-to-markdown-rs/src/converter/text/processing.rs +15 -8
- data/rust-vendor/html-to-markdown-rs/src/converter/utility/preprocessing.rs +43 -18
- data/rust-vendor/html-to-markdown-rs/src/lib.rs +6 -6
- data/rust-vendor/html-to-markdown-rs/src/validation.rs +68 -29
- data/rust-vendor/html-to-markdown-rs/tests/issue_190_regressions.rs +121 -0
- data/rust-vendor/html-to-markdown-rs/tests/skip_images_test.rs +21 -0
- data/rust-vendor/proc-macro2/.cargo-checksum.json +1 -1
- data/rust-vendor/proc-macro2/.cargo_vcs_info.json +1 -1
- data/rust-vendor/proc-macro2/Cargo.lock +14 -89
- data/rust-vendor/proc-macro2/Cargo.toml +1 -1
- data/rust-vendor/proc-macro2/Cargo.toml.orig +1 -1
- data/rust-vendor/proc-macro2/src/fallback.rs +37 -23
- data/rust-vendor/proc-macro2/src/lib.rs +1 -1
- data/rust-vendor/quote/.cargo-checksum.json +1 -1
- data/rust-vendor/quote/.cargo_vcs_info.json +1 -1
- data/rust-vendor/quote/.github/workflows/ci.yml +1 -1
- data/rust-vendor/quote/Cargo.lock +17 -17
- data/rust-vendor/quote/Cargo.toml +1 -1
- data/rust-vendor/quote/Cargo.toml.orig +1 -1
- data/rust-vendor/quote/src/format.rs +2 -2
- data/rust-vendor/quote/src/lib.rs +1 -1
- data/rust-vendor/quote/src/runtime.rs +2 -2
- data/rust-vendor/quote/tests/test.rs +6 -0
- data/rust-vendor/quote/tests/ui/does-not-have-iter-interpolated-dup.stderr +2 -2
- data/rust-vendor/quote/tests/ui/does-not-have-iter-interpolated.stderr +2 -2
- data/rust-vendor/quote/tests/ui/does-not-have-iter-separated.stderr +2 -2
- data/rust-vendor/quote/tests/ui/does-not-have-iter.stderr +2 -2
- data/rust-vendor/quote/tests/ui/not-repeatable.stderr +8 -8
- data/rust-vendor/siphasher/.cargo-checksum.json +1 -1
- data/rust-vendor/siphasher/.cargo_vcs_info.json +1 -1
- data/rust-vendor/siphasher/.github/workflows/issues.yml +17 -0
- data/rust-vendor/siphasher/COPYING +1 -1
- data/rust-vendor/siphasher/Cargo.lock +89 -0
- data/rust-vendor/siphasher/Cargo.toml +23 -13
- data/rust-vendor/siphasher/Cargo.toml.orig +1 -1
- data/rust-vendor/siphasher/src/common.rs +65 -0
- data/rust-vendor/siphasher/src/lib.rs +1 -1
- data/rust-vendor/siphasher/src/sip.rs +2 -68
- data/rust-vendor/siphasher/src/sip128.rs +15 -74
- data/rust-vendor/siphasher/src/tests.rs +1 -1
- data/rust-vendor/siphasher/src/tests128.rs +1 -1
- data/rust-vendor/uuid/.cargo-checksum.json +1 -1
- data/rust-vendor/uuid/.cargo_vcs_info.json +1 -1
- data/rust-vendor/uuid/Cargo.lock +125 -96
- data/rust-vendor/uuid/Cargo.toml +4 -11
- data/rust-vendor/uuid/Cargo.toml.orig +5 -14
- data/rust-vendor/uuid/README.md +3 -3
- data/rust-vendor/uuid/src/builder.rs +2 -1
- data/rust-vendor/uuid/src/external/serde_support.rs +209 -142
- data/rust-vendor/uuid/src/lib.rs +9 -11
- data/rust-vendor/uuid/src/macros.rs +9 -54
- data/rust-vendor/uuid/src/non_nil.rs +49 -2
- data/rust-vendor/web_atoms/.cargo-checksum.json +1 -1
- data/rust-vendor/web_atoms/.cargo_vcs_info.json +1 -1
- data/rust-vendor/web_atoms/Cargo.lock +1 -1
- data/rust-vendor/web_atoms/Cargo.toml +1 -1
- data/rust-vendor/web_atoms/Cargo.toml.orig +1 -1
- data/rust-vendor/web_atoms/local_names.txt +3 -0
- data/rust-vendor/zerocopy/.cargo-checksum.json +1 -1
- data/rust-vendor/zerocopy/.cargo_vcs_info.json +1 -1
- data/rust-vendor/zerocopy/Cargo.lock +5 -9
- data/rust-vendor/zerocopy/Cargo.toml +10 -18
- data/rust-vendor/zerocopy/Cargo.toml.orig +6 -14
- data/rust-vendor/zerocopy/Cargo.toml.std +58 -0
- data/rust-vendor/zerocopy/agent_docs/ui_tests.md +5 -5
- data/rust-vendor/zerocopy/cargo.sh +1 -1
- data/rust-vendor/zerocopy/ci/check_fmt.sh +1 -1
- data/rust-vendor/zerocopy/ci/check_readme.sh +1 -1
- data/rust-vendor/zerocopy/ci/check_stale_stderr.sh +44 -0
- data/rust-vendor/zerocopy/githooks/pre-push +2 -0
- data/rust-vendor/zerocopy/src/byte_slice.rs +1 -1
- data/rust-vendor/zerocopy/src/byteorder.rs +0 -1
- data/rust-vendor/zerocopy/src/impls.rs +334 -118
- data/rust-vendor/zerocopy/src/layout.rs +9 -0
- data/rust-vendor/zerocopy/src/lib.rs +163 -74
- data/rust-vendor/zerocopy/src/macros.rs +4 -8
- data/rust-vendor/zerocopy/src/pointer/inner.rs +4 -4
- data/rust-vendor/zerocopy/src/pointer/invariant.rs +22 -5
- data/rust-vendor/zerocopy/src/pointer/mod.rs +155 -18
- data/rust-vendor/zerocopy/src/pointer/ptr.rs +133 -182
- data/rust-vendor/zerocopy/src/pointer/transmute.rs +99 -106
- data/rust-vendor/zerocopy/src/ref.rs +4 -4
- data/rust-vendor/zerocopy/src/util/macro_util.rs +73 -127
- data/rust-vendor/zerocopy/src/util/macros.rs +61 -150
- data/rust-vendor/zerocopy/src/wrappers.rs +249 -3
- data/rust-vendor/zerocopy/tests/include.rs +67 -0
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-from-bytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-from-zeros.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-immutable.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-immutable.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-into-bytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-issue-1296.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-known-layout.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-known-layout.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-unaligned.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/diagnostic-not-implemented-unaligned.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-msrv/include_value_not_from_bytes.rs +3 -5
- data/rust-vendor/zerocopy/tests/ui-msrv/include_value_not_from_bytes.stderr +10 -10
- data/rust-vendor/zerocopy/tests/ui-msrv/include_value_wrong_size.rs +1 -4
- data/rust-vendor/zerocopy/tests/ui-msrv/include_value_wrong_size.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/invalid-impls/invalid-impls.rs +0 -1
- data/rust-vendor/zerocopy/tests/ui-msrv/invalid-impls/invalid-impls.stderr +35 -35
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-dst-not-frombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-dst-not-frombytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-const.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-const.stderr +10 -10
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-dst-not-references.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-dst-not-references.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-immutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-immutable.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-not-a-reference.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-not-frombytes.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-not-intobytes.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ptr-to-usize.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ptr-to-usize.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-mutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-mutable.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-frombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-nocell.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-nocell.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-dst-not-references.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-not-a-reference.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-not-intobytes.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-not-nocell.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-not-nocell.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-size-increase-allow-shrink.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-size-increase-allow-shrink.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-size-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-src-not-intobytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-dst-not-tryfrombytes.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-size-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute-src-not-intobytes.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-alignment-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-alignment-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr +16 -16
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-src-not-frombytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-src-not-intobytes.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-alignment-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-alignment-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-mutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-mutable.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +16 -16
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-from-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-from-bytes.stderr +15 -15
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-from-zeros.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-from-zeros.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-immutable.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-immutable.stderr +13 -13
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-into-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-into-bytes.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-issue-1296.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-issue-1296.stderr +16 -16
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-known-layout.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-known-layout.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.stderr +15 -15
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-unaligned.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/diagnostic-not-implemented-unaligned.stderr +5 -5
- data/rust-vendor/zerocopy/tests/ui-nightly/include_value_not_from_bytes.rs +3 -5
- data/rust-vendor/zerocopy/tests/ui-nightly/include_value_not_from_bytes.stderr +21 -21
- data/rust-vendor/zerocopy/tests/ui-nightly/include_value_wrong_size.rs +1 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/include_value_wrong_size.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/invalid-impls/invalid-impls.rs +0 -1
- data/rust-vendor/zerocopy/tests/ui-nightly/invalid-impls/invalid-impls.stderr +35 -51
- data/rust-vendor/zerocopy/tests/ui-nightly/ptr-is-invariant-over-v.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-dst-not-frombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-dst-not-frombytes.stderr +15 -15
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-const.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-const.stderr +7 -7
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr +5 -5
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-unsized.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-dst-not-references.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-immutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-immutable.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-not-intobytes.stderr +5 -5
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-unsized.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ptr-to-usize.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ptr-to-usize.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-mutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-mutable.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-frombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr +16 -16
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-nocell.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-nocell.stderr +14 -14
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-unsized.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-dst-not-references.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr +9 -9
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-not-intobytes.stderr +18 -18
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-not-nocell.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-not-nocell.stderr +28 -28
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-unsized.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-size-decrease.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-size-increase-allow-shrink.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-size-increase-allow-shrink.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-size-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-src-not-intobytes.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-dst-not-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-dst-not-tryfrombytes.stderr +43 -43
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-size-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute-src-not-intobytes.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-alignment-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-alignment-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr +51 -51
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-src-not-frombytes.stderr +29 -29
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-src-not-intobytes.stderr +22 -22
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-alignment-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-alignment-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-dst-mutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-dst-mutable.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +56 -56
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.stderr +21 -21
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-from-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-from-bytes.stderr +15 -15
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-from-zeros.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-from-zeros.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-immutable.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-immutable.stderr +13 -13
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-into-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-into-bytes.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-issue-1296.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-issue-1296.stderr +16 -16
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-known-layout.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-known-layout.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-try-from-bytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-try-from-bytes.stderr +15 -15
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-unaligned.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/diagnostic-not-implemented-unaligned.stderr +5 -5
- data/rust-vendor/zerocopy/tests/ui-stable/include_value_not_from_bytes.rs +3 -5
- data/rust-vendor/zerocopy/tests/ui-stable/include_value_not_from_bytes.stderr +21 -21
- data/rust-vendor/zerocopy/tests/ui-stable/include_value_wrong_size.rs +1 -4
- data/rust-vendor/zerocopy/tests/ui-stable/include_value_wrong_size.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-stable/invalid-impls/invalid-impls.rs +0 -1
- data/rust-vendor/zerocopy/tests/ui-stable/invalid-impls/invalid-impls.stderr +37 -37
- data/rust-vendor/zerocopy/tests/ui-stable/ptr-is-invariant-over-v.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-dst-not-frombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-dst-not-frombytes.stderr +15 -15
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-const.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-const.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr +11 -11
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-intobytes.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-dst-not-references.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-dst-not-references.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-immutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-immutable.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-not-a-reference.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-not-frombytes.stderr +11 -11
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-not-intobytes.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ptr-to-usize.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ptr-to-usize.stderr +9 -5
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-mutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-mutable.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-frombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-frombytes.stderr +16 -16
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-nocell.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-nocell.stderr +14 -14
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-dst-not-references.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-dst-not-references.stderr +9 -9
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-not-a-reference.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-not-a-reference.stderr +3 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-not-intobytes.stderr +18 -18
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-not-nocell.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-not-nocell.stderr +28 -28
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-unsized.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-unsized.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-size-decrease.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-size-increase-allow-shrink.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-size-increase-allow-shrink.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-size-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-src-not-intobytes.stderr +8 -8
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-dst-not-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-dst-not-tryfrombytes.stderr +42 -42
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-size-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-src-not-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute-src-not-intobytes.stderr +7 -7
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-alignment-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-alignment-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr +49 -49
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-increase.stderr +4 -4
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-src-not-frombytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-src-not-frombytes.stderr +26 -26
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-src-not-intobytes.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-src-not-intobytes.stderr +19 -19
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-alignment-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-alignment-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-dst-mutable.rs +0 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-dst-mutable.stderr +6 -6
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +54 -54
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-decrease.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-decrease.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-increase.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-increase.stderr +2 -2
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.rs +1 -3
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.stderr +19 -19
- data/rust-vendor/zerocopy-derive/.cargo-checksum.json +1 -1
- data/rust-vendor/zerocopy-derive/.cargo_vcs_info.json +1 -1
- data/rust-vendor/zerocopy-derive/Cargo.lock +3 -11
- data/rust-vendor/zerocopy-derive/Cargo.toml +13 -11
- data/rust-vendor/zerocopy-derive/Cargo.toml.orig +7 -10
- data/rust-vendor/zerocopy-derive/src/derive/from_bytes.rs +188 -0
- data/rust-vendor/zerocopy-derive/src/derive/into_bytes.rs +158 -0
- data/rust-vendor/zerocopy-derive/src/derive/known_layout.rs +348 -0
- data/rust-vendor/zerocopy-derive/src/derive/mod.rs +130 -0
- data/rust-vendor/zerocopy-derive/src/derive/try_from_bytes.rs +729 -0
- data/rust-vendor/zerocopy-derive/src/derive/unaligned.rs +78 -0
- data/rust-vendor/zerocopy-derive/src/lib.rs +31 -1893
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/eq.expected.rs +17 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/from_bytes_enum.expected.rs +64 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/from_bytes_struct.expected.rs +64 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/from_bytes_union.expected.rs +144 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/from_zeros.expected.rs +39 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/hash.expected.rs +24 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/immutable.expected.rs +17 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/into_bytes_enum.expected.rs +17 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/into_bytes_struct_basic.expected.rs +25 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/into_bytes_struct_empty.expected.rs +17 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/into_bytes_struct_trailing.expected.rs +25 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/into_bytes_struct_trailing_generic.expected.rs +21 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/known_layout_repr_c_struct.expected.rs +135 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/known_layout_struct.expected.rs +34 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/split_at_repr_c.expected.rs +22 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/split_at_repr_transparent.expected.rs +22 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/try_from_bytes.expected.rs +22 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_1.expected.rs +2802 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_2.expected.rs +2802 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/try_from_bytes_enum_3.expected.rs +2802 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/try_from_bytes_trivial_is_bit_valid_enum.expected.rs +22 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/expected/unaligned.expected.rs +17 -0
- data/rust-vendor/zerocopy-derive/src/output_tests/mod.rs +960 -0
- data/rust-vendor/zerocopy-derive/src/util.rs +757 -0
- data/rust-vendor/zerocopy-derive/tests/deprecated.rs +6 -0
- data/rust-vendor/zerocopy-derive/tests/enum_from_zeros.rs +9 -0
- data/rust-vendor/zerocopy-derive/tests/enum_known_layout.rs +4 -0
- data/rust-vendor/zerocopy-derive/tests/enum_no_cell.rs +4 -0
- data/rust-vendor/zerocopy-derive/tests/enum_to_bytes.rs +14 -0
- data/rust-vendor/zerocopy-derive/tests/enum_try_from_bytes.rs +37 -15
- data/rust-vendor/zerocopy-derive/tests/enum_unaligned.rs +4 -0
- data/rust-vendor/zerocopy-derive/tests/eq.rs +1 -0
- data/rust-vendor/zerocopy-derive/tests/hash.rs +1 -0
- data/rust-vendor/zerocopy-derive/tests/hygiene.rs +3 -1
- data/rust-vendor/zerocopy-derive/tests/include.rs +26 -4
- data/rust-vendor/zerocopy-derive/tests/issue_2117.rs +1 -0
- data/rust-vendor/zerocopy-derive/tests/issue_2835.rs +2 -1
- data/rust-vendor/zerocopy-derive/tests/issue_2880.rs +292 -0
- data/rust-vendor/zerocopy-derive/tests/issue_2915.rs +78 -0
- data/rust-vendor/zerocopy-derive/tests/paths_and_modules.rs +3 -0
- data/rust-vendor/zerocopy-derive/tests/priv_in_pub.rs +2 -0
- data/rust-vendor/zerocopy-derive/tests/struct_from_bytes.rs +6 -0
- data/rust-vendor/zerocopy-derive/tests/struct_from_zeros.rs +6 -0
- data/rust-vendor/zerocopy-derive/tests/struct_known_layout.rs +9 -0
- data/rust-vendor/zerocopy-derive/tests/struct_no_cell.rs +8 -0
- data/rust-vendor/zerocopy-derive/tests/struct_to_bytes.rs +17 -0
- data/rust-vendor/zerocopy-derive/tests/struct_try_from_bytes.rs +29 -65
- data/rust-vendor/zerocopy-derive/tests/struct_unaligned.rs +7 -0
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/derive_transparent.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/derive_transparent.stderr +32 -32
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/enum.rs +48 -1
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/enum.stderr +129 -126
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/enum_from_bytes_u8_too_few.rs +2 -1
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/enum_from_bytes_u8_too_few.stderr +6 -6
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/late_compile_pass.rs +9 -2
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr +37 -37
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/mid_compile_pass.rs +6 -2
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/mid_compile_pass.stderr +26 -26
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/msrv_specific.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/msrv_specific.stderr +7 -7
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/privacy.rs +66 -29
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/privacy.stderr +78 -78
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/struct.rs +34 -2
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/struct.stderr +79 -79
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/union.rs +12 -1
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/union.stderr +29 -29
- data/rust-vendor/zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.stderr +2 -2
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/derive_transparent.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/derive_transparent.stderr +57 -57
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/enum.rs +48 -1
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/enum.stderr +200 -192
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/enum_from_bytes_u8_too_few.rs +2 -1
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/enum_from_bytes_u8_too_few.stderr +6 -6
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/late_compile_pass.rs +9 -2
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/late_compile_pass.stderr +105 -105
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/mid_compile_pass.rs +6 -2
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/mid_compile_pass.stderr +29 -29
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/privacy.rs +66 -29
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/privacy.stderr +15 -15
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/struct.rs +34 -2
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/struct.stderr +130 -129
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/union.rs +12 -1
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/union.stderr +42 -42
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/ui-stable/derive_transparent.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/ui-stable/derive_transparent.stderr +57 -57
- data/rust-vendor/zerocopy-derive/tests/ui-stable/enum.rs +48 -1
- data/rust-vendor/zerocopy-derive/tests/ui-stable/enum.stderr +201 -186
- data/rust-vendor/zerocopy-derive/tests/ui-stable/enum_from_bytes_u8_too_few.rs +2 -1
- data/rust-vendor/zerocopy-derive/tests/ui-stable/enum_from_bytes_u8_too_few.stderr +6 -6
- data/rust-vendor/zerocopy-derive/tests/ui-stable/late_compile_pass.rs +9 -2
- data/rust-vendor/zerocopy-derive/tests/ui-stable/late_compile_pass.stderr +105 -105
- data/rust-vendor/zerocopy-derive/tests/ui-stable/mid_compile_pass.rs +6 -2
- data/rust-vendor/zerocopy-derive/tests/ui-stable/mid_compile_pass.stderr +29 -29
- data/rust-vendor/zerocopy-derive/tests/ui-stable/privacy.rs +66 -29
- data/rust-vendor/zerocopy-derive/tests/ui-stable/privacy.stderr +15 -15
- data/rust-vendor/zerocopy-derive/tests/ui-stable/struct.rs +34 -2
- data/rust-vendor/zerocopy-derive/tests/ui-stable/struct.stderr +158 -129
- data/rust-vendor/zerocopy-derive/tests/ui-stable/union.rs +12 -1
- data/rust-vendor/zerocopy-derive/tests/ui-stable/union.stderr +48 -44
- data/rust-vendor/zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.rs +3 -2
- data/rust-vendor/zerocopy-derive/tests/union_from_bytes.rs +15 -0
- data/rust-vendor/zerocopy-derive/tests/union_from_zeros.rs +14 -0
- data/rust-vendor/zerocopy-derive/tests/union_known_layout.rs +5 -0
- data/rust-vendor/zerocopy-derive/tests/union_no_cell.rs +5 -0
- data/rust-vendor/zerocopy-derive/tests/union_to_bytes.rs +5 -0
- data/rust-vendor/zerocopy-derive/tests/union_try_from_bytes.rs +34 -74
- data/rust-vendor/zerocopy-derive/tests/union_unaligned.rs +4 -1
- data/rust-vendor/zerocopy-derive/tests/unsafe_cell.rs +3 -0
- data/rust-vendor/zmij/.cargo-checksum.json +1 -1
- data/rust-vendor/zmij/.cargo_vcs_info.json +1 -1
- data/rust-vendor/zmij/Cargo.lock +10 -10
- data/rust-vendor/zmij/Cargo.toml +1 -1
- data/rust-vendor/zmij/Cargo.toml.orig +1 -1
- data/rust-vendor/zmij/README.md +1 -1
- data/rust-vendor/zmij/src/lib.rs +132 -158
- data/rust-vendor/zune-jpeg/.cargo-checksum.json +1 -1
- data/rust-vendor/zune-jpeg/.cargo_vcs_info.json +1 -1
- data/rust-vendor/zune-jpeg/Cargo.lock +1 -1
- data/rust-vendor/zune-jpeg/Cargo.toml +1 -1
- data/rust-vendor/zune-jpeg/Cargo.toml.orig +1 -1
- data/rust-vendor/zune-jpeg/src/bitstream.rs +1 -1
- data/rust-vendor/zune-jpeg/src/components.rs +2 -1
- data/rust-vendor/zune-jpeg/src/decoder.rs +3 -23
- data/rust-vendor/zune-jpeg/src/headers.rs +19 -1
- data/rust-vendor/zune-jpeg/src/lib.rs +1 -0
- data/rust-vendor/zune-jpeg/src/mcu.rs +6 -6
- data/rust-vendor/zune-jpeg/src/mcu_prog.rs +22 -34
- data/rust-vendor/zune-jpeg/src/upsampler/avx2.rs +3 -1
- data/rust-vendor/zune-jpeg/src/upsampler/neon.rs +13 -23
- data/rust-vendor/zune-jpeg/src/upsampler/portable_simd.rs +4 -1
- data/rust-vendor/zune-jpeg/src/upsampler/scalar.rs +4 -1
- metadata +41 -8
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-dst-unsized.stderr +0 -183
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-dst-unsized.stderr +0 -183
- data/rust-vendor/zerocopy-derive/src/enum.rs +0 -456
- data/rust-vendor/zerocopy-derive/src/ext.rs +0 -123
- data/rust-vendor/zerocopy-derive/src/output_tests.rs +0 -5608
- data/rust-vendor/zerocopy-derive/tests/crate_path.rs +0 -189
|
@@ -0,0 +1,729 @@
|
|
|
1
|
+
use proc_macro2::TokenStream;
|
|
2
|
+
use quote::quote;
|
|
3
|
+
use syn::{
|
|
4
|
+
parse_quote, spanned::Spanned as _, Data, DataEnum, DataStruct, DataUnion, DeriveInput, Error,
|
|
5
|
+
Expr, Fields, Ident, Index, Type,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
use crate::{
|
|
9
|
+
repr::{EnumRepr, StructUnionRepr},
|
|
10
|
+
util::{
|
|
11
|
+
const_block, enum_size_from_repr, generate_tag_enum, Ctx, DataExt, FieldBounds,
|
|
12
|
+
ImplBlockBuilder, Trait, TraitBound,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
fn tag_ident(variant_ident: &Ident) -> Ident {
|
|
16
|
+
ident!(("___ZEROCOPY_TAG_{}", variant_ident), variant_ident.span())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// Generates a constant for the tag associated with each variant of the enum.
|
|
20
|
+
/// When we match on the enum's tag, each arm matches one of these constants. We
|
|
21
|
+
/// have to use constants here because:
|
|
22
|
+
///
|
|
23
|
+
/// - The type that we're matching on is not the type of the tag, it's an
|
|
24
|
+
/// integer of the same size as the tag type and with the same bit patterns.
|
|
25
|
+
/// - We can't read the enum tag as an enum because the bytes may not represent
|
|
26
|
+
/// a valid variant.
|
|
27
|
+
/// - Patterns do not currently support const expressions, so we have to assign
|
|
28
|
+
/// these constants to names rather than use them inline in the `match`
|
|
29
|
+
/// statement.
|
|
30
|
+
fn generate_tag_consts(data: &DataEnum) -> TokenStream {
|
|
31
|
+
let tags = data.variants.iter().map(|v| {
|
|
32
|
+
let variant_ident = &v.ident;
|
|
33
|
+
let tag_ident = tag_ident(variant_ident);
|
|
34
|
+
|
|
35
|
+
quote! {
|
|
36
|
+
// This casts the enum variant to its discriminant, and then
|
|
37
|
+
// converts the discriminant to the target integral type via a
|
|
38
|
+
// numeric cast [1].
|
|
39
|
+
//
|
|
40
|
+
// Because these are the same size, this is defined to be a no-op
|
|
41
|
+
// and therefore is a lossless conversion [2].
|
|
42
|
+
//
|
|
43
|
+
// [1] Per https://doc.rust-lang.org/1.81.0/reference/expressions/operator-expr.html#enum-cast:
|
|
44
|
+
//
|
|
45
|
+
// Casts an enum to its discriminant.
|
|
46
|
+
//
|
|
47
|
+
// [2] Per https://doc.rust-lang.org/1.81.0/reference/expressions/operator-expr.html#numeric-cast:
|
|
48
|
+
//
|
|
49
|
+
// Casting between two integers of the same size (e.g. i32 -> u32)
|
|
50
|
+
// is a no-op.
|
|
51
|
+
const #tag_ident: ___ZerocopyTagPrimitive =
|
|
52
|
+
___ZerocopyTag::#variant_ident as ___ZerocopyTagPrimitive;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
quote! {
|
|
57
|
+
#(#tags)*
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fn variant_struct_ident(variant_ident: &Ident) -> Ident {
|
|
62
|
+
ident!(("___ZerocopyVariantStruct_{}", variant_ident), variant_ident.span())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Generates variant structs for the given enum variant.
|
|
66
|
+
///
|
|
67
|
+
/// These are structs associated with each variant of an enum. They are
|
|
68
|
+
/// `repr(C)` tuple structs with the same fields as the variant after a
|
|
69
|
+
/// `MaybeUninit<___ZerocopyInnerTag>`.
|
|
70
|
+
///
|
|
71
|
+
/// In order to unify the generated types for `repr(C)` and `repr(int)` enums,
|
|
72
|
+
/// we use a "fused" representation with fields for both an inner tag and an
|
|
73
|
+
/// outer tag. Depending on the repr, we will set one of these tags to the tag
|
|
74
|
+
/// type and the other to `()`. This lets us generate the same code but put the
|
|
75
|
+
/// tags in different locations.
|
|
76
|
+
fn generate_variant_structs(ctx: &Ctx, data: &DataEnum) -> TokenStream {
|
|
77
|
+
let (impl_generics, ty_generics, where_clause) = ctx.ast.generics.split_for_impl();
|
|
78
|
+
|
|
79
|
+
let enum_name = &ctx.ast.ident;
|
|
80
|
+
|
|
81
|
+
// All variant structs have a `PhantomData<MyEnum<...>>` field because we
|
|
82
|
+
// don't know which generic parameters each variant will use, and unused
|
|
83
|
+
// generic parameters are a compile error.
|
|
84
|
+
let core = ctx.core_path();
|
|
85
|
+
let phantom_ty = quote! {
|
|
86
|
+
#core::marker::PhantomData<#enum_name #ty_generics>
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
let variant_structs = data.variants.iter().filter_map(|variant| {
|
|
90
|
+
// We don't generate variant structs for unit variants because we only
|
|
91
|
+
// need to check the tag. This helps cut down our generated code a bit.
|
|
92
|
+
if matches!(variant.fields, Fields::Unit) {
|
|
93
|
+
return None;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let variant_struct_ident = variant_struct_ident(&variant.ident);
|
|
97
|
+
let field_types = variant.fields.iter().map(|f| &f.ty);
|
|
98
|
+
|
|
99
|
+
let variant_struct = parse_quote! {
|
|
100
|
+
#[repr(C)]
|
|
101
|
+
struct #variant_struct_ident #impl_generics (
|
|
102
|
+
#core::mem::MaybeUninit<___ZerocopyInnerTag>,
|
|
103
|
+
#(#field_types,)*
|
|
104
|
+
#phantom_ty,
|
|
105
|
+
) #where_clause;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// We do this rather than emitting `#[derive(::zerocopy::TryFromBytes)]`
|
|
109
|
+
// because that is not hygienic, and this is also more performant.
|
|
110
|
+
let try_from_bytes_impl =
|
|
111
|
+
derive_try_from_bytes(&ctx.with_input(&variant_struct), Trait::TryFromBytes)
|
|
112
|
+
.expect("derive_try_from_bytes should not fail on synthesized type");
|
|
113
|
+
|
|
114
|
+
Some(quote! {
|
|
115
|
+
#variant_struct
|
|
116
|
+
#try_from_bytes_impl
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
quote! {
|
|
121
|
+
#(#variant_structs)*
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
fn variants_union_field_ident(ident: &Ident) -> Ident {
|
|
126
|
+
// Field names are prefixed with `__field_` to prevent name collision
|
|
127
|
+
// with the `__nonempty` field.
|
|
128
|
+
ident!(("__field_{}", ident), ident.span())
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
fn generate_variants_union(ctx: &Ctx, data: &DataEnum) -> TokenStream {
|
|
132
|
+
let generics = &ctx.ast.generics;
|
|
133
|
+
let (_, ty_generics, _) = generics.split_for_impl();
|
|
134
|
+
|
|
135
|
+
let fields = data.variants.iter().filter_map(|variant| {
|
|
136
|
+
// We don't generate variant structs for unit variants because we only
|
|
137
|
+
// need to check the tag. This helps cut down our generated code a bit.
|
|
138
|
+
if matches!(variant.fields, Fields::Unit) {
|
|
139
|
+
return None;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let field_name = variants_union_field_ident(&variant.ident);
|
|
143
|
+
let variant_struct_ident = variant_struct_ident(&variant.ident);
|
|
144
|
+
|
|
145
|
+
let core = ctx.core_path();
|
|
146
|
+
Some(quote! {
|
|
147
|
+
#field_name: #core::mem::ManuallyDrop<#variant_struct_ident #ty_generics>,
|
|
148
|
+
})
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
let variants_union = parse_quote! {
|
|
152
|
+
#[repr(C)]
|
|
153
|
+
union ___ZerocopyVariants #generics {
|
|
154
|
+
#(#fields)*
|
|
155
|
+
// Enums can have variants with no fields, but unions must
|
|
156
|
+
// have at least one field. So we just add a trailing unit
|
|
157
|
+
// to ensure that this union always has at least one field.
|
|
158
|
+
// Because this union is `repr(C)`, this unit type does not
|
|
159
|
+
// affect the layout.
|
|
160
|
+
__nonempty: (),
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let has_field =
|
|
165
|
+
derive_has_field_struct_union(&ctx.with_input(&variants_union), &variants_union.data);
|
|
166
|
+
|
|
167
|
+
quote! {
|
|
168
|
+
#variants_union
|
|
169
|
+
#has_field
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// Generates an implementation of `is_bit_valid` for an arbitrary enum.
|
|
174
|
+
///
|
|
175
|
+
/// The general process is:
|
|
176
|
+
///
|
|
177
|
+
/// 1. Generate a tag enum. This is an enum with the same repr, variants, and
|
|
178
|
+
/// corresponding discriminants as the original enum, but without any fields
|
|
179
|
+
/// on the variants. This gives us access to an enum where the variants have
|
|
180
|
+
/// the same discriminants as the one we're writing `is_bit_valid` for.
|
|
181
|
+
/// 2. Make constants from the variants of the tag enum. We need these because
|
|
182
|
+
/// we can't put const exprs in match arms.
|
|
183
|
+
/// 3. Generate variant structs. These are structs which have the same fields as
|
|
184
|
+
/// each variant of the enum, and are `#[repr(C)]` with an optional "inner
|
|
185
|
+
/// tag".
|
|
186
|
+
/// 4. Generate a variants union, with one field for each variant struct type.
|
|
187
|
+
/// 5. And finally, our raw enum is a `#[repr(C)]` struct of an "outer tag" and
|
|
188
|
+
/// the variants union.
|
|
189
|
+
///
|
|
190
|
+
/// See these reference links for fully-worked example decompositions.
|
|
191
|
+
///
|
|
192
|
+
/// - `repr(C)`: <https://doc.rust-lang.org/reference/type-layout.html#reprc-enums-with-fields>
|
|
193
|
+
/// - `repr(int)`: <https://doc.rust-lang.org/reference/type-layout.html#primitive-representation-of-enums-with-fields>
|
|
194
|
+
/// - `repr(C, int)`: <https://doc.rust-lang.org/reference/type-layout.html#combining-primitive-representations-of-enums-with-fields-and-reprc>
|
|
195
|
+
pub(crate) fn derive_is_bit_valid(
|
|
196
|
+
ctx: &Ctx,
|
|
197
|
+
data: &DataEnum,
|
|
198
|
+
repr: &EnumRepr,
|
|
199
|
+
) -> Result<TokenStream, Error> {
|
|
200
|
+
let trait_path = Trait::TryFromBytes.crate_path(ctx);
|
|
201
|
+
let tag_enum = generate_tag_enum(ctx, repr, data);
|
|
202
|
+
let tag_consts = generate_tag_consts(data);
|
|
203
|
+
|
|
204
|
+
let (outer_tag_type, inner_tag_type) = if repr.is_c() {
|
|
205
|
+
(quote! { ___ZerocopyTag }, quote! { () })
|
|
206
|
+
} else if repr.is_primitive() {
|
|
207
|
+
(quote! { () }, quote! { ___ZerocopyTag })
|
|
208
|
+
} else {
|
|
209
|
+
return Err(Error::new(
|
|
210
|
+
ctx.ast.span(),
|
|
211
|
+
"must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout",
|
|
212
|
+
));
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
let variant_structs = generate_variant_structs(ctx, data);
|
|
216
|
+
let variants_union = generate_variants_union(ctx, data);
|
|
217
|
+
|
|
218
|
+
let (impl_generics, ty_generics, where_clause) = ctx.ast.generics.split_for_impl();
|
|
219
|
+
|
|
220
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
221
|
+
let has_tag = ImplBlockBuilder::new(ctx, data, Trait::HasTag, FieldBounds::None)
|
|
222
|
+
.inner_extras(quote! {
|
|
223
|
+
type Tag = ___ZerocopyTag;
|
|
224
|
+
type ProjectToTag = #zerocopy_crate::pointer::cast::CastSized;
|
|
225
|
+
})
|
|
226
|
+
.build();
|
|
227
|
+
let has_fields = data.variants().into_iter().flat_map(|(variant, fields)| {
|
|
228
|
+
let variant_ident = &variant.unwrap().ident;
|
|
229
|
+
let variants_union_field_ident = variants_union_field_ident(variant_ident);
|
|
230
|
+
let field: Box<syn::Type> = parse_quote!(());
|
|
231
|
+
fields.into_iter().enumerate().map(move |(idx, (vis, ident, ty))| {
|
|
232
|
+
// Rust does not presently support explicit visibility modifiers on
|
|
233
|
+
// enum fields, but we guard against the possibility to ensure this
|
|
234
|
+
// derive remains sound.
|
|
235
|
+
assert!(matches!(vis, syn::Visibility::Inherited));
|
|
236
|
+
let variant_struct_field_index = Index::from(idx + 1);
|
|
237
|
+
let (_, ty_generics, _) = ctx.ast.generics.split_for_impl();
|
|
238
|
+
let has_field_trait = Trait::HasField {
|
|
239
|
+
variant_id: parse_quote!({ #zerocopy_crate::ident_id!(#variant_ident) }),
|
|
240
|
+
// Since Rust does not presently support explicit visibility
|
|
241
|
+
// modifiers on enum fields, any public type is suitable here;
|
|
242
|
+
// we use `()`.
|
|
243
|
+
field: field.clone(),
|
|
244
|
+
field_id: parse_quote!({ #zerocopy_crate::ident_id!(#ident) }),
|
|
245
|
+
};
|
|
246
|
+
let has_field_path = has_field_trait.crate_path(ctx);
|
|
247
|
+
let has_field = ImplBlockBuilder::new(
|
|
248
|
+
ctx,
|
|
249
|
+
data,
|
|
250
|
+
has_field_trait,
|
|
251
|
+
FieldBounds::None,
|
|
252
|
+
)
|
|
253
|
+
.inner_extras(quote! {
|
|
254
|
+
type Type = #ty;
|
|
255
|
+
|
|
256
|
+
#[inline(always)]
|
|
257
|
+
fn project(slf: #zerocopy_crate::pointer::PtrInner<'_, Self>) -> *mut <Self as #has_field_path>::Type {
|
|
258
|
+
use #zerocopy_crate::pointer::cast::{CastSized, Projection};
|
|
259
|
+
|
|
260
|
+
slf.project::<___ZerocopyRawEnum #ty_generics, CastSized>()
|
|
261
|
+
.project::<_, Projection<_, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(variants) }>>()
|
|
262
|
+
.project::<_, Projection<_, { #zerocopy_crate::REPR_C_UNION_VARIANT_ID }, { #zerocopy_crate::ident_id!(#variants_union_field_ident) }>>()
|
|
263
|
+
.project::<_, Projection<_, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(value) }>>()
|
|
264
|
+
.project::<_, Projection<_, { #zerocopy_crate::STRUCT_VARIANT_ID }, { #zerocopy_crate::ident_id!(#variant_struct_field_index) }>>()
|
|
265
|
+
.as_ptr()
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
.build();
|
|
269
|
+
|
|
270
|
+
let project = ImplBlockBuilder::new(
|
|
271
|
+
ctx,
|
|
272
|
+
data,
|
|
273
|
+
Trait::ProjectField {
|
|
274
|
+
variant_id: parse_quote!({ #zerocopy_crate::ident_id!(#variant_ident) }),
|
|
275
|
+
// Since Rust does not presently support explicit visibility
|
|
276
|
+
// modifiers on enum fields, any public type is suitable
|
|
277
|
+
// here; we use `()`.
|
|
278
|
+
field: field.clone(),
|
|
279
|
+
field_id: parse_quote!({ #zerocopy_crate::ident_id!(#ident) }),
|
|
280
|
+
invariants: parse_quote!((Aliasing, Alignment, #zerocopy_crate::invariant::Initialized)),
|
|
281
|
+
},
|
|
282
|
+
FieldBounds::None,
|
|
283
|
+
)
|
|
284
|
+
.param_extras(vec![
|
|
285
|
+
parse_quote!(Aliasing: #zerocopy_crate::invariant::Aliasing),
|
|
286
|
+
parse_quote!(Alignment: #zerocopy_crate::invariant::Alignment),
|
|
287
|
+
])
|
|
288
|
+
.inner_extras(quote! {
|
|
289
|
+
type Error = #zerocopy_crate::util::macro_util::core_reexport::convert::Infallible;
|
|
290
|
+
type Invariants = (Aliasing, Alignment, #zerocopy_crate::invariant::Initialized);
|
|
291
|
+
})
|
|
292
|
+
.build();
|
|
293
|
+
|
|
294
|
+
quote! {
|
|
295
|
+
#has_field
|
|
296
|
+
#project
|
|
297
|
+
}
|
|
298
|
+
})
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
let core = ctx.core_path();
|
|
302
|
+
let match_arms = data.variants.iter().map(|variant| {
|
|
303
|
+
let tag_ident = tag_ident(&variant.ident);
|
|
304
|
+
let variant_struct_ident = variant_struct_ident(&variant.ident);
|
|
305
|
+
let variants_union_field_ident = variants_union_field_ident(&variant.ident);
|
|
306
|
+
|
|
307
|
+
if matches!(variant.fields, Fields::Unit) {
|
|
308
|
+
// Unit variants don't need any further validation beyond checking
|
|
309
|
+
// the tag.
|
|
310
|
+
quote! {
|
|
311
|
+
#tag_ident => true
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
quote! {
|
|
315
|
+
#tag_ident => {
|
|
316
|
+
// SAFETY: Since we know that the tag is `#tag_ident`, we
|
|
317
|
+
// know that no other `&`s exist which refer to this enum
|
|
318
|
+
// as any other variant.
|
|
319
|
+
let variant_md = variants.cast::<
|
|
320
|
+
_,
|
|
321
|
+
#zerocopy_crate::pointer::cast::Projection<
|
|
322
|
+
// #zerocopy_crate::ReadOnly<_>,
|
|
323
|
+
_,
|
|
324
|
+
{ #zerocopy_crate::REPR_C_UNION_VARIANT_ID },
|
|
325
|
+
{ #zerocopy_crate::ident_id!(#variants_union_field_ident) }
|
|
326
|
+
>,
|
|
327
|
+
_
|
|
328
|
+
>();
|
|
329
|
+
let variant = variant_md.cast::<
|
|
330
|
+
#zerocopy_crate::ReadOnly<#variant_struct_ident #ty_generics>,
|
|
331
|
+
#zerocopy_crate::pointer::cast::CastSized,
|
|
332
|
+
(#zerocopy_crate::pointer::BecauseRead, _)
|
|
333
|
+
>();
|
|
334
|
+
<
|
|
335
|
+
#variant_struct_ident #ty_generics as #trait_path
|
|
336
|
+
>::is_bit_valid(variant)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
let generics = &ctx.ast.generics;
|
|
343
|
+
let raw_enum: DeriveInput = parse_quote! {
|
|
344
|
+
#[repr(C)]
|
|
345
|
+
struct ___ZerocopyRawEnum #generics {
|
|
346
|
+
tag: ___ZerocopyOuterTag,
|
|
347
|
+
variants: ___ZerocopyVariants #ty_generics,
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
let self_ident = &ctx.ast.ident;
|
|
352
|
+
let invariants_eq_impl = quote! {
|
|
353
|
+
// SAFETY: `___ZerocopyRawEnum` is designed to have the same layout,
|
|
354
|
+
// validity, and invariants as `Self`.
|
|
355
|
+
unsafe impl #impl_generics #zerocopy_crate::pointer::InvariantsEq<___ZerocopyRawEnum #ty_generics> for #self_ident #ty_generics #where_clause {}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
let raw_enum_projections =
|
|
359
|
+
derive_has_field_struct_union(&ctx.with_input(&raw_enum), &raw_enum.data);
|
|
360
|
+
|
|
361
|
+
let raw_enum = quote! {
|
|
362
|
+
#raw_enum
|
|
363
|
+
#invariants_eq_impl
|
|
364
|
+
#raw_enum_projections
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
Ok(quote! {
|
|
368
|
+
// SAFETY: We use `is_bit_valid` to validate that the bit pattern of the
|
|
369
|
+
// enum's tag corresponds to one of the enum's discriminants. Then, we
|
|
370
|
+
// check the bit validity of each field of the corresponding variant.
|
|
371
|
+
// Thus, this is a sound implementation of `is_bit_valid`.
|
|
372
|
+
fn is_bit_valid(
|
|
373
|
+
mut candidate: #zerocopy_crate::Maybe<'_, Self>,
|
|
374
|
+
) -> #core::primitive::bool {
|
|
375
|
+
#tag_enum
|
|
376
|
+
|
|
377
|
+
type ___ZerocopyTagPrimitive = #zerocopy_crate::util::macro_util::SizeToTag<
|
|
378
|
+
{ #core::mem::size_of::<___ZerocopyTag>() },
|
|
379
|
+
>;
|
|
380
|
+
|
|
381
|
+
#tag_consts
|
|
382
|
+
|
|
383
|
+
type ___ZerocopyOuterTag = #outer_tag_type;
|
|
384
|
+
type ___ZerocopyInnerTag = #inner_tag_type;
|
|
385
|
+
|
|
386
|
+
#variant_structs
|
|
387
|
+
|
|
388
|
+
#variants_union
|
|
389
|
+
|
|
390
|
+
#raw_enum
|
|
391
|
+
|
|
392
|
+
#has_tag
|
|
393
|
+
|
|
394
|
+
#(#has_fields)*
|
|
395
|
+
|
|
396
|
+
let tag = {
|
|
397
|
+
// SAFETY:
|
|
398
|
+
// - The provided cast addresses a subset of the bytes addressed
|
|
399
|
+
// by `candidate` because it addresses the starting tag of the
|
|
400
|
+
// enum.
|
|
401
|
+
// - Because the pointer is cast from `candidate`, it has the
|
|
402
|
+
// same provenance as it.
|
|
403
|
+
// - There are no `UnsafeCell`s in the tag because it is a
|
|
404
|
+
// primitive integer.
|
|
405
|
+
// - `tag_ptr` is casted from `candidate`, whose referent is
|
|
406
|
+
// `Initialized`. Since we have not written uninitialized
|
|
407
|
+
// bytes into the referent, `tag_ptr` is also `Initialized`.
|
|
408
|
+
//
|
|
409
|
+
// FIXME(#2874): Revise this to a `cast` once `candidate`
|
|
410
|
+
// references a `ReadOnly<Self>`.
|
|
411
|
+
let tag_ptr = unsafe {
|
|
412
|
+
candidate.reborrow().project_transmute_unchecked::<
|
|
413
|
+
_,
|
|
414
|
+
#zerocopy_crate::invariant::Initialized,
|
|
415
|
+
#zerocopy_crate::pointer::cast::CastSized
|
|
416
|
+
>()
|
|
417
|
+
};
|
|
418
|
+
tag_ptr.recall_validity::<_, (_, (_, _))>().read_unaligned::<#zerocopy_crate::BecauseImmutable>()
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
let mut raw_enum = candidate.cast::<
|
|
422
|
+
#zerocopy_crate::ReadOnly<___ZerocopyRawEnum #ty_generics>,
|
|
423
|
+
#zerocopy_crate::pointer::cast::CastSized,
|
|
424
|
+
(#zerocopy_crate::pointer::BecauseRead, _)
|
|
425
|
+
>();
|
|
426
|
+
|
|
427
|
+
let variants = #zerocopy_crate::into_inner!(raw_enum.project::<
|
|
428
|
+
_,
|
|
429
|
+
{ #zerocopy_crate::STRUCT_VARIANT_ID },
|
|
430
|
+
{ #zerocopy_crate::ident_id!(variants) }
|
|
431
|
+
>());
|
|
432
|
+
|
|
433
|
+
match tag {
|
|
434
|
+
#(#match_arms,)*
|
|
435
|
+
_ => false,
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
pub(crate) fn derive_try_from_bytes(ctx: &Ctx, top_level: Trait) -> Result<TokenStream, Error> {
|
|
441
|
+
match &ctx.ast.data {
|
|
442
|
+
Data::Struct(strct) => derive_try_from_bytes_struct(ctx, strct, top_level),
|
|
443
|
+
Data::Enum(enm) => derive_try_from_bytes_enum(ctx, enm, top_level),
|
|
444
|
+
Data::Union(unn) => Ok(derive_try_from_bytes_union(ctx, unn, top_level)),
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
fn derive_has_field_struct_union(ctx: &Ctx, data: &dyn DataExt) -> TokenStream {
|
|
448
|
+
let fields = ctx.ast.data.fields();
|
|
449
|
+
if fields.is_empty() {
|
|
450
|
+
return quote! {};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
let field_tokens = fields.iter().map(|(vis, ident, _)| {
|
|
454
|
+
let ident = ident!(("ẕ{}", ident), ident.span());
|
|
455
|
+
quote!(
|
|
456
|
+
#vis enum #ident {}
|
|
457
|
+
)
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
461
|
+
let variant_id: Box<Expr> = match &ctx.ast.data {
|
|
462
|
+
Data::Struct(_) => parse_quote!({ #zerocopy_crate::STRUCT_VARIANT_ID }),
|
|
463
|
+
Data::Union(_) => {
|
|
464
|
+
let is_repr_c = StructUnionRepr::from_attrs(&ctx.ast.attrs)
|
|
465
|
+
.map(|repr| repr.is_c())
|
|
466
|
+
.unwrap_or(false);
|
|
467
|
+
if is_repr_c {
|
|
468
|
+
parse_quote!({ #zerocopy_crate::REPR_C_UNION_VARIANT_ID })
|
|
469
|
+
} else {
|
|
470
|
+
parse_quote!({ #zerocopy_crate::UNION_VARIANT_ID })
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
_ => unreachable!(),
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
let core = ctx.core_path();
|
|
477
|
+
let has_tag = ImplBlockBuilder::new(ctx, data, Trait::HasTag, FieldBounds::None)
|
|
478
|
+
.inner_extras(quote! {
|
|
479
|
+
type Tag = ();
|
|
480
|
+
type ProjectToTag = #zerocopy_crate::pointer::cast::CastToUnit;
|
|
481
|
+
})
|
|
482
|
+
.build();
|
|
483
|
+
let has_fields = fields.iter().map(move |(_, ident, ty)| {
|
|
484
|
+
let field_token = ident!(("ẕ{}", ident), ident.span());
|
|
485
|
+
let field: Box<Type> = parse_quote!(#field_token);
|
|
486
|
+
let field_id: Box<Expr> = parse_quote!({ #zerocopy_crate::ident_id!(#ident) });
|
|
487
|
+
let has_field_trait = Trait::HasField {
|
|
488
|
+
variant_id: variant_id.clone(),
|
|
489
|
+
field: field.clone(),
|
|
490
|
+
field_id: field_id.clone(),
|
|
491
|
+
};
|
|
492
|
+
let has_field_path = has_field_trait.crate_path(ctx);
|
|
493
|
+
ImplBlockBuilder::new(
|
|
494
|
+
ctx,
|
|
495
|
+
data,
|
|
496
|
+
has_field_trait,
|
|
497
|
+
FieldBounds::None,
|
|
498
|
+
)
|
|
499
|
+
.inner_extras(quote! {
|
|
500
|
+
type Type = #ty;
|
|
501
|
+
|
|
502
|
+
#[inline(always)]
|
|
503
|
+
fn project(slf: #zerocopy_crate::pointer::PtrInner<'_, Self>) -> *mut <Self as #has_field_path>::Type {
|
|
504
|
+
let slf = slf.as_ptr();
|
|
505
|
+
// SAFETY: By invariant on `PtrInner`, `slf` is a non-null
|
|
506
|
+
// pointer whose referent is zero-sized or lives in a valid
|
|
507
|
+
// allocation. Since `#ident` is a struct or union field of
|
|
508
|
+
// `Self`, this projection preserves or shrinks the referent
|
|
509
|
+
// size, and so the resulting referent also fits in the same
|
|
510
|
+
// allocation.
|
|
511
|
+
unsafe { #core::ptr::addr_of_mut!((*slf).#ident) }
|
|
512
|
+
}
|
|
513
|
+
}).outer_extras(if matches!(&ctx.ast.data, Data::Struct(..)) {
|
|
514
|
+
let fields_preserve_alignment = StructUnionRepr::from_attrs(&ctx.ast.attrs)
|
|
515
|
+
.map(|repr| repr.get_packed().is_none())
|
|
516
|
+
.unwrap();
|
|
517
|
+
let alignment = if fields_preserve_alignment {
|
|
518
|
+
quote! { Alignment }
|
|
519
|
+
} else {
|
|
520
|
+
quote! { #zerocopy_crate::invariant::Unaligned }
|
|
521
|
+
};
|
|
522
|
+
// SAFETY: See comments on items.
|
|
523
|
+
ImplBlockBuilder::new(
|
|
524
|
+
ctx,
|
|
525
|
+
data,
|
|
526
|
+
Trait::ProjectField {
|
|
527
|
+
variant_id: variant_id.clone(),
|
|
528
|
+
field: field.clone(),
|
|
529
|
+
field_id: field_id.clone(),
|
|
530
|
+
invariants: parse_quote!((Aliasing, Alignment, #zerocopy_crate::invariant::Initialized)),
|
|
531
|
+
},
|
|
532
|
+
FieldBounds::None,
|
|
533
|
+
)
|
|
534
|
+
.param_extras(vec![
|
|
535
|
+
parse_quote!(Aliasing: #zerocopy_crate::invariant::Aliasing),
|
|
536
|
+
parse_quote!(Alignment: #zerocopy_crate::invariant::Alignment),
|
|
537
|
+
])
|
|
538
|
+
.inner_extras(quote! {
|
|
539
|
+
// SAFETY: Projection into structs is always infallible.
|
|
540
|
+
type Error = #zerocopy_crate::util::macro_util::core_reexport::convert::Infallible;
|
|
541
|
+
// SAFETY: The alignment of the projected `Ptr` is `Unaligned`
|
|
542
|
+
// if the structure is packed; otherwise inherited from the
|
|
543
|
+
// outer `Ptr`. If the validity of the outer pointer is
|
|
544
|
+
// `Initialized`, so too is the validity of its fields.
|
|
545
|
+
type Invariants = (Aliasing, #alignment, #zerocopy_crate::invariant::Initialized);
|
|
546
|
+
})
|
|
547
|
+
.build()
|
|
548
|
+
} else {
|
|
549
|
+
quote! {}
|
|
550
|
+
})
|
|
551
|
+
.build()
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
const_block(field_tokens.into_iter().chain(Some(has_tag)).chain(has_fields).map(Some))
|
|
555
|
+
}
|
|
556
|
+
fn derive_try_from_bytes_struct(
|
|
557
|
+
ctx: &Ctx,
|
|
558
|
+
strct: &DataStruct,
|
|
559
|
+
top_level: Trait,
|
|
560
|
+
) -> Result<TokenStream, Error> {
|
|
561
|
+
let extras = try_gen_trivial_is_bit_valid(ctx, top_level).unwrap_or_else(|| {
|
|
562
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
563
|
+
let fields = strct.fields();
|
|
564
|
+
let field_names = fields.iter().map(|(_vis, name, _ty)| name);
|
|
565
|
+
let field_tys = fields.iter().map(|(_vis, _name, ty)| ty);
|
|
566
|
+
let core = ctx.core_path();
|
|
567
|
+
quote!(
|
|
568
|
+
// SAFETY: We use `is_bit_valid` to validate that each field is
|
|
569
|
+
// bit-valid, and only return `true` if all of them are. The bit
|
|
570
|
+
// validity of a struct is just the composition of the bit
|
|
571
|
+
// validities of its fields, so this is a sound implementation
|
|
572
|
+
// of `is_bit_valid`.
|
|
573
|
+
fn is_bit_valid(
|
|
574
|
+
mut candidate: #zerocopy_crate::Maybe<Self>,
|
|
575
|
+
) -> #core::primitive::bool {
|
|
576
|
+
true #(&& {
|
|
577
|
+
let field_candidate = #zerocopy_crate::into_inner!(candidate.reborrow().project::<
|
|
578
|
+
_,
|
|
579
|
+
{ #zerocopy_crate::STRUCT_VARIANT_ID },
|
|
580
|
+
{ #zerocopy_crate::ident_id!(#field_names) }
|
|
581
|
+
>());
|
|
582
|
+
<#field_tys as #zerocopy_crate::TryFromBytes>::is_bit_valid(field_candidate)
|
|
583
|
+
})*
|
|
584
|
+
}
|
|
585
|
+
)
|
|
586
|
+
});
|
|
587
|
+
Ok(ImplBlockBuilder::new(ctx, strct, Trait::TryFromBytes, FieldBounds::ALL_SELF)
|
|
588
|
+
.inner_extras(extras)
|
|
589
|
+
.outer_extras(derive_has_field_struct_union(ctx, strct))
|
|
590
|
+
.build())
|
|
591
|
+
}
|
|
592
|
+
fn derive_try_from_bytes_union(ctx: &Ctx, unn: &DataUnion, top_level: Trait) -> TokenStream {
|
|
593
|
+
let field_type_trait_bounds = FieldBounds::All(&[TraitBound::Slf]);
|
|
594
|
+
|
|
595
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
596
|
+
let variant_id: Box<Expr> = {
|
|
597
|
+
let is_repr_c =
|
|
598
|
+
StructUnionRepr::from_attrs(&ctx.ast.attrs).map(|repr| repr.is_c()).unwrap_or(false);
|
|
599
|
+
if is_repr_c {
|
|
600
|
+
parse_quote!({ #zerocopy_crate::REPR_C_UNION_VARIANT_ID })
|
|
601
|
+
} else {
|
|
602
|
+
parse_quote!({ #zerocopy_crate::UNION_VARIANT_ID })
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
let extras = try_gen_trivial_is_bit_valid(ctx, top_level).unwrap_or_else(|| {
|
|
607
|
+
let fields = unn.fields();
|
|
608
|
+
let field_names = fields.iter().map(|(_vis, name, _ty)| name);
|
|
609
|
+
let field_tys = fields.iter().map(|(_vis, _name, ty)| ty);
|
|
610
|
+
let core = ctx.core_path();
|
|
611
|
+
quote!(
|
|
612
|
+
// SAFETY: We use `is_bit_valid` to validate that any field is
|
|
613
|
+
// bit-valid; we only return `true` if at least one of them is.
|
|
614
|
+
// The bit validity of a union is not yet well defined in Rust,
|
|
615
|
+
// but it is guaranteed to be no more strict than this
|
|
616
|
+
// definition. See #696 for a more in-depth discussion.
|
|
617
|
+
fn is_bit_valid(
|
|
618
|
+
mut candidate: #zerocopy_crate::Maybe<'_, Self>,
|
|
619
|
+
) -> #core::primitive::bool {
|
|
620
|
+
false #(|| {
|
|
621
|
+
// SAFETY:
|
|
622
|
+
// - Since `ReadOnly<Self>: Immutable` unconditionally,
|
|
623
|
+
// neither `*slf` nor the returned pointer's referent
|
|
624
|
+
// permit interior mutation.
|
|
625
|
+
// - Both source and destination validity are
|
|
626
|
+
// `Initialized`, which is always a sound
|
|
627
|
+
// transmutation.
|
|
628
|
+
let field_candidate = unsafe {
|
|
629
|
+
candidate.reborrow().project_transmute_unchecked::<
|
|
630
|
+
_,
|
|
631
|
+
_,
|
|
632
|
+
#zerocopy_crate::pointer::cast::Projection<
|
|
633
|
+
_,
|
|
634
|
+
#variant_id,
|
|
635
|
+
{ #zerocopy_crate::ident_id!(#field_names) }
|
|
636
|
+
>
|
|
637
|
+
>()
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
<#field_tys as #zerocopy_crate::TryFromBytes>::is_bit_valid(field_candidate)
|
|
641
|
+
})*
|
|
642
|
+
}
|
|
643
|
+
)
|
|
644
|
+
});
|
|
645
|
+
ImplBlockBuilder::new(ctx, unn, Trait::TryFromBytes, field_type_trait_bounds)
|
|
646
|
+
.inner_extras(extras)
|
|
647
|
+
.outer_extras(derive_has_field_struct_union(ctx, unn))
|
|
648
|
+
.build()
|
|
649
|
+
}
|
|
650
|
+
fn derive_try_from_bytes_enum(
|
|
651
|
+
ctx: &Ctx,
|
|
652
|
+
enm: &DataEnum,
|
|
653
|
+
top_level: Trait,
|
|
654
|
+
) -> Result<TokenStream, Error> {
|
|
655
|
+
let repr = EnumRepr::from_attrs(&ctx.ast.attrs)?;
|
|
656
|
+
|
|
657
|
+
// If an enum has no fields, it has a well-defined integer representation,
|
|
658
|
+
// and every possible bit pattern corresponds to a valid discriminant tag,
|
|
659
|
+
// then it *could* be `FromBytes` (even if the user hasn't derived
|
|
660
|
+
// `FromBytes`). This holds if, for `repr(uN)` or `repr(iN)`, there are 2^N
|
|
661
|
+
// variants.
|
|
662
|
+
let could_be_from_bytes = enum_size_from_repr(&repr)
|
|
663
|
+
.map(|size| enm.fields().is_empty() && enm.variants.len() == 1usize << size)
|
|
664
|
+
.unwrap_or(false);
|
|
665
|
+
|
|
666
|
+
let trivial_is_bit_valid = try_gen_trivial_is_bit_valid(ctx, top_level);
|
|
667
|
+
let extra = match (trivial_is_bit_valid, could_be_from_bytes) {
|
|
668
|
+
(Some(is_bit_valid), _) => is_bit_valid,
|
|
669
|
+
// SAFETY: It would be sound for the enum to implement `FromBytes`, as
|
|
670
|
+
// required by `gen_trivial_is_bit_valid_unchecked`.
|
|
671
|
+
(None, true) => unsafe { gen_trivial_is_bit_valid_unchecked(ctx) },
|
|
672
|
+
(None, false) => derive_is_bit_valid(ctx, enm, &repr)?,
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
Ok(ImplBlockBuilder::new(ctx, enm, Trait::TryFromBytes, FieldBounds::ALL_SELF)
|
|
676
|
+
.inner_extras(extra)
|
|
677
|
+
.build())
|
|
678
|
+
}
|
|
679
|
+
fn try_gen_trivial_is_bit_valid(ctx: &Ctx, top_level: Trait) -> Option<proc_macro2::TokenStream> {
|
|
680
|
+
// If the top-level trait is `FromBytes` and `Self` has no type parameters,
|
|
681
|
+
// then the `FromBytes` derive will fail compilation if `Self` is not
|
|
682
|
+
// actually soundly `FromBytes`, and so we can rely on that for our
|
|
683
|
+
// `is_bit_valid` impl. It's plausible that we could make changes - or Rust
|
|
684
|
+
// could make changes (such as the "trivial bounds" language feature) - that
|
|
685
|
+
// make this no longer true. To hedge against these, we include an explicit
|
|
686
|
+
// `Self: FromBytes` check in the generated `is_bit_valid`, which is
|
|
687
|
+
// bulletproof.
|
|
688
|
+
if matches!(top_level, Trait::FromBytes) && ctx.ast.generics.params.is_empty() {
|
|
689
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
690
|
+
let core = ctx.core_path();
|
|
691
|
+
Some(quote!(
|
|
692
|
+
// SAFETY: See inline.
|
|
693
|
+
fn is_bit_valid(
|
|
694
|
+
_candidate: #zerocopy_crate::Maybe<Self>,
|
|
695
|
+
) -> #core::primitive::bool {
|
|
696
|
+
if false {
|
|
697
|
+
fn assert_is_from_bytes<T>()
|
|
698
|
+
where
|
|
699
|
+
T: #zerocopy_crate::FromBytes,
|
|
700
|
+
T: ?#core::marker::Sized,
|
|
701
|
+
{
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
assert_is_from_bytes::<Self>();
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// SAFETY: The preceding code only compiles if `Self:
|
|
708
|
+
// FromBytes`. Thus, this code only compiles if all initialized
|
|
709
|
+
// byte sequences represent valid instances of `Self`.
|
|
710
|
+
true
|
|
711
|
+
}
|
|
712
|
+
))
|
|
713
|
+
} else {
|
|
714
|
+
None
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
unsafe fn gen_trivial_is_bit_valid_unchecked(ctx: &Ctx) -> proc_macro2::TokenStream {
|
|
718
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
719
|
+
let core = ctx.core_path();
|
|
720
|
+
quote!(
|
|
721
|
+
// SAFETY: The caller of `gen_trivial_is_bit_valid_unchecked` has
|
|
722
|
+
// promised that all initialized bit patterns are valid for `Self`.
|
|
723
|
+
fn is_bit_valid(
|
|
724
|
+
_candidate: #zerocopy_crate::Maybe<Self>,
|
|
725
|
+
) -> #core::primitive::bool {
|
|
726
|
+
true
|
|
727
|
+
}
|
|
728
|
+
)
|
|
729
|
+
}
|