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,757 @@
|
|
|
1
|
+
// Copyright 2019 The Fuchsia Authors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
|
|
4
|
+
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
|
|
5
|
+
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
|
|
6
|
+
// This file may not be copied, modified, or distributed except according to
|
|
7
|
+
// those terms.
|
|
8
|
+
|
|
9
|
+
use proc_macro2::{Span, TokenStream};
|
|
10
|
+
use quote::{quote, ToTokens};
|
|
11
|
+
use syn::{
|
|
12
|
+
parse_quote, Data, DataEnum, DataStruct, DataUnion, DeriveInput, Error, Expr, ExprLit, Field,
|
|
13
|
+
GenericParam, Ident, Index, Lit, Meta, Path, Type, Variant, Visibility, WherePredicate,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
use crate::repr::{CompoundRepr, EnumRepr, PrimitiveRepr, Repr, Spanned};
|
|
17
|
+
|
|
18
|
+
pub(crate) struct Ctx {
|
|
19
|
+
pub(crate) ast: DeriveInput,
|
|
20
|
+
pub(crate) zerocopy_crate: Path,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
impl Ctx {
|
|
24
|
+
/// Attempt to extract a crate path from the provided attributes. Defaults to
|
|
25
|
+
/// `::zerocopy` if not found.
|
|
26
|
+
pub(crate) fn try_from_derive_input(ast: DeriveInput) -> Result<Self, Error> {
|
|
27
|
+
let mut path = parse_quote!(::zerocopy);
|
|
28
|
+
|
|
29
|
+
for attr in &ast.attrs {
|
|
30
|
+
if let Meta::List(ref meta_list) = attr.meta {
|
|
31
|
+
if meta_list.path.is_ident("zerocopy") {
|
|
32
|
+
attr.parse_nested_meta(|meta| {
|
|
33
|
+
if meta.path.is_ident("crate") {
|
|
34
|
+
let expr = meta.value().and_then(|value| value.parse());
|
|
35
|
+
if let Ok(Expr::Lit(ExprLit { lit: Lit::Str(lit), .. })) = expr {
|
|
36
|
+
if let Ok(path_lit) = lit.parse::<Ident>() {
|
|
37
|
+
path = parse_quote!(::#path_lit);
|
|
38
|
+
return Ok(());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return Err(Error::new(
|
|
43
|
+
Span::call_site(),
|
|
44
|
+
"`crate` attribute requires a path as the value",
|
|
45
|
+
));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Err(Error::new(
|
|
49
|
+
Span::call_site(),
|
|
50
|
+
format!(
|
|
51
|
+
"unknown attribute encountered: {}",
|
|
52
|
+
meta.path.into_token_stream()
|
|
53
|
+
),
|
|
54
|
+
))
|
|
55
|
+
})?;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Ok(Self { ast, zerocopy_crate: path })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
pub(crate) fn with_input(&self, input: &DeriveInput) -> Self {
|
|
64
|
+
Self { ast: input.clone(), zerocopy_crate: self.zerocopy_crate.clone() }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub(crate) fn core_path(&self) -> TokenStream {
|
|
68
|
+
let zerocopy_crate = &self.zerocopy_crate;
|
|
69
|
+
quote!(#zerocopy_crate::util::macro_util::core_reexport)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
pub(crate) trait DataExt {
|
|
74
|
+
/// Extracts the names and types of all fields. For enums, extracts the
|
|
75
|
+
/// names and types of fields from each variant. For tuple structs, the
|
|
76
|
+
/// names are the indices used to index into the struct (ie, `0`, `1`, etc).
|
|
77
|
+
///
|
|
78
|
+
/// FIXME: Extracting field names for enums doesn't really make sense. Types
|
|
79
|
+
/// makes sense because we don't care about where they live - we just care
|
|
80
|
+
/// about transitive ownership. But for field names, we'd only use them when
|
|
81
|
+
/// generating is_bit_valid, which cares about where they live.
|
|
82
|
+
fn fields(&self) -> Vec<(&Visibility, TokenStream, &Type)>;
|
|
83
|
+
|
|
84
|
+
fn variants(&self) -> Vec<(Option<&Variant>, Vec<(&Visibility, TokenStream, &Type)>)>;
|
|
85
|
+
|
|
86
|
+
fn tag(&self) -> Option<Ident>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
impl DataExt for Data {
|
|
90
|
+
fn fields(&self) -> Vec<(&Visibility, TokenStream, &Type)> {
|
|
91
|
+
match self {
|
|
92
|
+
Data::Struct(strc) => strc.fields(),
|
|
93
|
+
Data::Enum(enm) => enm.fields(),
|
|
94
|
+
Data::Union(un) => un.fields(),
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
fn variants(&self) -> Vec<(Option<&Variant>, Vec<(&Visibility, TokenStream, &Type)>)> {
|
|
99
|
+
match self {
|
|
100
|
+
Data::Struct(strc) => strc.variants(),
|
|
101
|
+
Data::Enum(enm) => enm.variants(),
|
|
102
|
+
Data::Union(un) => un.variants(),
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn tag(&self) -> Option<Ident> {
|
|
107
|
+
match self {
|
|
108
|
+
Data::Struct(strc) => strc.tag(),
|
|
109
|
+
Data::Enum(enm) => enm.tag(),
|
|
110
|
+
Data::Union(un) => un.tag(),
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
impl DataExt for DataStruct {
|
|
116
|
+
fn fields(&self) -> Vec<(&Visibility, TokenStream, &Type)> {
|
|
117
|
+
map_fields(&self.fields)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
fn variants(&self) -> Vec<(Option<&Variant>, Vec<(&Visibility, TokenStream, &Type)>)> {
|
|
121
|
+
vec![(None, self.fields())]
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
fn tag(&self) -> Option<Ident> {
|
|
125
|
+
None
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
impl DataExt for DataEnum {
|
|
130
|
+
fn fields(&self) -> Vec<(&Visibility, TokenStream, &Type)> {
|
|
131
|
+
map_fields(self.variants.iter().flat_map(|var| &var.fields))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
fn variants(&self) -> Vec<(Option<&Variant>, Vec<(&Visibility, TokenStream, &Type)>)> {
|
|
135
|
+
self.variants.iter().map(|var| (Some(var), map_fields(&var.fields))).collect()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
fn tag(&self) -> Option<Ident> {
|
|
139
|
+
Some(Ident::new("___ZerocopyTag", Span::call_site()))
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
impl DataExt for DataUnion {
|
|
144
|
+
fn fields(&self) -> Vec<(&Visibility, TokenStream, &Type)> {
|
|
145
|
+
map_fields(&self.fields.named)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
fn variants(&self) -> Vec<(Option<&Variant>, Vec<(&Visibility, TokenStream, &Type)>)> {
|
|
149
|
+
vec![(None, self.fields())]
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
fn tag(&self) -> Option<Ident> {
|
|
153
|
+
None
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
fn map_fields<'a>(
|
|
158
|
+
fields: impl 'a + IntoIterator<Item = &'a Field>,
|
|
159
|
+
) -> Vec<(&'a Visibility, TokenStream, &'a Type)> {
|
|
160
|
+
fields
|
|
161
|
+
.into_iter()
|
|
162
|
+
.enumerate()
|
|
163
|
+
.map(|(idx, f)| {
|
|
164
|
+
(
|
|
165
|
+
&f.vis,
|
|
166
|
+
f.ident
|
|
167
|
+
.as_ref()
|
|
168
|
+
.map(ToTokens::to_token_stream)
|
|
169
|
+
.unwrap_or_else(|| Index::from(idx).to_token_stream()),
|
|
170
|
+
&f.ty,
|
|
171
|
+
)
|
|
172
|
+
})
|
|
173
|
+
.collect()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
pub(crate) fn to_ident_str(t: &impl ToString) -> String {
|
|
177
|
+
let s = t.to_string();
|
|
178
|
+
if let Some(stripped) = s.strip_prefix("r#") {
|
|
179
|
+
stripped.to_string()
|
|
180
|
+
} else {
|
|
181
|
+
s
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/// This enum describes what kind of padding check needs to be generated for the
|
|
186
|
+
/// associated impl.
|
|
187
|
+
pub(crate) enum PaddingCheck {
|
|
188
|
+
/// Check that the sum of the fields' sizes exactly equals the struct's
|
|
189
|
+
/// size.
|
|
190
|
+
Struct,
|
|
191
|
+
/// Check that a `repr(C)` struct has no padding.
|
|
192
|
+
ReprCStruct,
|
|
193
|
+
/// Check that the size of each field exactly equals the union's size.
|
|
194
|
+
Union,
|
|
195
|
+
/// Check that every variant of the enum contains no padding.
|
|
196
|
+
///
|
|
197
|
+
/// Because doing so requires a tag enum, this padding check requires an
|
|
198
|
+
/// additional `TokenStream` which defines the tag enum as `___ZerocopyTag`.
|
|
199
|
+
Enum { tag_type_definition: TokenStream },
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
impl PaddingCheck {
|
|
203
|
+
/// Returns the idents of the trait to use and the macro to call in order to
|
|
204
|
+
/// validate that a type passes the relevant padding check.
|
|
205
|
+
pub(crate) fn validator_trait_and_macro_idents(&self) -> (Ident, Ident) {
|
|
206
|
+
let (trt, mcro) = match self {
|
|
207
|
+
PaddingCheck::Struct => ("PaddingFree", "struct_padding"),
|
|
208
|
+
PaddingCheck::ReprCStruct => ("DynamicPaddingFree", "repr_c_struct_has_padding"),
|
|
209
|
+
PaddingCheck::Union => ("PaddingFree", "union_padding"),
|
|
210
|
+
PaddingCheck::Enum { .. } => ("PaddingFree", "enum_padding"),
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
let trt = Ident::new(trt, Span::call_site());
|
|
214
|
+
let mcro = Ident::new(mcro, Span::call_site());
|
|
215
|
+
(trt, mcro)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/// Sometimes performing the padding check requires some additional
|
|
219
|
+
/// "context" code. For enums, this is the definition of the tag enum.
|
|
220
|
+
pub(crate) fn validator_macro_context(&self) -> Option<&TokenStream> {
|
|
221
|
+
match self {
|
|
222
|
+
PaddingCheck::Struct | PaddingCheck::ReprCStruct | PaddingCheck::Union => None,
|
|
223
|
+
PaddingCheck::Enum { tag_type_definition } => Some(tag_type_definition),
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
#[derive(Clone)]
|
|
229
|
+
pub(crate) enum Trait {
|
|
230
|
+
KnownLayout,
|
|
231
|
+
HasTag,
|
|
232
|
+
HasField {
|
|
233
|
+
variant_id: Box<Expr>,
|
|
234
|
+
field: Box<Type>,
|
|
235
|
+
field_id: Box<Expr>,
|
|
236
|
+
},
|
|
237
|
+
ProjectField {
|
|
238
|
+
variant_id: Box<Expr>,
|
|
239
|
+
field: Box<Type>,
|
|
240
|
+
field_id: Box<Expr>,
|
|
241
|
+
invariants: Box<Type>,
|
|
242
|
+
},
|
|
243
|
+
Immutable,
|
|
244
|
+
TryFromBytes,
|
|
245
|
+
FromZeros,
|
|
246
|
+
FromBytes,
|
|
247
|
+
IntoBytes,
|
|
248
|
+
Unaligned,
|
|
249
|
+
Sized,
|
|
250
|
+
ByteHash,
|
|
251
|
+
ByteEq,
|
|
252
|
+
SplitAt,
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
impl ToTokens for Trait {
|
|
256
|
+
fn to_tokens(&self, tokens: &mut TokenStream) {
|
|
257
|
+
// According to [1], the format of the derived `Debug`` output is not
|
|
258
|
+
// stable and therefore not guaranteed to represent the variant names.
|
|
259
|
+
// Indeed with the (unstable) `fmt-debug` compiler flag [2], it can
|
|
260
|
+
// return only a minimalized output or empty string. To make sure this
|
|
261
|
+
// code will work in the future and independent of the compiler flag, we
|
|
262
|
+
// translate the variants to their names manually here.
|
|
263
|
+
//
|
|
264
|
+
// [1] https://doc.rust-lang.org/1.81.0/std/fmt/trait.Debug.html#stability
|
|
265
|
+
// [2] https://doc.rust-lang.org/beta/unstable-book/compiler-flags/fmt-debug.html
|
|
266
|
+
let s = match self {
|
|
267
|
+
Trait::HasField { .. } => "HasField",
|
|
268
|
+
Trait::ProjectField { .. } => "ProjectField",
|
|
269
|
+
Trait::KnownLayout => "KnownLayout",
|
|
270
|
+
Trait::HasTag => "HasTag",
|
|
271
|
+
Trait::Immutable => "Immutable",
|
|
272
|
+
Trait::TryFromBytes => "TryFromBytes",
|
|
273
|
+
Trait::FromZeros => "FromZeros",
|
|
274
|
+
Trait::FromBytes => "FromBytes",
|
|
275
|
+
Trait::IntoBytes => "IntoBytes",
|
|
276
|
+
Trait::Unaligned => "Unaligned",
|
|
277
|
+
Trait::Sized => "Sized",
|
|
278
|
+
Trait::ByteHash => "ByteHash",
|
|
279
|
+
Trait::ByteEq => "ByteEq",
|
|
280
|
+
Trait::SplitAt => "SplitAt",
|
|
281
|
+
};
|
|
282
|
+
let ident = Ident::new(s, Span::call_site());
|
|
283
|
+
let arguments: Option<syn::AngleBracketedGenericArguments> = match self {
|
|
284
|
+
Trait::HasField { variant_id, field, field_id } => {
|
|
285
|
+
Some(parse_quote!(<#field, #variant_id, #field_id>))
|
|
286
|
+
}
|
|
287
|
+
Trait::ProjectField { variant_id, field, field_id, invariants } => {
|
|
288
|
+
Some(parse_quote!(<#field, #invariants, #variant_id, #field_id>))
|
|
289
|
+
}
|
|
290
|
+
Trait::KnownLayout
|
|
291
|
+
| Trait::HasTag
|
|
292
|
+
| Trait::Immutable
|
|
293
|
+
| Trait::TryFromBytes
|
|
294
|
+
| Trait::FromZeros
|
|
295
|
+
| Trait::FromBytes
|
|
296
|
+
| Trait::IntoBytes
|
|
297
|
+
| Trait::Unaligned
|
|
298
|
+
| Trait::Sized
|
|
299
|
+
| Trait::ByteHash
|
|
300
|
+
| Trait::ByteEq
|
|
301
|
+
| Trait::SplitAt => None,
|
|
302
|
+
};
|
|
303
|
+
tokens.extend(quote!(#ident #arguments));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
impl Trait {
|
|
308
|
+
pub(crate) fn crate_path(&self, ctx: &Ctx) -> Path {
|
|
309
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
310
|
+
let core = ctx.core_path();
|
|
311
|
+
match self {
|
|
312
|
+
Self::Sized => parse_quote!(#core::marker::#self),
|
|
313
|
+
_ => parse_quote!(#zerocopy_crate::#self),
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
pub(crate) enum TraitBound {
|
|
319
|
+
Slf,
|
|
320
|
+
Other(Trait),
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
pub(crate) enum FieldBounds<'a> {
|
|
324
|
+
None,
|
|
325
|
+
All(&'a [TraitBound]),
|
|
326
|
+
Trailing(&'a [TraitBound]),
|
|
327
|
+
Explicit(Vec<WherePredicate>),
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
impl<'a> FieldBounds<'a> {
|
|
331
|
+
pub(crate) const ALL_SELF: FieldBounds<'a> = FieldBounds::All(&[TraitBound::Slf]);
|
|
332
|
+
pub(crate) const TRAILING_SELF: FieldBounds<'a> = FieldBounds::Trailing(&[TraitBound::Slf]);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
pub(crate) enum SelfBounds<'a> {
|
|
336
|
+
None,
|
|
337
|
+
All(&'a [Trait]),
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// FIXME(https://github.com/rust-lang/rust-clippy/issues/12908): This is a false
|
|
341
|
+
// positive. Explicit lifetimes are actually necessary here.
|
|
342
|
+
#[allow(clippy::needless_lifetimes)]
|
|
343
|
+
impl<'a> SelfBounds<'a> {
|
|
344
|
+
pub(crate) const SIZED: Self = Self::All(&[Trait::Sized]);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/// Normalizes a slice of bounds by replacing [`TraitBound::Slf`] with `slf`.
|
|
348
|
+
pub(crate) fn normalize_bounds<'a>(
|
|
349
|
+
slf: &'a Trait,
|
|
350
|
+
bounds: &'a [TraitBound],
|
|
351
|
+
) -> impl 'a + Iterator<Item = Trait> {
|
|
352
|
+
bounds.iter().map(move |bound| match bound {
|
|
353
|
+
TraitBound::Slf => slf.clone(),
|
|
354
|
+
TraitBound::Other(trt) => trt.clone(),
|
|
355
|
+
})
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
pub(crate) struct ImplBlockBuilder<'a> {
|
|
359
|
+
ctx: &'a Ctx,
|
|
360
|
+
data: &'a dyn DataExt,
|
|
361
|
+
trt: Trait,
|
|
362
|
+
field_type_trait_bounds: FieldBounds<'a>,
|
|
363
|
+
self_type_trait_bounds: SelfBounds<'a>,
|
|
364
|
+
padding_check: Option<PaddingCheck>,
|
|
365
|
+
param_extras: Vec<GenericParam>,
|
|
366
|
+
inner_extras: Option<TokenStream>,
|
|
367
|
+
outer_extras: Option<TokenStream>,
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
impl<'a> ImplBlockBuilder<'a> {
|
|
371
|
+
pub(crate) fn new(
|
|
372
|
+
ctx: &'a Ctx,
|
|
373
|
+
data: &'a dyn DataExt,
|
|
374
|
+
trt: Trait,
|
|
375
|
+
field_type_trait_bounds: FieldBounds<'a>,
|
|
376
|
+
) -> Self {
|
|
377
|
+
Self {
|
|
378
|
+
ctx,
|
|
379
|
+
data,
|
|
380
|
+
trt,
|
|
381
|
+
field_type_trait_bounds,
|
|
382
|
+
self_type_trait_bounds: SelfBounds::None,
|
|
383
|
+
padding_check: None,
|
|
384
|
+
param_extras: Vec::new(),
|
|
385
|
+
inner_extras: None,
|
|
386
|
+
outer_extras: None,
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
pub(crate) fn self_type_trait_bounds(mut self, self_type_trait_bounds: SelfBounds<'a>) -> Self {
|
|
391
|
+
self.self_type_trait_bounds = self_type_trait_bounds;
|
|
392
|
+
self
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
pub(crate) fn padding_check<P: Into<Option<PaddingCheck>>>(mut self, padding_check: P) -> Self {
|
|
396
|
+
self.padding_check = padding_check.into();
|
|
397
|
+
self
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
pub(crate) fn param_extras(mut self, param_extras: Vec<GenericParam>) -> Self {
|
|
401
|
+
self.param_extras.extend(param_extras);
|
|
402
|
+
self
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
pub(crate) fn inner_extras(mut self, inner_extras: TokenStream) -> Self {
|
|
406
|
+
self.inner_extras = Some(inner_extras);
|
|
407
|
+
self
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
pub(crate) fn outer_extras<T: Into<Option<TokenStream>>>(mut self, outer_extras: T) -> Self {
|
|
411
|
+
self.outer_extras = outer_extras.into();
|
|
412
|
+
self
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
pub(crate) fn build(self) -> TokenStream {
|
|
416
|
+
// In this documentation, we will refer to this hypothetical struct:
|
|
417
|
+
//
|
|
418
|
+
// #[derive(FromBytes)]
|
|
419
|
+
// struct Foo<T, I: Iterator>
|
|
420
|
+
// where
|
|
421
|
+
// T: Copy,
|
|
422
|
+
// I: Clone,
|
|
423
|
+
// I::Item: Clone,
|
|
424
|
+
// {
|
|
425
|
+
// a: u8,
|
|
426
|
+
// b: T,
|
|
427
|
+
// c: I::Item,
|
|
428
|
+
// }
|
|
429
|
+
//
|
|
430
|
+
// We extract the field types, which in this case are `u8`, `T`, and
|
|
431
|
+
// `I::Item`. We re-use the existing parameters and where clauses. If
|
|
432
|
+
// `require_trait_bound == true` (as it is for `FromBytes), we add where
|
|
433
|
+
// bounds for each field's type:
|
|
434
|
+
//
|
|
435
|
+
// impl<T, I: Iterator> FromBytes for Foo<T, I>
|
|
436
|
+
// where
|
|
437
|
+
// T: Copy,
|
|
438
|
+
// I: Clone,
|
|
439
|
+
// I::Item: Clone,
|
|
440
|
+
// T: FromBytes,
|
|
441
|
+
// I::Item: FromBytes,
|
|
442
|
+
// {
|
|
443
|
+
// }
|
|
444
|
+
//
|
|
445
|
+
// NOTE: It is standard practice to only emit bounds for the type
|
|
446
|
+
// parameters themselves, not for field types based on those parameters
|
|
447
|
+
// (e.g., `T` vs `T::Foo`). For a discussion of why this is standard
|
|
448
|
+
// practice, see https://github.com/rust-lang/rust/issues/26925.
|
|
449
|
+
//
|
|
450
|
+
// The reason we diverge from this standard is that doing it that way
|
|
451
|
+
// for us would be unsound. E.g., consider a type, `T` where `T:
|
|
452
|
+
// FromBytes` but `T::Foo: !FromBytes`. It would not be sound for us to
|
|
453
|
+
// accept a type with a `T::Foo` field as `FromBytes` simply because `T:
|
|
454
|
+
// FromBytes`.
|
|
455
|
+
//
|
|
456
|
+
// While there's no getting around this requirement for us, it does have
|
|
457
|
+
// the pretty serious downside that, when lifetimes are involved, the
|
|
458
|
+
// trait solver ties itself in knots:
|
|
459
|
+
//
|
|
460
|
+
// #[derive(Unaligned)]
|
|
461
|
+
// #[repr(C)]
|
|
462
|
+
// struct Dup<'a, 'b> {
|
|
463
|
+
// a: PhantomData<&'a u8>,
|
|
464
|
+
// b: PhantomData<&'b u8>,
|
|
465
|
+
// }
|
|
466
|
+
//
|
|
467
|
+
// error[E0283]: type annotations required: cannot resolve `core::marker::PhantomData<&'a u8>: zerocopy::Unaligned`
|
|
468
|
+
// --> src/main.rs:6:10
|
|
469
|
+
// |
|
|
470
|
+
// 6 | #[derive(Unaligned)]
|
|
471
|
+
// | ^^^^^^^^^
|
|
472
|
+
// |
|
|
473
|
+
// = note: required by `zerocopy::Unaligned`
|
|
474
|
+
|
|
475
|
+
let type_ident = &self.ctx.ast.ident;
|
|
476
|
+
let trait_path = self.trt.crate_path(self.ctx);
|
|
477
|
+
let fields = self.data.fields();
|
|
478
|
+
let variants = self.data.variants();
|
|
479
|
+
let tag = self.data.tag();
|
|
480
|
+
let zerocopy_crate = &self.ctx.zerocopy_crate;
|
|
481
|
+
|
|
482
|
+
fn bound_tt(ty: &Type, traits: impl Iterator<Item = Trait>, ctx: &Ctx) -> WherePredicate {
|
|
483
|
+
let traits = traits.map(|t| t.crate_path(ctx));
|
|
484
|
+
parse_quote!(#ty: #(#traits)+*)
|
|
485
|
+
}
|
|
486
|
+
let field_type_bounds: Vec<_> = match (self.field_type_trait_bounds, &fields[..]) {
|
|
487
|
+
(FieldBounds::All(traits), _) => fields
|
|
488
|
+
.iter()
|
|
489
|
+
.map(|(_vis, _name, ty)| {
|
|
490
|
+
bound_tt(ty, normalize_bounds(&self.trt, traits), self.ctx)
|
|
491
|
+
})
|
|
492
|
+
.collect(),
|
|
493
|
+
(FieldBounds::None, _) | (FieldBounds::Trailing(..), []) => vec![],
|
|
494
|
+
(FieldBounds::Trailing(traits), [.., last]) => {
|
|
495
|
+
vec![bound_tt(last.2, normalize_bounds(&self.trt, traits), self.ctx)]
|
|
496
|
+
}
|
|
497
|
+
(FieldBounds::Explicit(bounds), _) => bounds,
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// Don't bother emitting a padding check if there are no fields.
|
|
501
|
+
#[allow(unstable_name_collisions)] // See `BoolExt` below
|
|
502
|
+
let padding_check_bound = self
|
|
503
|
+
.padding_check
|
|
504
|
+
.and_then(|check| (!fields.is_empty()).then_some(check))
|
|
505
|
+
.map(|check| {
|
|
506
|
+
let variant_types = variants.iter().map(|(_, fields)| {
|
|
507
|
+
let types = fields.iter().map(|(_vis, _name, ty)| ty);
|
|
508
|
+
quote!([#((#types)),*])
|
|
509
|
+
});
|
|
510
|
+
let validator_context = check.validator_macro_context();
|
|
511
|
+
let (trt, validator_macro) = check.validator_trait_and_macro_idents();
|
|
512
|
+
let t = tag.iter();
|
|
513
|
+
parse_quote! {
|
|
514
|
+
(): #zerocopy_crate::util::macro_util::#trt<
|
|
515
|
+
Self,
|
|
516
|
+
{
|
|
517
|
+
#validator_context
|
|
518
|
+
#zerocopy_crate::#validator_macro!(Self, #(#t,)* #(#variant_types),*)
|
|
519
|
+
}
|
|
520
|
+
>
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
let self_bounds: Option<WherePredicate> = match self.self_type_trait_bounds {
|
|
525
|
+
SelfBounds::None => None,
|
|
526
|
+
SelfBounds::All(traits) => {
|
|
527
|
+
Some(bound_tt(&parse_quote!(Self), traits.iter().cloned(), self.ctx))
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
let bounds = self
|
|
532
|
+
.ctx
|
|
533
|
+
.ast
|
|
534
|
+
.generics
|
|
535
|
+
.where_clause
|
|
536
|
+
.as_ref()
|
|
537
|
+
.map(|where_clause| where_clause.predicates.iter())
|
|
538
|
+
.into_iter()
|
|
539
|
+
.flatten()
|
|
540
|
+
.chain(field_type_bounds.iter())
|
|
541
|
+
.chain(padding_check_bound.iter())
|
|
542
|
+
.chain(self_bounds.iter());
|
|
543
|
+
|
|
544
|
+
// The parameters with trait bounds, but without type defaults.
|
|
545
|
+
let mut params: Vec<_> = self
|
|
546
|
+
.ctx
|
|
547
|
+
.ast
|
|
548
|
+
.generics
|
|
549
|
+
.params
|
|
550
|
+
.clone()
|
|
551
|
+
.into_iter()
|
|
552
|
+
.map(|mut param| {
|
|
553
|
+
match &mut param {
|
|
554
|
+
GenericParam::Type(ty) => ty.default = None,
|
|
555
|
+
GenericParam::Const(cnst) => cnst.default = None,
|
|
556
|
+
GenericParam::Lifetime(_) => {}
|
|
557
|
+
}
|
|
558
|
+
parse_quote!(#param)
|
|
559
|
+
})
|
|
560
|
+
.chain(self.param_extras)
|
|
561
|
+
.collect();
|
|
562
|
+
|
|
563
|
+
// For MSRV purposes, ensure that lifetimes precede types precede const
|
|
564
|
+
// generics.
|
|
565
|
+
params.sort_by_cached_key(|param| match param {
|
|
566
|
+
GenericParam::Lifetime(_) => 0,
|
|
567
|
+
GenericParam::Type(_) => 1,
|
|
568
|
+
GenericParam::Const(_) => 2,
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
// The identifiers of the parameters without trait bounds or type
|
|
572
|
+
// defaults.
|
|
573
|
+
let param_idents = self.ctx.ast.generics.params.iter().map(|param| match param {
|
|
574
|
+
GenericParam::Type(ty) => {
|
|
575
|
+
let ident = &ty.ident;
|
|
576
|
+
quote!(#ident)
|
|
577
|
+
}
|
|
578
|
+
GenericParam::Lifetime(l) => {
|
|
579
|
+
let ident = &l.lifetime;
|
|
580
|
+
quote!(#ident)
|
|
581
|
+
}
|
|
582
|
+
GenericParam::Const(cnst) => {
|
|
583
|
+
let ident = &cnst.ident;
|
|
584
|
+
quote!({#ident})
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
let inner_extras = self.inner_extras;
|
|
589
|
+
let impl_tokens = quote! {
|
|
590
|
+
unsafe impl < #(#params),* > #trait_path for #type_ident < #(#param_idents),* >
|
|
591
|
+
where
|
|
592
|
+
#(#bounds,)*
|
|
593
|
+
{
|
|
594
|
+
fn only_derive_is_allowed_to_implement_this_trait() {}
|
|
595
|
+
|
|
596
|
+
#inner_extras
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
let outer_extras = self.outer_extras.filter(|e| !e.is_empty());
|
|
601
|
+
const_block([Some(impl_tokens), outer_extras])
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// A polyfill for `Option::then_some`, which was added after our MSRV.
|
|
606
|
+
//
|
|
607
|
+
// The `#[allow(unused)]` is necessary because, on sufficiently recent toolchain
|
|
608
|
+
// versions, `b.then_some(...)` resolves to the inherent method rather than to
|
|
609
|
+
// this trait, and so this trait is considered unused.
|
|
610
|
+
//
|
|
611
|
+
// FIXME(#67): Remove this once our MSRV is >= 1.62.
|
|
612
|
+
#[allow(unused)]
|
|
613
|
+
trait BoolExt {
|
|
614
|
+
fn then_some<T>(self, t: T) -> Option<T>;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
impl BoolExt for bool {
|
|
618
|
+
fn then_some<T>(self, t: T) -> Option<T> {
|
|
619
|
+
if self {
|
|
620
|
+
Some(t)
|
|
621
|
+
} else {
|
|
622
|
+
None
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
pub(crate) fn const_block(items: impl IntoIterator<Item = Option<TokenStream>>) -> TokenStream {
|
|
628
|
+
let items = items.into_iter().flatten();
|
|
629
|
+
quote! {
|
|
630
|
+
#[allow(
|
|
631
|
+
// FIXME(#553): Add a test that generates a warning when
|
|
632
|
+
// `#[allow(deprecated)]` isn't present.
|
|
633
|
+
deprecated,
|
|
634
|
+
// Required on some rustc versions due to a lint that is only
|
|
635
|
+
// triggered when `derive(KnownLayout)` is applied to `repr(C)`
|
|
636
|
+
// structs that are generated by macros. See #2177 for details.
|
|
637
|
+
private_bounds,
|
|
638
|
+
non_local_definitions,
|
|
639
|
+
non_camel_case_types,
|
|
640
|
+
non_upper_case_globals,
|
|
641
|
+
non_snake_case,
|
|
642
|
+
non_ascii_idents,
|
|
643
|
+
clippy::missing_inline_in_public_items,
|
|
644
|
+
)]
|
|
645
|
+
#[deny(ambiguous_associated_items)]
|
|
646
|
+
// While there are not currently any warnings that this suppresses
|
|
647
|
+
// (that we're aware of), it's good future-proofing hygiene.
|
|
648
|
+
#[automatically_derived]
|
|
649
|
+
const _: () = {
|
|
650
|
+
#(#items)*
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
pub(crate) fn generate_tag_enum(ctx: &Ctx, repr: &EnumRepr, data: &DataEnum) -> TokenStream {
|
|
655
|
+
let zerocopy_crate = &ctx.zerocopy_crate;
|
|
656
|
+
let variants = data.variants.iter().map(|v| {
|
|
657
|
+
let ident = &v.ident;
|
|
658
|
+
if let Some((eq, discriminant)) = &v.discriminant {
|
|
659
|
+
quote! { #ident #eq #discriminant }
|
|
660
|
+
} else {
|
|
661
|
+
quote! { #ident }
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
// Don't include any `repr(align)` when generating the tag enum, as that
|
|
666
|
+
// could add padding after the tag but before any variants, which is not the
|
|
667
|
+
// correct behavior.
|
|
668
|
+
let repr = match repr {
|
|
669
|
+
EnumRepr::Transparent(span) => quote::quote_spanned! { *span => #[repr(transparent)] },
|
|
670
|
+
EnumRepr::Compound(c, _) => quote! { #c },
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
quote! {
|
|
674
|
+
#repr
|
|
675
|
+
#[allow(dead_code)]
|
|
676
|
+
pub enum ___ZerocopyTag {
|
|
677
|
+
#(#variants,)*
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// SAFETY: `___ZerocopyTag` has no fields, and so it does not permit
|
|
681
|
+
// interior mutation.
|
|
682
|
+
unsafe impl #zerocopy_crate::Immutable for ___ZerocopyTag {
|
|
683
|
+
fn only_derive_is_allowed_to_implement_this_trait() {}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
pub(crate) fn enum_size_from_repr(repr: &EnumRepr) -> Result<usize, Error> {
|
|
688
|
+
use CompoundRepr::*;
|
|
689
|
+
use PrimitiveRepr::*;
|
|
690
|
+
use Repr::*;
|
|
691
|
+
match repr {
|
|
692
|
+
Transparent(span)
|
|
693
|
+
| Compound(
|
|
694
|
+
Spanned {
|
|
695
|
+
t: C | Rust | Primitive(U32 | I32 | U64 | I64 | U128 | I128 | Usize | Isize),
|
|
696
|
+
span,
|
|
697
|
+
},
|
|
698
|
+
_,
|
|
699
|
+
) => Err(Error::new(
|
|
700
|
+
*span,
|
|
701
|
+
"`FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`",
|
|
702
|
+
)),
|
|
703
|
+
Compound(Spanned { t: Primitive(U8 | I8), span: _ }, _align) => Ok(8),
|
|
704
|
+
Compound(Spanned { t: Primitive(U16 | I16), span: _ }, _align) => Ok(16),
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
#[cfg(test)]
|
|
709
|
+
pub(crate) mod testutil {
|
|
710
|
+
use proc_macro2::TokenStream;
|
|
711
|
+
use syn::visit::{self, Visit};
|
|
712
|
+
|
|
713
|
+
/// Checks for hygiene violations in the generated code.
|
|
714
|
+
///
|
|
715
|
+
/// # Panics
|
|
716
|
+
///
|
|
717
|
+
/// Panics if a hygiene violation is found.
|
|
718
|
+
pub(crate) fn check_hygiene(ts: TokenStream) {
|
|
719
|
+
struct AmbiguousItemVisitor;
|
|
720
|
+
|
|
721
|
+
impl<'ast> Visit<'ast> for AmbiguousItemVisitor {
|
|
722
|
+
fn visit_path(&mut self, i: &'ast syn::Path) {
|
|
723
|
+
if i.segments.len() > 1 && i.segments.first().unwrap().ident == "Self" {
|
|
724
|
+
panic!(
|
|
725
|
+
"Found ambiguous path `{}` in generated output. \
|
|
726
|
+
All associated item access must be fully qualified (e.g., `<Self as Trait>::Item`) \
|
|
727
|
+
to prevent hygiene issues.",
|
|
728
|
+
quote::quote!(#i)
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
visit::visit_path(self, i);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
let file = syn::parse2::<syn::File>(ts).expect("failed to parse generated output as File");
|
|
736
|
+
AmbiguousItemVisitor.visit_file(&file);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
#[test]
|
|
740
|
+
fn test_check_hygiene_success() {
|
|
741
|
+
check_hygiene(quote::quote! {
|
|
742
|
+
fn foo() {
|
|
743
|
+
let _ = <Self as Trait>::Item;
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
#[test]
|
|
749
|
+
#[should_panic(expected = "Found ambiguous path `Self :: Ambiguous`")]
|
|
750
|
+
fn test_check_hygiene_failure() {
|
|
751
|
+
check_hygiene(quote::quote! {
|
|
752
|
+
fn foo() {
|
|
753
|
+
let _ = Self::Ambiguous;
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
}
|