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,158 @@
|
|
|
1
|
+
use proc_macro2::{Span, TokenStream};
|
|
2
|
+
use quote::quote;
|
|
3
|
+
use syn::{Data, DataEnum, DataStruct, DataUnion, Error, Type};
|
|
4
|
+
|
|
5
|
+
use crate::{
|
|
6
|
+
repr::{EnumRepr, StructUnionRepr},
|
|
7
|
+
util::{
|
|
8
|
+
generate_tag_enum, Ctx, DataExt, FieldBounds, ImplBlockBuilder, PaddingCheck, Trait,
|
|
9
|
+
TraitBound,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
pub(crate) fn derive_into_bytes(ctx: &Ctx, _top_level: Trait) -> Result<TokenStream, Error> {
|
|
13
|
+
match &ctx.ast.data {
|
|
14
|
+
Data::Struct(strct) => derive_into_bytes_struct(ctx, strct),
|
|
15
|
+
Data::Enum(enm) => derive_into_bytes_enum(ctx, enm),
|
|
16
|
+
Data::Union(unn) => derive_into_bytes_union(ctx, unn),
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
fn derive_into_bytes_struct(ctx: &Ctx, strct: &DataStruct) -> Result<TokenStream, Error> {
|
|
20
|
+
let repr = StructUnionRepr::from_attrs(&ctx.ast.attrs)?;
|
|
21
|
+
|
|
22
|
+
let is_transparent = repr.is_transparent();
|
|
23
|
+
let is_c = repr.is_c();
|
|
24
|
+
let is_packed_1 = repr.is_packed_1();
|
|
25
|
+
let num_fields = strct.fields().len();
|
|
26
|
+
|
|
27
|
+
let (padding_check, require_unaligned_fields) = if is_transparent || is_packed_1 {
|
|
28
|
+
// No padding check needed.
|
|
29
|
+
// - repr(transparent): The layout and ABI of the whole struct is the
|
|
30
|
+
// same as its only non-ZST field (meaning there's no padding outside
|
|
31
|
+
// of that field) and we require that field to be `IntoBytes` (meaning
|
|
32
|
+
// there's no padding in that field).
|
|
33
|
+
// - repr(packed): Any inter-field padding bytes are removed, meaning
|
|
34
|
+
// that any padding bytes would need to come from the fields, all of
|
|
35
|
+
// which we require to be `IntoBytes` (meaning they don't have any
|
|
36
|
+
// padding). Note that this holds regardless of other `repr`
|
|
37
|
+
// attributes, including `repr(Rust)`. [1]
|
|
38
|
+
//
|
|
39
|
+
// [1] Per https://doc.rust-lang.org/1.81.0/reference/type-layout.html#the-alignment-modifiers:
|
|
40
|
+
//
|
|
41
|
+
// An important consequence of these rules is that a type with
|
|
42
|
+
// `#[repr(packed(1))]`` (or `#[repr(packed)]``) will have no
|
|
43
|
+
// inter-field padding.
|
|
44
|
+
(None, false)
|
|
45
|
+
} else if is_c && !repr.is_align_gt_1() && num_fields <= 1 {
|
|
46
|
+
// No padding check needed. A repr(C) struct with zero or one field has
|
|
47
|
+
// no padding unless #[repr(align)] explicitly adds padding, which we
|
|
48
|
+
// check for in this branch's condition.
|
|
49
|
+
(None, false)
|
|
50
|
+
} else if ctx.ast.generics.params.is_empty() {
|
|
51
|
+
// Is the last field a syntactic slice, i.e., `[SomeType]`.
|
|
52
|
+
let is_syntactic_dst =
|
|
53
|
+
strct.fields().last().map(|(_, _, ty)| matches!(ty, Type::Slice(_))).unwrap_or(false);
|
|
54
|
+
// Since there are no generics, we can emit a padding check. All reprs
|
|
55
|
+
// guarantee that fields won't overlap [1], so the padding check is
|
|
56
|
+
// sound. This is more permissive than the next case, which requires
|
|
57
|
+
// that all field types implement `Unaligned`.
|
|
58
|
+
//
|
|
59
|
+
// [1] Per https://doc.rust-lang.org/1.81.0/reference/type-layout.html#the-rust-representation:
|
|
60
|
+
//
|
|
61
|
+
// The only data layout guarantees made by [`repr(Rust)`] are those
|
|
62
|
+
// required for soundness. They are:
|
|
63
|
+
// ...
|
|
64
|
+
// 2. The fields do not overlap.
|
|
65
|
+
// ...
|
|
66
|
+
if is_c && is_syntactic_dst {
|
|
67
|
+
(Some(PaddingCheck::ReprCStruct), false)
|
|
68
|
+
} else {
|
|
69
|
+
(Some(PaddingCheck::Struct), false)
|
|
70
|
+
}
|
|
71
|
+
} else if is_c && !repr.is_align_gt_1() {
|
|
72
|
+
// We can't use a padding check since there are generic type arguments.
|
|
73
|
+
// Instead, we require all field types to implement `Unaligned`. This
|
|
74
|
+
// ensures that the `repr(C)` layout algorithm will not insert any
|
|
75
|
+
// padding unless #[repr(align)] explicitly adds padding, which we check
|
|
76
|
+
// for in this branch's condition.
|
|
77
|
+
//
|
|
78
|
+
// FIXME(#10): Support type parameters for non-transparent, non-packed
|
|
79
|
+
// structs without requiring `Unaligned`.
|
|
80
|
+
(None, true)
|
|
81
|
+
} else {
|
|
82
|
+
return Err(Error::new(
|
|
83
|
+
Span::call_site(),
|
|
84
|
+
"must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout",
|
|
85
|
+
));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
let field_bounds = if require_unaligned_fields {
|
|
89
|
+
FieldBounds::All(&[TraitBound::Slf, TraitBound::Other(Trait::Unaligned)])
|
|
90
|
+
} else {
|
|
91
|
+
FieldBounds::ALL_SELF
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
Ok(ImplBlockBuilder::new(ctx, strct, Trait::IntoBytes, field_bounds)
|
|
95
|
+
.padding_check(padding_check)
|
|
96
|
+
.build())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn derive_into_bytes_enum(ctx: &Ctx, enm: &DataEnum) -> Result<TokenStream, Error> {
|
|
100
|
+
let repr = EnumRepr::from_attrs(&ctx.ast.attrs)?;
|
|
101
|
+
if !repr.is_c() && !repr.is_primitive() {
|
|
102
|
+
return Err(Error::new(
|
|
103
|
+
Span::call_site(),
|
|
104
|
+
"must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout",
|
|
105
|
+
));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let tag_type_definition = generate_tag_enum(ctx, &repr, enm);
|
|
109
|
+
Ok(ImplBlockBuilder::new(ctx, enm, Trait::IntoBytes, FieldBounds::ALL_SELF)
|
|
110
|
+
.padding_check(PaddingCheck::Enum { tag_type_definition })
|
|
111
|
+
.build())
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
fn derive_into_bytes_union(ctx: &Ctx, unn: &DataUnion) -> Result<TokenStream, Error> {
|
|
115
|
+
// See #1792 for more context.
|
|
116
|
+
//
|
|
117
|
+
// By checking for `zerocopy_derive_union_into_bytes` both here and in the
|
|
118
|
+
// generated code, we ensure that `--cfg zerocopy_derive_union_into_bytes`
|
|
119
|
+
// need only be passed *either* when compiling this crate *or* when
|
|
120
|
+
// compiling the user's crate. The former is preferable, but in some
|
|
121
|
+
// situations (such as when cross-compiling using `cargo build --target`),
|
|
122
|
+
// it doesn't get propagated to this crate's build by default.
|
|
123
|
+
let cfg_compile_error = if cfg!(zerocopy_derive_union_into_bytes) {
|
|
124
|
+
quote!()
|
|
125
|
+
} else {
|
|
126
|
+
let core = ctx.core_path();
|
|
127
|
+
let error_message = "requires --cfg zerocopy_derive_union_into_bytes;
|
|
128
|
+
please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802";
|
|
129
|
+
quote!(
|
|
130
|
+
const _: () = {
|
|
131
|
+
#[cfg(not(zerocopy_derive_union_into_bytes))]
|
|
132
|
+
#core::compile_error!(#error_message);
|
|
133
|
+
};
|
|
134
|
+
)
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// FIXME(#10): Support type parameters.
|
|
138
|
+
if !ctx.ast.generics.params.is_empty() {
|
|
139
|
+
return Err(Error::new(Span::call_site(), "unsupported on types with type parameters"));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Because we don't support generics, we don't need to worry about
|
|
143
|
+
// special-casing different reprs. So long as there is *some* repr which
|
|
144
|
+
// guarantees the layout, our `PaddingCheck::Union` guarantees that there is
|
|
145
|
+
// no padding.
|
|
146
|
+
let repr = StructUnionRepr::from_attrs(&ctx.ast.attrs)?;
|
|
147
|
+
if !repr.is_c() && !repr.is_transparent() && !repr.is_packed_1() {
|
|
148
|
+
return Err(Error::new(
|
|
149
|
+
Span::call_site(),
|
|
150
|
+
"must be #[repr(C)], #[repr(packed)], or #[repr(transparent)]",
|
|
151
|
+
));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let impl_block = ImplBlockBuilder::new(ctx, unn, Trait::IntoBytes, FieldBounds::ALL_SELF)
|
|
155
|
+
.padding_check(PaddingCheck::Union)
|
|
156
|
+
.build();
|
|
157
|
+
Ok(quote!(#cfg_compile_error #impl_block))
|
|
158
|
+
}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
use proc_macro2::TokenStream;
|
|
2
|
+
use quote::quote;
|
|
3
|
+
use syn::{parse_quote, Data, Error, Type};
|
|
4
|
+
|
|
5
|
+
use crate::{
|
|
6
|
+
repr::StructUnionRepr,
|
|
7
|
+
util::{Ctx, DataExt, FieldBounds, ImplBlockBuilder, SelfBounds, Trait},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
fn derive_known_layout_for_repr_c_struct<'a>(
|
|
11
|
+
ctx: &'a Ctx,
|
|
12
|
+
repr: &StructUnionRepr,
|
|
13
|
+
fields: &[(&'a syn::Visibility, TokenStream, &'a Type)],
|
|
14
|
+
) -> Option<(SelfBounds<'a>, TokenStream, Option<TokenStream>)> {
|
|
15
|
+
let (trailing_field, leading_fields) = fields.split_last()?;
|
|
16
|
+
|
|
17
|
+
let (_vis, trailing_field_name, trailing_field_ty) = trailing_field;
|
|
18
|
+
let leading_fields_tys = leading_fields.iter().map(|(_vis, _name, ty)| ty);
|
|
19
|
+
|
|
20
|
+
let core = ctx.core_path();
|
|
21
|
+
let repr_align = repr
|
|
22
|
+
.get_align()
|
|
23
|
+
.map(|align| {
|
|
24
|
+
let align = align.t.get();
|
|
25
|
+
quote!(#core::num::NonZeroUsize::new(#align as usize))
|
|
26
|
+
})
|
|
27
|
+
.unwrap_or_else(|| quote!(#core::option::Option::None));
|
|
28
|
+
let repr_packed = repr
|
|
29
|
+
.get_packed()
|
|
30
|
+
.map(|packed| {
|
|
31
|
+
let packed = packed.get();
|
|
32
|
+
quote!(#core::num::NonZeroUsize::new(#packed as usize))
|
|
33
|
+
})
|
|
34
|
+
.unwrap_or_else(|| quote!(#core::option::Option::None));
|
|
35
|
+
|
|
36
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
37
|
+
let make_methods = |trailing_field_ty| {
|
|
38
|
+
quote! {
|
|
39
|
+
// SAFETY:
|
|
40
|
+
// - The returned pointer has the same address and provenance as
|
|
41
|
+
// `bytes`:
|
|
42
|
+
// - The recursive call to `raw_from_ptr_len` preserves both
|
|
43
|
+
// address and provenance.
|
|
44
|
+
// - The `as` cast preserves both address and provenance.
|
|
45
|
+
// - `NonNull::new_unchecked` preserves both address and
|
|
46
|
+
// provenance.
|
|
47
|
+
// - If `Self` is a slice DST, the returned pointer encodes
|
|
48
|
+
// `elems` elements in the trailing slice:
|
|
49
|
+
// - This is true of the recursive call to `raw_from_ptr_len`.
|
|
50
|
+
// - `trailing.as_ptr() as *mut Self` preserves trailing slice
|
|
51
|
+
// element count [1].
|
|
52
|
+
// - `NonNull::new_unchecked` preserves trailing slice element
|
|
53
|
+
// count.
|
|
54
|
+
//
|
|
55
|
+
// [1] Per https://doc.rust-lang.org/reference/expressions/operator-expr.html#pointer-to-pointer-cast:
|
|
56
|
+
//
|
|
57
|
+
// `*const T`` / `*mut T` can be cast to `*const U` / `*mut U`
|
|
58
|
+
// with the following behavior:
|
|
59
|
+
// ...
|
|
60
|
+
// - If `T` and `U` are both unsized, the pointer is also
|
|
61
|
+
// returned unchanged. In particular, the metadata is
|
|
62
|
+
// preserved exactly.
|
|
63
|
+
//
|
|
64
|
+
// For instance, a cast from `*const [T]` to `*const [U]`
|
|
65
|
+
// preserves the number of elements. ... The same holds
|
|
66
|
+
// for str and any compound type whose unsized tail is a
|
|
67
|
+
// slice type, such as struct `Foo(i32, [u8])` or
|
|
68
|
+
// `(u64, Foo)`.
|
|
69
|
+
#[inline(always)]
|
|
70
|
+
fn raw_from_ptr_len(
|
|
71
|
+
bytes: #core::ptr::NonNull<u8>,
|
|
72
|
+
meta: <Self as #zerocopy_crate::KnownLayout>::PointerMetadata,
|
|
73
|
+
) -> #core::ptr::NonNull<Self> {
|
|
74
|
+
let trailing = <#trailing_field_ty as #zerocopy_crate::KnownLayout>::raw_from_ptr_len(bytes, meta);
|
|
75
|
+
let slf = trailing.as_ptr() as *mut Self;
|
|
76
|
+
// SAFETY: Constructed from `trailing`, which is non-null.
|
|
77
|
+
unsafe { #core::ptr::NonNull::new_unchecked(slf) }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#[inline(always)]
|
|
81
|
+
fn pointer_to_metadata(ptr: *mut Self) -> <Self as #zerocopy_crate::KnownLayout>::PointerMetadata {
|
|
82
|
+
<#trailing_field_ty>::pointer_to_metadata(ptr as *mut _)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
let inner_extras = {
|
|
88
|
+
let leading_fields_tys = leading_fields_tys.clone();
|
|
89
|
+
let methods = make_methods(*trailing_field_ty);
|
|
90
|
+
let (_, ty_generics, _) = ctx.ast.generics.split_for_impl();
|
|
91
|
+
|
|
92
|
+
quote!(
|
|
93
|
+
type PointerMetadata = <#trailing_field_ty as #zerocopy_crate::KnownLayout>::PointerMetadata;
|
|
94
|
+
|
|
95
|
+
type MaybeUninit = __ZerocopyKnownLayoutMaybeUninit #ty_generics;
|
|
96
|
+
|
|
97
|
+
// SAFETY: `LAYOUT` accurately describes the layout of `Self`.
|
|
98
|
+
// The documentation of `DstLayout::for_repr_c_struct` vows that
|
|
99
|
+
// invocations in this manner will accurately describe a type,
|
|
100
|
+
// so long as:
|
|
101
|
+
//
|
|
102
|
+
// - that type is `repr(C)`,
|
|
103
|
+
// - its fields are enumerated in the order they appear,
|
|
104
|
+
// - the presence of `repr_align` and `repr_packed` are
|
|
105
|
+
// correctly accounted for.
|
|
106
|
+
//
|
|
107
|
+
// We respect all three of these preconditions here. This
|
|
108
|
+
// expansion is only used if `is_repr_c_struct`, we enumerate
|
|
109
|
+
// the fields in order, and we extract the values of `align(N)`
|
|
110
|
+
// and `packed(N)`.
|
|
111
|
+
const LAYOUT: #zerocopy_crate::DstLayout = #zerocopy_crate::DstLayout::for_repr_c_struct(
|
|
112
|
+
#repr_align,
|
|
113
|
+
#repr_packed,
|
|
114
|
+
&[
|
|
115
|
+
#(#zerocopy_crate::DstLayout::for_type::<#leading_fields_tys>(),)*
|
|
116
|
+
<#trailing_field_ty as #zerocopy_crate::KnownLayout>::LAYOUT
|
|
117
|
+
],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
#methods
|
|
121
|
+
)
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
let outer_extras = {
|
|
125
|
+
let ident = &ctx.ast.ident;
|
|
126
|
+
let vis = &ctx.ast.vis;
|
|
127
|
+
let params = &ctx.ast.generics.params;
|
|
128
|
+
let (impl_generics, ty_generics, where_clause) = ctx.ast.generics.split_for_impl();
|
|
129
|
+
|
|
130
|
+
let predicates = if let Some(where_clause) = where_clause {
|
|
131
|
+
where_clause.predicates.clone()
|
|
132
|
+
} else {
|
|
133
|
+
Default::default()
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// Generate a valid ident for a type-level handle to a field of a
|
|
137
|
+
// given `name`.
|
|
138
|
+
let field_index = |name: &TokenStream| ident!(("__Zerocopy_Field_{}", name), ident.span());
|
|
139
|
+
|
|
140
|
+
let field_indices: Vec<_> =
|
|
141
|
+
fields.iter().map(|(_vis, name, _ty)| field_index(name)).collect();
|
|
142
|
+
|
|
143
|
+
// Define the collection of type-level field handles.
|
|
144
|
+
let field_defs = field_indices.iter().zip(fields).map(|(idx, (vis, _, _))| {
|
|
145
|
+
quote! {
|
|
146
|
+
#vis struct #idx;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
let field_impls = field_indices.iter().zip(fields).map(|(idx, (_, _, ty))| quote! {
|
|
151
|
+
// SAFETY: `#ty` is the type of `#ident`'s field at `#idx`.
|
|
152
|
+
//
|
|
153
|
+
// We implement `Field` for each field of the struct to create a
|
|
154
|
+
// projection from the field index to its type. This allows us
|
|
155
|
+
// to refer to the field's type in a way that respects `Self`
|
|
156
|
+
// hygiene. If we just copy-pasted the tokens of `#ty`, we
|
|
157
|
+
// would not respect `Self` hygiene, as `Self` would refer to
|
|
158
|
+
// the helper struct we are generating, not the derive target
|
|
159
|
+
// type.
|
|
160
|
+
unsafe impl #impl_generics #zerocopy_crate::util::macro_util::Field<#idx> for #ident #ty_generics
|
|
161
|
+
where
|
|
162
|
+
#predicates
|
|
163
|
+
{
|
|
164
|
+
type Type = #ty;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
let trailing_field_index = field_index(trailing_field_name);
|
|
169
|
+
let leading_field_indices =
|
|
170
|
+
leading_fields.iter().map(|(_vis, name, _ty)| field_index(name));
|
|
171
|
+
|
|
172
|
+
// We use `Field` to project the type of the trailing field. This is
|
|
173
|
+
// required to ensure that if the field type uses `Self`, it
|
|
174
|
+
// resolves to the derive target type, not the helper struct we are
|
|
175
|
+
// generating.
|
|
176
|
+
let trailing_field_ty = quote! {
|
|
177
|
+
<#ident #ty_generics as
|
|
178
|
+
#zerocopy_crate::util::macro_util::Field<#trailing_field_index>
|
|
179
|
+
>::Type
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
let methods = make_methods(&parse_quote! {
|
|
183
|
+
<#trailing_field_ty as #zerocopy_crate::KnownLayout>::MaybeUninit
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
let core = ctx.core_path();
|
|
187
|
+
|
|
188
|
+
quote! {
|
|
189
|
+
#(#field_defs)*
|
|
190
|
+
|
|
191
|
+
#(#field_impls)*
|
|
192
|
+
|
|
193
|
+
// SAFETY: This has the same layout as the derive target type,
|
|
194
|
+
// except that it admits uninit bytes. This is ensured by using
|
|
195
|
+
// the same repr as the target type, and by using field types
|
|
196
|
+
// which have the same layout as the target type's fields,
|
|
197
|
+
// except that they admit uninit bytes. We indirect through
|
|
198
|
+
// `Field` to ensure that occurrences of `Self` resolve to
|
|
199
|
+
// `#ty`, not `__ZerocopyKnownLayoutMaybeUninit` (see #2116).
|
|
200
|
+
#repr
|
|
201
|
+
#[doc(hidden)]
|
|
202
|
+
#vis struct __ZerocopyKnownLayoutMaybeUninit<#params> (
|
|
203
|
+
#(#core::mem::MaybeUninit<
|
|
204
|
+
<#ident #ty_generics as
|
|
205
|
+
#zerocopy_crate::util::macro_util::Field<#leading_field_indices>
|
|
206
|
+
>::Type
|
|
207
|
+
>,)*
|
|
208
|
+
// NOTE(#2302): We wrap in `ManuallyDrop` here in case the
|
|
209
|
+
// type we're operating on is both generic and
|
|
210
|
+
// `repr(packed)`. In that case, Rust needs to know that the
|
|
211
|
+
// type is *either* `Sized` or has a trivial `Drop`.
|
|
212
|
+
// `ManuallyDrop` has a trivial `Drop`, and so satisfies
|
|
213
|
+
// this requirement.
|
|
214
|
+
#core::mem::ManuallyDrop<
|
|
215
|
+
<#trailing_field_ty as #zerocopy_crate::KnownLayout>::MaybeUninit
|
|
216
|
+
>
|
|
217
|
+
)
|
|
218
|
+
where
|
|
219
|
+
#trailing_field_ty: #zerocopy_crate::KnownLayout,
|
|
220
|
+
#predicates;
|
|
221
|
+
|
|
222
|
+
// SAFETY: We largely defer to the `KnownLayout` implementation
|
|
223
|
+
// on the derive target type (both by using the same tokens, and
|
|
224
|
+
// by deferring to impl via type-level indirection). This is
|
|
225
|
+
// sound, since `__ZerocopyKnownLayoutMaybeUninit` is guaranteed
|
|
226
|
+
// to have the same layout as the derive target type, except
|
|
227
|
+
// that `__ZerocopyKnownLayoutMaybeUninit` admits uninit bytes.
|
|
228
|
+
unsafe impl #impl_generics #zerocopy_crate::KnownLayout for __ZerocopyKnownLayoutMaybeUninit #ty_generics
|
|
229
|
+
where
|
|
230
|
+
#trailing_field_ty: #zerocopy_crate::KnownLayout,
|
|
231
|
+
#predicates
|
|
232
|
+
{
|
|
233
|
+
fn only_derive_is_allowed_to_implement_this_trait() {}
|
|
234
|
+
|
|
235
|
+
type PointerMetadata = <#ident #ty_generics as #zerocopy_crate::KnownLayout>::PointerMetadata;
|
|
236
|
+
|
|
237
|
+
type MaybeUninit = Self;
|
|
238
|
+
|
|
239
|
+
const LAYOUT: #zerocopy_crate::DstLayout = <#ident #ty_generics as #zerocopy_crate::KnownLayout>::LAYOUT;
|
|
240
|
+
|
|
241
|
+
#methods
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
Some((SelfBounds::None, inner_extras, Some(outer_extras)))
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
pub(crate) fn derive(ctx: &Ctx, _top_level: Trait) -> Result<TokenStream, Error> {
|
|
250
|
+
// If this is a `repr(C)` struct, then `c_struct_repr` contains the entire
|
|
251
|
+
// `repr` attribute.
|
|
252
|
+
let c_struct_repr = match &ctx.ast.data {
|
|
253
|
+
Data::Struct(..) => {
|
|
254
|
+
let repr = StructUnionRepr::from_attrs(&ctx.ast.attrs)?;
|
|
255
|
+
if repr.is_c() {
|
|
256
|
+
Some(repr)
|
|
257
|
+
} else {
|
|
258
|
+
None
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
Data::Enum(..) | Data::Union(..) => None,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
let fields = ctx.ast.data.fields();
|
|
265
|
+
|
|
266
|
+
let (self_bounds, inner_extras, outer_extras) = c_struct_repr
|
|
267
|
+
.as_ref()
|
|
268
|
+
.and_then(|repr| {
|
|
269
|
+
derive_known_layout_for_repr_c_struct(ctx, repr, &fields)
|
|
270
|
+
})
|
|
271
|
+
.unwrap_or_else(|| {
|
|
272
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
273
|
+
let core = ctx.core_path();
|
|
274
|
+
|
|
275
|
+
// For enums, unions, and non-`repr(C)` structs, we require that
|
|
276
|
+
// `Self` is sized, and as a result don't need to reason about the
|
|
277
|
+
// internals of the type.
|
|
278
|
+
(
|
|
279
|
+
SelfBounds::SIZED,
|
|
280
|
+
quote!(
|
|
281
|
+
type PointerMetadata = ();
|
|
282
|
+
type MaybeUninit =
|
|
283
|
+
#core::mem::MaybeUninit<Self>;
|
|
284
|
+
|
|
285
|
+
// SAFETY: `LAYOUT` is guaranteed to accurately describe the
|
|
286
|
+
// layout of `Self`, because that is the documented safety
|
|
287
|
+
// contract of `DstLayout::for_type`.
|
|
288
|
+
const LAYOUT: #zerocopy_crate::DstLayout = #zerocopy_crate::DstLayout::for_type::<Self>();
|
|
289
|
+
|
|
290
|
+
// SAFETY: `.cast` preserves address and provenance.
|
|
291
|
+
//
|
|
292
|
+
// FIXME(#429): Add documentation to `.cast` that promises that
|
|
293
|
+
// it preserves provenance.
|
|
294
|
+
#[inline(always)]
|
|
295
|
+
fn raw_from_ptr_len(bytes: #core::ptr::NonNull<u8>, _meta: ()) -> #core::ptr::NonNull<Self> {
|
|
296
|
+
bytes.cast::<Self>()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
#[inline(always)]
|
|
300
|
+
fn pointer_to_metadata(_ptr: *mut Self) -> () {}
|
|
301
|
+
),
|
|
302
|
+
None,
|
|
303
|
+
)
|
|
304
|
+
});
|
|
305
|
+
Ok(match &ctx.ast.data {
|
|
306
|
+
Data::Struct(strct) => {
|
|
307
|
+
let require_trait_bound_on_field_types =
|
|
308
|
+
if matches!(self_bounds, SelfBounds::All(&[Trait::Sized])) {
|
|
309
|
+
FieldBounds::None
|
|
310
|
+
} else {
|
|
311
|
+
FieldBounds::TRAILING_SELF
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// A bound on the trailing field is required, since structs are
|
|
315
|
+
// unsized if their trailing field is unsized. Reflecting the layout
|
|
316
|
+
// of an usized trailing field requires that the field is
|
|
317
|
+
// `KnownLayout`.
|
|
318
|
+
ImplBlockBuilder::new(
|
|
319
|
+
ctx,
|
|
320
|
+
strct,
|
|
321
|
+
Trait::KnownLayout,
|
|
322
|
+
require_trait_bound_on_field_types,
|
|
323
|
+
)
|
|
324
|
+
.self_type_trait_bounds(self_bounds)
|
|
325
|
+
.inner_extras(inner_extras)
|
|
326
|
+
.outer_extras(outer_extras)
|
|
327
|
+
.build()
|
|
328
|
+
}
|
|
329
|
+
Data::Enum(enm) => {
|
|
330
|
+
// A bound on the trailing field is not required, since enums cannot
|
|
331
|
+
// currently be unsized.
|
|
332
|
+
ImplBlockBuilder::new(ctx, enm, Trait::KnownLayout, FieldBounds::None)
|
|
333
|
+
.self_type_trait_bounds(SelfBounds::SIZED)
|
|
334
|
+
.inner_extras(inner_extras)
|
|
335
|
+
.outer_extras(outer_extras)
|
|
336
|
+
.build()
|
|
337
|
+
}
|
|
338
|
+
Data::Union(unn) => {
|
|
339
|
+
// A bound on the trailing field is not required, since unions
|
|
340
|
+
// cannot currently be unsized.
|
|
341
|
+
ImplBlockBuilder::new(ctx, unn, Trait::KnownLayout, FieldBounds::None)
|
|
342
|
+
.self_type_trait_bounds(SelfBounds::SIZED)
|
|
343
|
+
.inner_extras(inner_extras)
|
|
344
|
+
.outer_extras(outer_extras)
|
|
345
|
+
.build()
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
pub mod from_bytes;
|
|
2
|
+
pub mod into_bytes;
|
|
3
|
+
pub mod known_layout;
|
|
4
|
+
pub mod try_from_bytes;
|
|
5
|
+
pub mod unaligned;
|
|
6
|
+
|
|
7
|
+
use proc_macro2::{Span, TokenStream};
|
|
8
|
+
use quote::quote;
|
|
9
|
+
use syn::{Data, Error};
|
|
10
|
+
|
|
11
|
+
use crate::{
|
|
12
|
+
repr::StructUnionRepr,
|
|
13
|
+
util::{Ctx, DataExt, FieldBounds, ImplBlockBuilder, Trait},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
pub(crate) fn derive_immutable(ctx: &Ctx, _top_level: Trait) -> TokenStream {
|
|
17
|
+
match &ctx.ast.data {
|
|
18
|
+
Data::Struct(strct) => {
|
|
19
|
+
ImplBlockBuilder::new(ctx, strct, Trait::Immutable, FieldBounds::ALL_SELF).build()
|
|
20
|
+
}
|
|
21
|
+
Data::Enum(enm) => {
|
|
22
|
+
ImplBlockBuilder::new(ctx, enm, Trait::Immutable, FieldBounds::ALL_SELF).build()
|
|
23
|
+
}
|
|
24
|
+
Data::Union(unn) => {
|
|
25
|
+
ImplBlockBuilder::new(ctx, unn, Trait::Immutable, FieldBounds::ALL_SELF).build()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub(crate) fn derive_hash(ctx: &Ctx, _top_level: Trait) -> Result<TokenStream, Error> {
|
|
31
|
+
// This doesn't delegate to `impl_block` because `impl_block` assumes it is
|
|
32
|
+
// deriving a `zerocopy`-defined trait, and these trait impls share a common
|
|
33
|
+
// shape that `Hash` does not. In particular, `zerocopy` traits contain a
|
|
34
|
+
// method that only `zerocopy_derive` macros are supposed to implement, and
|
|
35
|
+
// `impl_block` generating this trait method is incompatible with `Hash`.
|
|
36
|
+
let type_ident = &ctx.ast.ident;
|
|
37
|
+
let (impl_generics, ty_generics, where_clause) = ctx.ast.generics.split_for_impl();
|
|
38
|
+
let where_predicates = where_clause.map(|clause| &clause.predicates);
|
|
39
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
40
|
+
let core = ctx.core_path();
|
|
41
|
+
Ok(quote! {
|
|
42
|
+
impl #impl_generics #core::hash::Hash for #type_ident #ty_generics
|
|
43
|
+
where
|
|
44
|
+
Self: #zerocopy_crate::IntoBytes + #zerocopy_crate::Immutable,
|
|
45
|
+
#where_predicates
|
|
46
|
+
{
|
|
47
|
+
fn hash<H: #core::hash::Hasher>(&self, state: &mut H) {
|
|
48
|
+
#core::hash::Hasher::write(state, #zerocopy_crate::IntoBytes::as_bytes(self))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn hash_slice<H: #core::hash::Hasher>(data: &[Self], state: &mut H) {
|
|
52
|
+
#core::hash::Hasher::write(state, #zerocopy_crate::IntoBytes::as_bytes(data))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pub(crate) fn derive_eq(ctx: &Ctx, _top_level: Trait) -> Result<TokenStream, Error> {
|
|
59
|
+
// This doesn't delegate to `impl_block` because `impl_block` assumes it is
|
|
60
|
+
// deriving a `zerocopy`-defined trait, and these trait impls share a common
|
|
61
|
+
// shape that `Eq` does not. In particular, `zerocopy` traits contain a
|
|
62
|
+
// method that only `zerocopy_derive` macros are supposed to implement, and
|
|
63
|
+
// `impl_block` generating this trait method is incompatible with `Eq`.
|
|
64
|
+
let type_ident = &ctx.ast.ident;
|
|
65
|
+
let (impl_generics, ty_generics, where_clause) = ctx.ast.generics.split_for_impl();
|
|
66
|
+
let where_predicates = where_clause.map(|clause| &clause.predicates);
|
|
67
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
68
|
+
let core = ctx.core_path();
|
|
69
|
+
Ok(quote! {
|
|
70
|
+
impl #impl_generics #core::cmp::PartialEq for #type_ident #ty_generics
|
|
71
|
+
where
|
|
72
|
+
Self: #zerocopy_crate::IntoBytes + #zerocopy_crate::Immutable,
|
|
73
|
+
#where_predicates
|
|
74
|
+
{
|
|
75
|
+
fn eq(&self, other: &Self) -> bool {
|
|
76
|
+
#core::cmp::PartialEq::eq(
|
|
77
|
+
#zerocopy_crate::IntoBytes::as_bytes(self),
|
|
78
|
+
#zerocopy_crate::IntoBytes::as_bytes(other),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
impl #impl_generics #core::cmp::Eq for #type_ident #ty_generics
|
|
84
|
+
where
|
|
85
|
+
Self: #zerocopy_crate::IntoBytes + #zerocopy_crate::Immutable,
|
|
86
|
+
#where_predicates
|
|
87
|
+
{
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pub(crate) fn derive_split_at(ctx: &Ctx, _top_level: Trait) -> Result<TokenStream, Error> {
|
|
93
|
+
let repr = StructUnionRepr::from_attrs(&ctx.ast.attrs)?;
|
|
94
|
+
|
|
95
|
+
match &ctx.ast.data {
|
|
96
|
+
Data::Struct(_) => {}
|
|
97
|
+
Data::Enum(_) | Data::Union(_) => {
|
|
98
|
+
return Err(Error::new(Span::call_site(), "can only be applied to structs"));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
if repr.get_packed().is_some() {
|
|
103
|
+
return Err(Error::new(Span::call_site(), "must not have #[repr(packed)] attribute"));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if !(repr.is_c() || repr.is_transparent()) {
|
|
107
|
+
return Err(Error::new(
|
|
108
|
+
Span::call_site(),
|
|
109
|
+
"must have #[repr(C)] or #[repr(transparent)] in order to guarantee this type's layout is splitable",
|
|
110
|
+
));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let fields = ctx.ast.data.fields();
|
|
114
|
+
let trailing_field = if let Some(((_, _, trailing_field), _)) = fields.split_last() {
|
|
115
|
+
trailing_field
|
|
116
|
+
} else {
|
|
117
|
+
return Err(Error::new(Span::call_site(), "must at least one field"));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
121
|
+
// SAFETY: `#ty`, per the above checks, is `repr(C)` or `repr(transparent)`
|
|
122
|
+
// and is not packed; its trailing field is guaranteed to be well-aligned
|
|
123
|
+
// for its type. By invariant on `FieldBounds::TRAILING_SELF`, the trailing
|
|
124
|
+
// slice of the trailing field is also well-aligned for its type.
|
|
125
|
+
Ok(ImplBlockBuilder::new(ctx, &ctx.ast.data, Trait::SplitAt, FieldBounds::TRAILING_SELF)
|
|
126
|
+
.inner_extras(quote! {
|
|
127
|
+
type Elem = <#trailing_field as #zerocopy_crate::SplitAt>::Elem;
|
|
128
|
+
})
|
|
129
|
+
.build())
|
|
130
|
+
}
|