├── .github ├── ISSUE_TEMPLATE │ └── customer-request.md ├── actions │ └── cache │ │ └── action.yml ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── backport-pr.yml │ ├── ci.yml │ ├── dependency-review.yml │ ├── docs.yml │ ├── release-crate-version.yml │ ├── roll-pinned-toolchain-versions.yml │ └── scorecard.yml ├── .gitignore ├── .vscode └── settings.json ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-BSD ├── LICENSE-MIT ├── POLICIES.md ├── README.md ├── build.rs ├── cargo.sh ├── ci ├── check_all_toolchains_tested.sh ├── check_fmt.sh ├── check_job_dependencies.sh ├── check_readme.sh ├── check_todo.sh ├── check_versions.sh └── release_crate_version.sh ├── clippy.toml ├── githooks └── pre-push ├── rustfmt.toml ├── src ├── byte_slice.rs ├── byteorder.rs ├── deprecated.rs ├── doctests.rs ├── error.rs ├── impls.rs ├── layout.rs ├── lib.rs ├── macros.rs ├── pointer │ ├── inner.rs │ ├── invariant.rs │ ├── mod.rs │ ├── ptr.rs │ └── transmute.rs ├── ref.rs ├── split_at.rs ├── util │ ├── macro_util.rs │ ├── macros.rs │ └── mod.rs └── wrappers.rs ├── testdata └── include_value │ └── data ├── tests ├── trybuild.rs ├── ui-msrv │ ├── diagnostic-not-implemented-from-bytes.rs │ ├── diagnostic-not-implemented-from-bytes.stderr │ ├── diagnostic-not-implemented-from-zeros.rs │ ├── diagnostic-not-implemented-from-zeros.stderr │ ├── diagnostic-not-implemented-immutable.rs │ ├── diagnostic-not-implemented-immutable.stderr │ ├── diagnostic-not-implemented-into-bytes.rs │ ├── diagnostic-not-implemented-into-bytes.stderr │ ├── diagnostic-not-implemented-issue-1296.rs │ ├── diagnostic-not-implemented-issue-1296.stderr │ ├── diagnostic-not-implemented-known-layout.rs │ ├── diagnostic-not-implemented-known-layout.stderr │ ├── diagnostic-not-implemented-try-from-bytes.rs │ ├── diagnostic-not-implemented-try-from-bytes.stderr │ ├── diagnostic-not-implemented-unaligned.rs │ ├── diagnostic-not-implemented-unaligned.stderr │ ├── include_value_not_from_bytes.rs │ ├── include_value_not_from_bytes.stderr │ ├── include_value_wrong_size.rs │ ├── include_value_wrong_size.stderr │ ├── invalid-impls │ │ ├── invalid-impls.rs │ │ └── invalid-impls.stderr │ ├── max-align.rs │ ├── max-align.stderr │ ├── ptr-is-invariant-over-v.rs │ ├── ptr-is-invariant-over-v.stderr │ ├── transmute-dst-not-frombytes.rs │ ├── transmute-dst-not-frombytes.stderr │ ├── transmute-mut-const.rs │ ├── transmute-mut-const.stderr │ ├── transmute-mut-dst-not-a-reference.rs │ ├── transmute-mut-dst-not-a-reference.stderr │ ├── transmute-mut-dst-not-frombytes.rs │ ├── transmute-mut-dst-not-frombytes.stderr │ ├── transmute-mut-dst-not-intobytes.rs │ ├── transmute-mut-dst-not-intobytes.stderr │ ├── transmute-mut-dst-unsized.rs │ ├── transmute-mut-dst-unsized.stderr │ ├── transmute-mut-illegal-lifetime.rs │ ├── transmute-mut-illegal-lifetime.stderr │ ├── transmute-mut-src-dst-not-references.rs │ ├── transmute-mut-src-dst-not-references.stderr │ ├── transmute-mut-src-immutable.rs │ ├── transmute-mut-src-immutable.stderr │ ├── transmute-mut-src-not-a-reference.rs │ ├── transmute-mut-src-not-a-reference.stderr │ ├── transmute-mut-src-not-frombytes.rs │ ├── transmute-mut-src-not-frombytes.stderr │ ├── transmute-mut-src-not-intobytes.rs │ ├── transmute-mut-src-not-intobytes.stderr │ ├── transmute-mut-src-unsized.rs │ ├── transmute-mut-src-unsized.stderr │ ├── transmute-ptr-to-usize.rs │ ├── transmute-ptr-to-usize.stderr │ ├── transmute-ref-dst-mutable.rs │ ├── transmute-ref-dst-mutable.stderr │ ├── transmute-ref-dst-not-a-reference.rs │ ├── transmute-ref-dst-not-a-reference.stderr │ ├── transmute-ref-dst-not-frombytes.rs │ ├── transmute-ref-dst-not-frombytes.stderr │ ├── transmute-ref-dst-not-nocell.rs │ ├── transmute-ref-dst-not-nocell.stderr │ ├── transmute-ref-dst-unsized.rs │ ├── transmute-ref-dst-unsized.stderr │ ├── transmute-ref-illegal-lifetime.rs │ ├── transmute-ref-illegal-lifetime.stderr │ ├── transmute-ref-src-dst-not-references.rs │ ├── transmute-ref-src-dst-not-references.stderr │ ├── transmute-ref-src-not-a-reference.rs │ ├── transmute-ref-src-not-a-reference.stderr │ ├── transmute-ref-src-not-intobytes.rs │ ├── transmute-ref-src-not-intobytes.stderr │ ├── transmute-ref-src-not-nocell.rs │ ├── transmute-ref-src-not-nocell.stderr │ ├── transmute-ref-src-unsized.rs │ ├── transmute-ref-src-unsized.stderr │ ├── transmute-size-decrease.rs │ ├── transmute-size-decrease.stderr │ ├── transmute-size-increase.rs │ ├── transmute-size-increase.stderr │ ├── transmute-src-not-intobytes.rs │ ├── transmute-src-not-intobytes.stderr │ ├── try_transmute-dst-not-tryfrombytes.rs │ ├── try_transmute-dst-not-tryfrombytes.stderr │ ├── try_transmute-size-decrease.rs │ ├── try_transmute-size-decrease.stderr │ ├── try_transmute-size-increase.rs │ ├── try_transmute-size-increase.stderr │ ├── try_transmute-src-not-intobytes.rs │ ├── try_transmute-src-not-intobytes.stderr │ ├── try_transmute_mut-alignment-increase.rs │ ├── try_transmute_mut-alignment-increase.stderr │ ├── try_transmute_mut-dst-not-tryfrombytes.rs │ ├── try_transmute_mut-dst-not-tryfrombytes.stderr │ ├── try_transmute_mut-size-decrease.rs │ ├── try_transmute_mut-size-decrease.stderr │ ├── try_transmute_mut-size-increase.rs │ ├── try_transmute_mut-size-increase.stderr │ ├── try_transmute_mut-src-not-frombytes.rs │ ├── try_transmute_mut-src-not-frombytes.stderr │ ├── try_transmute_mut-src-not-intobytes.rs │ ├── try_transmute_mut-src-not-intobytes.stderr │ ├── try_transmute_ref-alignment-increase.rs │ ├── try_transmute_ref-alignment-increase.stderr │ ├── try_transmute_ref-dst-mutable.rs │ ├── try_transmute_ref-dst-mutable.stderr │ ├── try_transmute_ref-dst-not-immutable-tryfrombytes.rs │ ├── try_transmute_ref-dst-not-immutable-tryfrombytes.stderr │ ├── try_transmute_ref-size-decrease.rs │ ├── try_transmute_ref-size-decrease.stderr │ ├── try_transmute_ref-size-increase.rs │ ├── try_transmute_ref-size-increase.stderr │ ├── try_transmute_ref-src-not-immutable-intobytes.rs │ └── try_transmute_ref-src-not-immutable-intobytes.stderr ├── ui-nightly │ ├── diagnostic-not-implemented-from-bytes.rs │ ├── diagnostic-not-implemented-from-bytes.stderr │ ├── diagnostic-not-implemented-from-zeros.rs │ ├── diagnostic-not-implemented-from-zeros.stderr │ ├── diagnostic-not-implemented-immutable.rs │ ├── diagnostic-not-implemented-immutable.stderr │ ├── diagnostic-not-implemented-into-bytes.rs │ ├── diagnostic-not-implemented-into-bytes.stderr │ ├── diagnostic-not-implemented-issue-1296.rs │ ├── diagnostic-not-implemented-issue-1296.stderr │ ├── diagnostic-not-implemented-known-layout.rs │ ├── diagnostic-not-implemented-known-layout.stderr │ ├── diagnostic-not-implemented-try-from-bytes.rs │ ├── diagnostic-not-implemented-try-from-bytes.stderr │ ├── diagnostic-not-implemented-unaligned.rs │ ├── diagnostic-not-implemented-unaligned.stderr │ ├── include_value_not_from_bytes.rs │ ├── include_value_not_from_bytes.stderr │ ├── include_value_wrong_size.rs │ ├── include_value_wrong_size.stderr │ ├── invalid-impls │ │ ├── invalid-impls.rs │ │ └── invalid-impls.stderr │ ├── max-align.rs │ ├── max-align.stderr │ ├── ptr-is-invariant-over-v.rs │ ├── ptr-is-invariant-over-v.stderr │ ├── transmute-dst-not-frombytes.rs │ ├── transmute-dst-not-frombytes.stderr │ ├── transmute-mut-const.rs │ ├── transmute-mut-const.stderr │ ├── transmute-mut-dst-not-a-reference.rs │ ├── transmute-mut-dst-not-a-reference.stderr │ ├── transmute-mut-dst-not-frombytes.rs │ ├── transmute-mut-dst-not-frombytes.stderr │ ├── transmute-mut-dst-not-intobytes.rs │ ├── transmute-mut-dst-not-intobytes.stderr │ ├── transmute-mut-dst-unsized.rs │ ├── transmute-mut-dst-unsized.stderr │ ├── transmute-mut-illegal-lifetime.rs │ ├── transmute-mut-illegal-lifetime.stderr │ ├── transmute-mut-src-dst-not-references.rs │ ├── transmute-mut-src-dst-not-references.stderr │ ├── transmute-mut-src-immutable.rs │ ├── transmute-mut-src-immutable.stderr │ ├── transmute-mut-src-not-a-reference.rs │ ├── transmute-mut-src-not-a-reference.stderr │ ├── transmute-mut-src-not-frombytes.rs │ ├── transmute-mut-src-not-frombytes.stderr │ ├── transmute-mut-src-not-intobytes.rs │ ├── transmute-mut-src-not-intobytes.stderr │ ├── transmute-mut-src-unsized.rs │ ├── transmute-mut-src-unsized.stderr │ ├── transmute-ptr-to-usize.rs │ ├── transmute-ptr-to-usize.stderr │ ├── transmute-ref-dst-mutable.rs │ ├── transmute-ref-dst-mutable.stderr │ ├── transmute-ref-dst-not-a-reference.rs │ ├── transmute-ref-dst-not-a-reference.stderr │ ├── transmute-ref-dst-not-frombytes.rs │ ├── transmute-ref-dst-not-frombytes.stderr │ ├── transmute-ref-dst-not-nocell.rs │ ├── transmute-ref-dst-not-nocell.stderr │ ├── transmute-ref-dst-unsized.rs │ ├── transmute-ref-dst-unsized.stderr │ ├── transmute-ref-illegal-lifetime.rs │ ├── transmute-ref-illegal-lifetime.stderr │ ├── transmute-ref-src-dst-not-references.rs │ ├── transmute-ref-src-dst-not-references.stderr │ ├── transmute-ref-src-not-a-reference.rs │ ├── transmute-ref-src-not-a-reference.stderr │ ├── transmute-ref-src-not-intobytes.rs │ ├── transmute-ref-src-not-intobytes.stderr │ ├── transmute-ref-src-not-nocell.rs │ ├── transmute-ref-src-not-nocell.stderr │ ├── transmute-ref-src-unsized.rs │ ├── transmute-ref-src-unsized.stderr │ ├── transmute-size-decrease.rs │ ├── transmute-size-decrease.stderr │ ├── transmute-size-increase.rs │ ├── transmute-size-increase.stderr │ ├── transmute-src-not-intobytes.rs │ ├── transmute-src-not-intobytes.stderr │ ├── try_transmute-dst-not-tryfrombytes.rs │ ├── try_transmute-dst-not-tryfrombytes.stderr │ ├── try_transmute-size-decrease.rs │ ├── try_transmute-size-decrease.stderr │ ├── try_transmute-size-increase.rs │ ├── try_transmute-size-increase.stderr │ ├── try_transmute-src-not-intobytes.rs │ ├── try_transmute-src-not-intobytes.stderr │ ├── try_transmute_mut-alignment-increase.rs │ ├── try_transmute_mut-alignment-increase.stderr │ ├── try_transmute_mut-dst-not-tryfrombytes.rs │ ├── try_transmute_mut-dst-not-tryfrombytes.stderr │ ├── try_transmute_mut-size-decrease.rs │ ├── try_transmute_mut-size-decrease.stderr │ ├── try_transmute_mut-size-increase.rs │ ├── try_transmute_mut-size-increase.stderr │ ├── try_transmute_mut-src-not-frombytes.rs │ ├── try_transmute_mut-src-not-frombytes.stderr │ ├── try_transmute_mut-src-not-intobytes.rs │ ├── try_transmute_mut-src-not-intobytes.stderr │ ├── try_transmute_ref-alignment-increase.rs │ ├── try_transmute_ref-alignment-increase.stderr │ ├── try_transmute_ref-dst-mutable.rs │ ├── try_transmute_ref-dst-mutable.stderr │ ├── try_transmute_ref-dst-not-immutable-tryfrombytes.rs │ ├── try_transmute_ref-dst-not-immutable-tryfrombytes.stderr │ ├── try_transmute_ref-size-decrease.rs │ ├── try_transmute_ref-size-decrease.stderr │ ├── try_transmute_ref-size-increase.rs │ ├── try_transmute_ref-size-increase.stderr │ ├── try_transmute_ref-src-not-immutable-intobytes.rs │ └── try_transmute_ref-src-not-immutable-intobytes.stderr └── ui-stable │ ├── diagnostic-not-implemented-from-bytes.rs │ ├── diagnostic-not-implemented-from-bytes.stderr │ ├── diagnostic-not-implemented-from-zeros.rs │ ├── diagnostic-not-implemented-from-zeros.stderr │ ├── diagnostic-not-implemented-immutable.rs │ ├── diagnostic-not-implemented-immutable.stderr │ ├── diagnostic-not-implemented-into-bytes.rs │ ├── diagnostic-not-implemented-into-bytes.stderr │ ├── diagnostic-not-implemented-issue-1296.rs │ ├── diagnostic-not-implemented-issue-1296.stderr │ ├── diagnostic-not-implemented-known-layout.rs │ ├── diagnostic-not-implemented-known-layout.stderr │ ├── diagnostic-not-implemented-try-from-bytes.rs │ ├── diagnostic-not-implemented-try-from-bytes.stderr │ ├── diagnostic-not-implemented-unaligned.rs │ ├── diagnostic-not-implemented-unaligned.stderr │ ├── include_value_not_from_bytes.rs │ ├── include_value_not_from_bytes.stderr │ ├── include_value_wrong_size.rs │ ├── include_value_wrong_size.stderr │ ├── invalid-impls │ ├── invalid-impls.rs │ └── invalid-impls.stderr │ ├── max-align.rs │ ├── max-align.stderr │ ├── ptr-is-invariant-over-v.rs │ ├── ptr-is-invariant-over-v.stderr │ ├── transmute-dst-not-frombytes.rs │ ├── transmute-dst-not-frombytes.stderr │ ├── transmute-mut-const.rs │ ├── transmute-mut-const.stderr │ ├── transmute-mut-dst-not-a-reference.rs │ ├── transmute-mut-dst-not-a-reference.stderr │ ├── transmute-mut-dst-not-frombytes.rs │ ├── transmute-mut-dst-not-frombytes.stderr │ ├── transmute-mut-dst-not-intobytes.rs │ ├── transmute-mut-dst-not-intobytes.stderr │ ├── transmute-mut-dst-unsized.rs │ ├── transmute-mut-dst-unsized.stderr │ ├── transmute-mut-illegal-lifetime.rs │ ├── transmute-mut-illegal-lifetime.stderr │ ├── transmute-mut-src-dst-not-references.rs │ ├── transmute-mut-src-dst-not-references.stderr │ ├── transmute-mut-src-dst-unsized.stderr │ ├── transmute-mut-src-immutable.rs │ ├── transmute-mut-src-immutable.stderr │ ├── transmute-mut-src-not-a-reference.rs │ ├── transmute-mut-src-not-a-reference.stderr │ ├── transmute-mut-src-not-frombytes.rs │ ├── transmute-mut-src-not-frombytes.stderr │ ├── transmute-mut-src-not-intobytes.rs │ ├── transmute-mut-src-not-intobytes.stderr │ ├── transmute-mut-src-unsized.rs │ ├── transmute-mut-src-unsized.stderr │ ├── transmute-ptr-to-usize.rs │ ├── transmute-ptr-to-usize.stderr │ ├── transmute-ref-dst-mutable.rs │ ├── transmute-ref-dst-mutable.stderr │ ├── transmute-ref-dst-not-a-reference.rs │ ├── transmute-ref-dst-not-a-reference.stderr │ ├── transmute-ref-dst-not-frombytes.rs │ ├── transmute-ref-dst-not-frombytes.stderr │ ├── transmute-ref-dst-not-nocell.rs │ ├── transmute-ref-dst-not-nocell.stderr │ ├── transmute-ref-dst-unsized.rs │ ├── transmute-ref-dst-unsized.stderr │ ├── transmute-ref-illegal-lifetime.rs │ ├── transmute-ref-illegal-lifetime.stderr │ ├── transmute-ref-src-dst-not-references.rs │ ├── transmute-ref-src-dst-not-references.stderr │ ├── transmute-ref-src-dst-unsized.stderr │ ├── transmute-ref-src-not-a-reference.rs │ ├── transmute-ref-src-not-a-reference.stderr │ ├── transmute-ref-src-not-intobytes.rs │ ├── transmute-ref-src-not-intobytes.stderr │ ├── transmute-ref-src-not-nocell.rs │ ├── transmute-ref-src-not-nocell.stderr │ ├── transmute-ref-src-unsized.rs │ ├── transmute-ref-src-unsized.stderr │ ├── transmute-size-decrease.rs │ ├── transmute-size-decrease.stderr │ ├── transmute-size-increase.rs │ ├── transmute-size-increase.stderr │ ├── transmute-src-not-intobytes.rs │ ├── transmute-src-not-intobytes.stderr │ ├── try_transmute-dst-not-tryfrombytes.rs │ ├── try_transmute-dst-not-tryfrombytes.stderr │ ├── try_transmute-size-decrease.rs │ ├── try_transmute-size-decrease.stderr │ ├── try_transmute-size-increase.rs │ ├── try_transmute-size-increase.stderr │ ├── try_transmute-src-not-intobytes.rs │ ├── try_transmute-src-not-intobytes.stderr │ ├── try_transmute_mut-alignment-increase.rs │ ├── try_transmute_mut-alignment-increase.stderr │ ├── try_transmute_mut-dst-not-tryfrombytes.rs │ ├── try_transmute_mut-dst-not-tryfrombytes.stderr │ ├── try_transmute_mut-size-decrease.rs │ ├── try_transmute_mut-size-decrease.stderr │ ├── try_transmute_mut-size-increase.rs │ ├── try_transmute_mut-size-increase.stderr │ ├── try_transmute_mut-src-not-frombytes.rs │ ├── try_transmute_mut-src-not-frombytes.stderr │ ├── try_transmute_mut-src-not-intobytes.rs │ ├── try_transmute_mut-src-not-intobytes.stderr │ ├── try_transmute_ref-alignment-increase.rs │ ├── try_transmute_ref-alignment-increase.stderr │ ├── try_transmute_ref-dst-mutable.rs │ ├── try_transmute_ref-dst-mutable.stderr │ ├── try_transmute_ref-dst-not-immutable-tryfrombytes.rs │ ├── try_transmute_ref-dst-not-immutable-tryfrombytes.stderr │ ├── try_transmute_ref-size-decrease.rs │ ├── try_transmute_ref-size-decrease.stderr │ ├── try_transmute_ref-size-increase.rs │ ├── try_transmute_ref-size-increase.stderr │ ├── try_transmute_ref-src-not-immutable-intobytes.rs │ └── try_transmute_ref-src-not-immutable-intobytes.stderr ├── testutil ├── Cargo.toml └── src │ └── lib.rs ├── tools ├── Cargo.toml ├── cargo-zerocopy │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── generate-readme │ ├── Cargo.toml │ └── src │ │ └── main.rs └── update-ui-test-files.sh ├── win-cargo.bat └── zerocopy-derive ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-BSD ├── LICENSE-MIT ├── src ├── enum.rs ├── ext.rs ├── lib.rs ├── output_tests.rs └── repr.rs └── tests ├── crate_path.rs ├── deprecated.rs ├── enum_from_bytes.rs ├── enum_from_zeros.rs ├── enum_known_layout.rs ├── enum_no_cell.rs ├── enum_to_bytes.rs ├── enum_try_from_bytes.rs ├── enum_unaligned.rs ├── eq.rs ├── hash.rs ├── hygiene.rs ├── include.rs ├── issue_2117.rs ├── paths_and_modules.rs ├── priv_in_pub.rs ├── struct_from_bytes.rs ├── struct_from_zeros.rs ├── struct_known_layout.rs ├── struct_no_cell.rs ├── struct_to_bytes.rs ├── struct_try_from_bytes.rs ├── struct_unaligned.rs ├── trybuild.rs ├── ui-msrv ├── derive_transparent.rs ├── derive_transparent.stderr ├── enum.rs ├── enum.stderr ├── enum_from_bytes_u8_too_few.rs ├── enum_from_bytes_u8_too_few.stderr ├── late_compile_pass.rs ├── late_compile_pass.stderr ├── mid_compile_pass.rs ├── mid_compile_pass.stderr ├── msrv_specific.rs ├── msrv_specific.stderr ├── struct.rs ├── struct.stderr ├── union.rs ├── union.stderr └── union_into_bytes_cfg │ ├── union_into_bytes_cfg.rs │ └── union_into_bytes_cfg.stderr ├── ui-nightly ├── absence_of_deprecated_warning.rs ├── absence_of_deprecated_warning.stderr ├── derive_transparent.rs ├── derive_transparent.stderr ├── enum.rs ├── enum.stderr ├── enum_from_bytes_u16_too_few.rs.disabled ├── enum_from_bytes_u8_too_few.rs ├── enum_from_bytes_u8_too_few.stderr ├── late_compile_pass.rs ├── late_compile_pass.stderr ├── mid_compile_pass.rs ├── mid_compile_pass.stderr ├── struct.rs ├── struct.stderr ├── union.rs ├── union.stderr └── union_into_bytes_cfg │ ├── union_into_bytes_cfg.rs │ └── union_into_bytes_cfg.stderr ├── ui-stable ├── derive_transparent.rs ├── derive_transparent.stderr ├── enum.rs ├── enum.stderr ├── enum_from_bytes_u8_too_few.rs ├── enum_from_bytes_u8_too_few.stderr ├── late_compile_pass.rs ├── late_compile_pass.stderr ├── mid_compile_pass.rs ├── mid_compile_pass.stderr ├── struct.rs ├── struct.stderr ├── union.rs ├── union.stderr └── union_into_bytes_cfg │ ├── union_into_bytes_cfg.rs │ └── union_into_bytes_cfg.stderr ├── union_from_bytes.rs ├── union_from_zeros.rs ├── union_known_layout.rs ├── union_no_cell.rs ├── union_to_bytes.rs ├── union_try_from_bytes.rs ├── union_unaligned.rs └── unsafe_cell.rs /.github/ISSUE_TEMPLATE/customer-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Customer request 3 | about: Describe what features you'd like from zerocopy for your project 4 | title: Features to support 5 | labels: customer-request 6 | assignees: '' 7 | 8 | --- 9 | 10 | **What is the name of your project?** 11 | 12 | **Please provide a link to your project (GitHub repository, crates.io page, etc).** 13 | 14 | **What features would you like from zerocopy?** 15 | For each feature: 16 | - Describe why it would be useful to your project, providing any useful context (GitHub links, etc). 17 | - If there is an existing zerocopy GitHub issue describing this feature, link to it. 18 | -------------------------------------------------------------------------------- /.github/actions/cache/action.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | name: Cache 10 | description: 'Caches cargo dependencies' 11 | outputs: 12 | cache-hit: 13 | description: "Cache Hit" 14 | value: ${{ steps.cache.outputs.cache-hit }} 15 | runs: 16 | using: composite 17 | steps: 18 | - uses: actions/cache@v4 19 | id: cache 20 | with: 21 | path: | 22 | ~/.cargo/ 23 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} 24 | restore-keys: | 25 | ${{ runner.os }}-cargo- 26 | 27 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | version: 2 10 | updates: 11 | - package-ecosystem: github-actions 12 | directory: / 13 | schedule: 14 | interval: daily 15 | commit-message: 16 | # The trailing space instructs dependabot not to insert a colon between 17 | # the prefix and the rest of the message. 18 | prefix: "[CI] " 19 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Fuchsia Authors 2 | # 3 | # Licensed under the 2-Clause BSD License , Apache License, Version 2.0 5 | # , or the MIT 6 | # license , at your option. 7 | # This file may not be copied, modified, or distributed except according to 8 | # those terms. 9 | 10 | target 11 | Cargo.lock 12 | lcov.info 13 | 14 | # VSCode workspace files 15 | *.code-workspace 16 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // Extra cfgs added to rust-analyzer. 3 | "rust-analyzer.cargo.cfgs": [ 4 | // Expensive-to-compile tests can `cfg(not(rust_analyzer))` to avoid 5 | // slowing developers down. 6 | "rust_analyzer", 7 | // Converting unions to bytes currently requires a `cfg` feature. 8 | // Used in some tests. 9 | // See https://github.com/google/zerocopy/discussions/1802. 10 | "zerocopy_derive_union_into_bytes" 11 | ], 12 | // The above list is duplicated so that the `cfg`s are also used in `cargo check`. 13 | // See https://github.com/rust-lang/rust-analyzer/issues/19926. 14 | "rust-analyzer.cargo.extraEnv": { 15 | "RUSTFLAGS": "--cfg rust_analyzer --cfg zerocopy_derive_union_into_bytes" 16 | } 17 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | # How to Contribute 10 | 11 | See our [Contributing Guide](https://github.com/google/zerocopy/discussions/1318). 12 | -------------------------------------------------------------------------------- /LICENSE-BSD: -------------------------------------------------------------------------------- 1 | Copyright 2019 The Fuchsia Authors. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright 2023 The Fuchsia Authors 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | 27 | -------------------------------------------------------------------------------- /cargo.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | set -eo pipefail 10 | 11 | # Build `cargo-zerocopy` without any RUSTFLAGS set in the environment 12 | env -u RUSTFLAGS cargo +stable build --manifest-path tools/Cargo.toml -p cargo-zerocopy -q 13 | # Thin wrapper around the `cargo-zerocopy` binary in `tools/cargo-zerocopy` 14 | ./tools/target/debug/cargo-zerocopy $@ 15 | -------------------------------------------------------------------------------- /ci/check_all_toolchains_tested.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2024 The Fuchsia Authors 4 | # 5 | # Licensed under a BSD-style license , Apache License, Version 2.0 6 | # , or the MIT 7 | # license , at your option. 8 | # This file may not be copied, modified, or distributed except according to 9 | # those terms. 10 | 11 | set -eo pipefail 12 | 13 | # Check whether the set of toolchains tested in this file (other than 14 | # 'msrv', 'stable', and 'nightly') is equal to the set of toolchains 15 | # listed in the 'package.metadata.build-rs' section of Cargo.toml. 16 | # 17 | # If the inputs to `diff` are not identical, `diff` exits with a 18 | # non-zero error code, which causes this script to fail (thanks to 19 | # `set -e`). 20 | diff \ 21 | <(cat .github/workflows/ci.yml | yq '.jobs.build_test.strategy.matrix.toolchain | .[]' | \ 22 | sort -u | grep -v '^\(msrv\|stable\|nightly\)$') \ 23 | <(cargo metadata -q --format-version 1 | \ 24 | jq -r ".packages[] | select(.name == \"zerocopy\").metadata.\"build-rs\" | keys | .[]" | \ 25 | sort -u) >&2 26 | -------------------------------------------------------------------------------- /ci/check_fmt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2024 The Fuchsia Authors 4 | # 5 | # Licensed under a BSD-style license , Apache License, Version 2.0 6 | # , or the MIT 7 | # license , at your option. 8 | # This file may not be copied, modified, or distributed except according to 9 | # those terms. 10 | 11 | set -eo pipefail 12 | files=$(find . -iname '*.rs' -type f -not -path './target/*') 13 | # check that find succeeded 14 | if [[ -z $files ]] 15 | then 16 | exit 1 17 | fi 18 | rustfmt --check $files >&2 19 | -------------------------------------------------------------------------------- /ci/check_readme.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2024 The Fuchsia Authors 4 | # 5 | # Licensed under a BSD-style license , Apache License, Version 2.0 6 | # , or the MIT 7 | # license , at your option. 8 | # This file may not be copied, modified, or distributed except according to 9 | # those terms. 10 | 11 | set -eo pipefail 12 | 13 | # Install again in case the installation failed during the 14 | # `generate_cache` step. We treat that step as best-effort and 15 | # suppress all errors from it. 16 | cargo install -q cargo-readme --version 3.2.0 17 | 18 | diff <(cargo -q run --manifest-path tools/Cargo.toml -p generate-readme) README.md >&2 19 | exit $? 20 | -------------------------------------------------------------------------------- /ci/release_crate_version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2024 The Fuchsia Authors 4 | # 5 | # Licensed under a BSD-style license , Apache License, Version 2.0 6 | # , or the MIT 7 | # license , at your option. 8 | # This file may not be copied, modified, or distributed except according to 9 | # those terms. 10 | 11 | set -e 12 | 13 | if [ $# -ne 1 ]; then 14 | echo "Usage: $0 " >&2 15 | exit 1 16 | fi 17 | 18 | VERSION="$1" 19 | 20 | sed -i -e "s/^zerocopy-derive = { version = \"=[0-9a-zA-Z\.-]*\"/zerocopy-derive = { version = \"=$VERSION\"/" Cargo.toml 21 | sed -i -e "s/^version = \"[0-9a-zA-Z\.-]*\"/version = \"$VERSION\"/" Cargo.toml zerocopy-derive/Cargo.toml 22 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | accept-comment-above-statement = true 10 | accept-comment-above-attributes = true 11 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | edition = "2021" 10 | 11 | # The "Default" setting has a heuristic which splits lines too aggressively. 12 | # We are willing to revisit this setting in future versions of rustfmt. 13 | # Bugs: 14 | # * https://github.com/rust-lang/rustfmt/issues/3119 15 | # * https://github.com/rust-lang/rustfmt/issues/3120 16 | use_small_heuristics = "Max" 17 | 18 | # Prevent carriage returns 19 | newline_style = "Unix" 20 | -------------------------------------------------------------------------------- /testdata/include_value/data: -------------------------------------------------------------------------------- 1 | abcd -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-from-bytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-from-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:18:24 3 | | 4 | 18 | takes_from_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `takes_from_bytes` 8 | --> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:21:24 9 | | 10 | 21 | fn takes_from_bytes() {} 11 | | ^^^^^^^^^ required by this bound in `takes_from_bytes` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-from-zeros.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-from-zeros.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:18:24 3 | | 4 | 18 | takes_from_zeros::(); 5 | | ^^^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `takes_from_zeros` 8 | --> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:21:24 9 | | 10 | 21 | fn takes_from_zeros() {} 11 | | ^^^^^^^^^ required by this bound in `takes_from_zeros` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-immutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-immutable.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-immutable.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:18:23 3 | | 4 | 18 | takes_immutable::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `takes_immutable` 8 | --> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:21:23 9 | | 10 | 21 | fn takes_immutable() {} 11 | | ^^^^^^^^^ required by this bound in `takes_immutable` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-into-bytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-into-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:18:24 3 | | 4 | 18 | takes_into_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `takes_into_bytes` 8 | --> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:21:24 9 | | 10 | 21 | fn takes_into_bytes() {} 11 | | ^^^^^^^^^ required by this bound in `takes_into_bytes` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-issue-1296.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-issue-1296.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:52:19 3 | | 4 | 52 | Foo.write_obj(NotZerocopy(())); 5 | | ^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` 6 | 7 | error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied 8 | --> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:52:19 9 | | 10 | 52 | Foo.write_obj(NotZerocopy(())); 11 | | ^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-known-layout.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-known-layout.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-known-layout.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::KnownLayout` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:18:26 3 | | 4 | 18 | takes_known_layout::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::KnownLayout` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `takes_known_layout` 8 | --> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:21:26 9 | | 10 | 21 | fn takes_known_layout() {} 11 | | ^^^^^^^^^^^ required by this bound in `takes_known_layout` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-try-from-bytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:18:28 3 | | 4 | 18 | takes_try_from_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `takes_try_from_bytes` 8 | --> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:21:28 9 | | 10 | 21 | fn takes_try_from_bytes() {} 11 | | ^^^^^^^^^^^^ required by this bound in `takes_try_from_bytes` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-unaligned.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-unaligned.rs -------------------------------------------------------------------------------- /tests/ui-msrv/diagnostic-not-implemented-unaligned.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::Unaligned` is not satisfied 2 | --> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:18:23 3 | | 4 | 18 | takes_unaligned::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `takes_unaligned` 8 | --> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:21:23 9 | | 10 | 21 | fn takes_unaligned() {} 11 | | ^^^^^^^^^ required by this bound in `takes_unaligned` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/include_value_not_from_bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/include_value_not_from_bytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/include_value_not_from_bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied 2 | --> tests/ui-msrv/include_value_not_from_bytes.rs:19:42 3 | | 4 | 19 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy` 6 | | 7 | note: required by `AssertIsFromBytes` 8 | --> tests/ui-msrv/include_value_not_from_bytes.rs:19:42 9 | | 10 | 19 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); 11 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12 | = note: this error originates in the macro `$crate::transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/include_value_wrong_size.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/include_value_wrong_size.rs -------------------------------------------------------------------------------- /tests/ui-msrv/include_value_wrong_size.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-msrv/include_value_wrong_size.rs:15:25 3 | | 4 | 15 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data"); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `[u8; 4]` (32 bits) 8 | = note: target type: `u64` (64 bits) 9 | = note: this error originates in the macro `$crate::transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-msrv/invalid-impls/invalid-impls.rs: -------------------------------------------------------------------------------- 1 | ../../ui-nightly/invalid-impls/invalid-impls.rs -------------------------------------------------------------------------------- /tests/ui-msrv/max-align.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/max-align.rs -------------------------------------------------------------------------------- /tests/ui-msrv/max-align.stderr: -------------------------------------------------------------------------------- 1 | error[E0589]: invalid `repr(align)` attribute: larger than 2^29 2 | --> tests/ui-msrv/max-align.rs:96:11 3 | | 4 | 96 | #[repr(C, align(1073741824))] 5 | | ^^^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /tests/ui-msrv/ptr-is-invariant-over-v.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/ptr-is-invariant-over-v.rs -------------------------------------------------------------------------------- /tests/ui-msrv/ptr-is-invariant-over-v.stderr: -------------------------------------------------------------------------------- 1 | error[E0623]: lifetime mismatch 2 | --> tests/ui-msrv/ptr-is-invariant-over-v.rs:10:14 3 | | 4 | 7 | big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>, 5 | | --------------------------------------------------- these two types are declared with different lifetimes... 6 | ... 7 | 10 | _small = big; 8 | | ^^^ ...but data from `big` flows into `big` here 9 | 10 | error[E0623]: lifetime mismatch 11 | --> tests/ui-msrv/ptr-is-invariant-over-v.rs:17:14 12 | | 13 | 14 | big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>, 14 | | ------------------------------------------------ these two types are declared with different lifetimes... 15 | ... 16 | 17 | _small = big; 17 | | ^^^ ...but data from `big` flows into `big` here 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-dst-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-dst-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied 2 | --> tests/ui-msrv/transmute-dst-not-frombytes.rs:19:41 3 | | 4 | 19 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy` 6 | | 7 | note: required by `AssertIsFromBytes` 8 | --> tests/ui-msrv/transmute-dst-not-frombytes.rs:19:41 9 | | 10 | 19 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); 11 | | ^^^^^^^^^^^^^^^^^^^ 12 | = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-const.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-const.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36 3 | | 4 | 17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` 6 | | 7 | = note: expected type `usize` 8 | found mutable reference `&mut _` 9 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: FromBytes` is not satisfied 2 | --> tests/ui-msrv/transmute-mut-dst-not-frombytes.rs:24:38 3 | | 4 | 24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` 6 | | 7 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied 2 | --> tests/ui-msrv/transmute-mut-dst-not-intobytes.rs:24:36 3 | | 4 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` 6 | | 7 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-unsized.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-dst-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time 2 | --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32 3 | | 4 | 17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 6 | | 7 | = help: the trait `Sized` is not implemented for `[u8]` 8 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-illegal-lifetime.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-illegal-lifetime.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-illegal-lifetime.stderr: -------------------------------------------------------------------------------- 1 | error[E0597]: `x` does not live long enough 2 | --> tests/ui-msrv/transmute-mut-illegal-lifetime.rs:14:56 3 | | 4 | 14 | let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); 5 | | ---------------- ^^^^^^ borrowed value does not live long enough 6 | | | 7 | | type annotation requires that `x` is borrowed for `'static` 8 | 15 | } 9 | | - `x` dropped here while still borrowed 10 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-dst-not-references.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-dst-not-references.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-dst-not-references.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-msrv/transmute-mut-src-dst-not-references.rs:17:59 3 | | 4 | 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&mut _`, found `usize` 8 | | | help: consider mutably borrowing here: `&mut 0usize` 9 | | expected due to this 10 | | 11 | = note: expected mutable reference `&mut _` 12 | found type `usize` 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-immutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-immutable.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-immutable.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-msrv/transmute-mut-src-immutable.rs:17:37 3 | | 4 | 17 | let _: &mut u8 = transmute_mut!(&0u8); 5 | | ---------------^^^^- 6 | | | | 7 | | | types differ in mutability 8 | | expected due to this 9 | | 10 | = note: expected mutable reference `&mut _` 11 | found reference `&u8` 12 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-msrv/transmute-mut-src-not-a-reference.rs:17:53 3 | | 4 | 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&mut _`, found `usize` 8 | | | help: consider mutably borrowing here: `&mut 0usize` 9 | | expected due to this 10 | | 11 | = note: expected mutable reference `&mut _` 12 | found type `usize` 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Src: FromBytes` is not satisfied 2 | --> tests/ui-msrv/transmute-mut-src-not-frombytes.rs:24:38 3 | | 4 | 24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` 6 | | 7 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Src: IntoBytes` is not satisfied 2 | --> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36 3 | | 4 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` 6 | | 7 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-unsized.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-mut-src-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` 2 | --> tests/ui-msrv/transmute-mut-src-unsized.rs:17:35 3 | | 4 | 17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize` 6 | | 7 | = note: required because of the requirements on the impl of `TransmuteMutDst<'_>` for `Wrap<&mut [u8], &mut [u8; 1]>` 8 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ptr-to-usize.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ptr-to-usize.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-mutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-mutable.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: zerocopy::FromBytes` is not satisfied 2 | --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:23:34 3 | | 4 | 23 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `Dst` 6 | | 7 | note: required by `AssertDstIsFromBytes` 8 | --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:23:34 9 | | 10 | 23 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); 11 | | ^^^^^^^^^^^^^^^^^^^^^^^^ 12 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-not-nocell.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-not-nocell.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-not-nocell.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: zerocopy::Immutable` is not satisfied 2 | --> tests/ui-msrv/transmute-ref-dst-not-nocell.rs:23:33 3 | | 4 | 23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `Dst` 6 | | 7 | note: required by `AssertDstIsImmutable` 8 | --> tests/ui-msrv/transmute-ref-dst-not-nocell.rs:23:33 9 | | 10 | 23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); 11 | | ^^^^^^^^^^^^^^^^^^^^^^^^ 12 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-unsized.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-dst-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time 2 | --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28 3 | | 4 | 17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 6 | | 7 | = help: the trait `Sized` is not implemented for `[u8]` 8 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-illegal-lifetime.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-illegal-lifetime.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-illegal-lifetime.stderr: -------------------------------------------------------------------------------- 1 | error[E0597]: `x` does not live long enough 2 | --> tests/ui-msrv/transmute-ref-illegal-lifetime.rs:14:52 3 | | 4 | 14 | let _: &'static u64 = zerocopy::transmute_ref!(&x); 5 | | ------------ ^^ borrowed value does not live long enough 6 | | | 7 | | type annotation requires that `x` is borrowed for `'static` 8 | 15 | } 9 | | - `x` dropped here while still borrowed 10 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-src-dst-not-references.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-dst-not-references.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-src-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-src-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-msrv/transmute-ref-src-not-a-reference.rs:17:49 3 | | 4 | 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected reference, found `usize` 8 | | | help: consider borrowing here: `&0usize` 9 | | expected due to this 10 | | 11 | = note: expected reference `&_` 12 | found type `usize` 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-src-not-nocell.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-not-nocell.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-src-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-unsized.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-ref-src-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` 2 | --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31 3 | | 4 | 16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize` 6 | | 7 | = note: required because of the requirements on the impl of `TransmuteRefDst<'_>` for `Wrap<&[u8], &[u8; 1]>` 8 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-msrv/transmute-size-decrease.rs:20:27 3 | | 4 | 20 | const DECREASE_SIZE: u8 = transmute!(AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-size-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-msrv/transmute-size-increase.rs:20:29 3 | | 4 | 20 | const INCREASE_SIZE: AU16 = transmute!(0u8); 5 | | ^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `u8` (8 bits) 8 | = note: target type: `AU16` (16 bits) 9 | = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-msrv/transmute-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-dst-not-tryfrombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | warning: unused variable: `decrease_size` 2 | --> tests/ui-msrv/try_transmute-size-decrease.rs:19:9 3 | | 4 | 19 | let decrease_size: Result = try_transmute!(AU16(0)); 5 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_decrease_size` 6 | | 7 | = note: `#[warn(unused_variables)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-msrv/try_transmute-size-decrease.rs:19:40 11 | | 12 | 19 | let decrease_size: Result = try_transmute!(AU16(0)); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `AU16` (16 bits) 16 | = note: target type: `u8` (8 bits) 17 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute-size-increase.stderr: -------------------------------------------------------------------------------- 1 | warning: unused variable: `increase_size` 2 | --> tests/ui-msrv/try_transmute-size-increase.rs:19:9 3 | | 4 | 19 | let increase_size: Result = try_transmute!(0u8); 5 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` 6 | | 7 | = note: `#[warn(unused_variables)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-msrv/try_transmute-size-increase.rs:19:42 11 | | 12 | 19 | let increase_size: Result = try_transmute!(0u8); 13 | | ^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `u8` (8 bits) 16 | = note: target type: `AU16` (16 bits) 17 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute-src-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied 2 | --> tests/ui-msrv/try_transmute-src-not-intobytes.rs:18:47 3 | | 4 | 18 | let src_not_into_bytes: Result = try_transmute!(NotZerocopy(AU16(0))); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` 6 | | 7 | note: required by a bound in `try_transmute` 8 | --> src/util/macro_util.rs 9 | | 10 | | Src: IntoBytes, 11 | | ^^^^^^^^^ required by this bound in `try_transmute` 12 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 13 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-alignment-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-alignment-increase.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-alignment-increase.stderr: -------------------------------------------------------------------------------- 1 | warning: unused variable: `increase_size` 2 | --> tests/ui-msrv/try_transmute_mut-alignment-increase.rs:20:9 3 | | 4 | 20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); 5 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` 6 | | 7 | = note: `#[warn(unused_variables)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-msrv/try_transmute_mut-alignment-increase.rs:20:47 11 | | 12 | 20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 16 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 17 | = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | warning: unused variable: `decrease_size` 2 | --> tests/ui-msrv/try_transmute_mut-size-decrease.rs:20:9 3 | | 4 | 20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); 5 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_decrease_size` 6 | | 7 | = note: `#[warn(unused_variables)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-msrv/try_transmute_mut-size-decrease.rs:20:45 11 | | 12 | 20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `AU16` (16 bits) 16 | = note: target type: `u8` (8 bits) 17 | = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-size-increase.stderr: -------------------------------------------------------------------------------- 1 | warning: unused import: `util::AU16` 2 | --> tests/ui-msrv/try_transmute_mut-size-increase.rs:13:5 3 | | 4 | 13 | use util::AU16; 5 | | ^^^^^^^^^^ 6 | | 7 | = note: `#[warn(unused_imports)]` on by default 8 | 9 | warning: unused variable: `increase_size` 10 | --> tests/ui-msrv/try_transmute_mut-size-increase.rs:20:9 11 | | 12 | 20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); 13 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` 14 | | 15 | = note: `#[warn(unused_variables)]` on by default 16 | 17 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 18 | --> tests/ui-msrv/try_transmute_mut-size-increase.rs:20:50 19 | | 20 | 20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); 21 | | ^^^^^^^^^^^^^^^^^^^^^^^ 22 | | 23 | = note: source type: `u8` (8 bits) 24 | = note: target type: `[u8; 2]` (16 bits) 25 | = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) 26 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-src-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-src-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_mut-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-alignment-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-alignment-increase.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-alignment-increase.stderr: -------------------------------------------------------------------------------- 1 | warning: unused variable: `increase_size` 2 | --> tests/ui-msrv/try_transmute_ref-alignment-increase.rs:19:9 3 | | 4 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 5 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` 6 | | 7 | = note: `#[warn(unused_variables)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-msrv/try_transmute_ref-alignment-increase.rs:19:43 11 | | 12 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 16 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 17 | = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-dst-mutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-dst-mutable.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-dst-mutable.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-msrv/try_transmute_ref-dst-mutable.rs:18:33 3 | | 4 | 18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability 6 | | 7 | = note: expected mutable reference `&mut u8` 8 | found reference `&_` 9 | = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | 11 | error[E0308]: mismatched types 12 | --> tests/ui-msrv/try_transmute_ref-dst-mutable.rs:18:33 13 | | 14 | 18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); 15 | | ^^^^^^^^^^^^^^^^^^^^^^^^ 16 | | | 17 | | types differ in mutability 18 | | help: try using a variant of the expected enum: `Err($crate::util::macro_util::try_transmute_ref::<_, _>(e))` 19 | | 20 | = note: expected enum `Result<&mut u8, _>` 21 | found enum `Result<&_, ValidityError<&u8, _>>` 22 | = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 23 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | warning: unused variable: `decrease_size` 2 | --> tests/ui-msrv/try_transmute_ref-size-decrease.rs:19:9 3 | | 4 | 19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_decrease_size` 6 | | 7 | = note: `#[warn(unused_variables)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-msrv/try_transmute_ref-size-decrease.rs:19:41 11 | | 12 | 19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `AU16` (16 bits) 16 | = note: target type: `u8` (8 bits) 17 | = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-size-increase.stderr: -------------------------------------------------------------------------------- 1 | warning: unused variable: `increase_size` 2 | --> tests/ui-msrv/try_transmute_ref-size-increase.rs:19:9 3 | | 4 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 5 | | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_increase_size` 6 | | 7 | = note: `#[warn(unused_variables)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-msrv/try_transmute_ref-size-increase.rs:19:43 11 | | 12 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 16 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 17 | = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-from-bytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::NotZerocopy; 14 | use zerocopy::FromBytes; 15 | 16 | fn main() { 17 | // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. 18 | takes_from_bytes::(); 19 | } 20 | 21 | fn takes_from_bytes() {} 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-from-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied 2 | --> tests/ui-nightly/diagnostic-not-implemented-from-bytes.rs:18:24 3 | | 4 | 18 | takes_from_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::FromBytes`: 9 | () 10 | AU16 11 | AtomicI16 12 | AtomicI32 13 | AtomicI64 14 | AtomicI8 15 | AtomicIsize 16 | AtomicU16 17 | and $N others 18 | note: required by a bound in `takes_from_bytes` 19 | --> tests/ui-nightly/diagnostic-not-implemented-from-bytes.rs:21:24 20 | | 21 | 21 | fn takes_from_bytes() {} 22 | | ^^^^^^^^^ required by this bound in `takes_from_bytes` 23 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-from-zeros.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::NotZerocopy; 14 | use zerocopy::FromZeros; 15 | 16 | fn main() { 17 | // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. 18 | takes_from_zeros::(); 19 | } 20 | 21 | fn takes_from_zeros() {} 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-from-zeros.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied 2 | --> tests/ui-nightly/diagnostic-not-implemented-from-zeros.rs:18:24 3 | | 4 | 18 | takes_from_zeros::(); 5 | | ^^^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy` 8 | = help: the following other types implement trait `FromZeros`: 9 | () 10 | *const T 11 | *mut T 12 | AU16 13 | AtomicBool 14 | AtomicI16 15 | AtomicI32 16 | AtomicI64 17 | and $N others 18 | note: required by a bound in `takes_from_zeros` 19 | --> tests/ui-nightly/diagnostic-not-implemented-from-zeros.rs:21:24 20 | | 21 | 21 | fn takes_from_zeros() {} 22 | | ^^^^^^^^^ required by this bound in `takes_from_zeros` 23 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-immutable.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::NotZerocopy; 14 | use zerocopy::Immutable; 15 | 16 | fn main() { 17 | // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. 18 | takes_immutable::(); 19 | } 20 | 21 | fn takes_immutable() {} 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-immutable.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied 2 | --> tests/ui-nightly/diagnostic-not-implemented-immutable.rs:18:23 3 | | 4 | 18 | takes_immutable::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(Immutable)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::Immutable`: 9 | &T 10 | &mut T 11 | () 12 | *const T 13 | *mut T 14 | AU16 15 | Box 16 | F32 17 | and $N others 18 | note: required by a bound in `takes_immutable` 19 | --> tests/ui-nightly/diagnostic-not-implemented-immutable.rs:21:23 20 | | 21 | 21 | fn takes_immutable() {} 22 | | ^^^^^^^^^ required by this bound in `takes_immutable` 23 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-into-bytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::NotZerocopy; 14 | use zerocopy::IntoBytes; 15 | 16 | fn main() { 17 | // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. 18 | takes_into_bytes::(); 19 | } 20 | 21 | fn takes_into_bytes() {} 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-into-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied 2 | --> tests/ui-nightly/diagnostic-not-implemented-into-bytes.rs:18:24 3 | | 4 | 18 | takes_into_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::IntoBytes`: 9 | () 10 | AU16 11 | AtomicBool 12 | AtomicI16 13 | AtomicI32 14 | AtomicI64 15 | AtomicI8 16 | AtomicIsize 17 | and $N others 18 | note: required by a bound in `takes_into_bytes` 19 | --> tests/ui-nightly/diagnostic-not-implemented-into-bytes.rs:21:24 20 | | 21 | 21 | fn takes_into_bytes() {} 22 | | ^^^^^^^^^ required by this bound in `takes_into_bytes` 23 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-known-layout.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::NotZerocopy; 14 | use zerocopy::KnownLayout; 15 | 16 | fn main() { 17 | // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. 18 | takes_known_layout::(); 19 | } 20 | 21 | fn takes_known_layout() {} 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-known-layout.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::KnownLayout` is not satisfied 2 | --> tests/ui-nightly/diagnostic-not-implemented-known-layout.rs:18:26 3 | | 4 | 18 | takes_known_layout::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::KnownLayout` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(KnownLayout)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::KnownLayout`: 9 | &T 10 | &mut T 11 | () 12 | *const T 13 | *mut T 14 | AU16 15 | AtomicBool 16 | AtomicI16 17 | and $N others 18 | note: required by a bound in `takes_known_layout` 19 | --> tests/ui-nightly/diagnostic-not-implemented-known-layout.rs:21:26 20 | | 21 | 21 | fn takes_known_layout() {} 22 | | ^^^^^^^^^^^ required by this bound in `takes_known_layout` 23 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::NotZerocopy; 14 | use zerocopy::TryFromBytes; 15 | 16 | fn main() { 17 | // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. 18 | takes_try_from_bytes::(); 19 | } 20 | 21 | fn takes_try_from_bytes() {} 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied 2 | --> tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.rs:18:28 3 | | 4 | 18 | takes_try_from_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::TryFromBytes`: 9 | () 10 | *const T 11 | *mut T 12 | AU16 13 | AtomicBool 14 | AtomicI16 15 | AtomicI32 16 | AtomicI64 17 | and $N others 18 | note: required by a bound in `takes_try_from_bytes` 19 | --> tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.rs:21:28 20 | | 21 | 21 | fn takes_try_from_bytes() {} 22 | | ^^^^^^^^^^^^ required by this bound in `takes_try_from_bytes` 23 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-unaligned.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::NotZerocopy; 14 | use zerocopy::Unaligned; 15 | 16 | fn main() { 17 | // We expect the proper diagnostic to be emitted on Rust 1.78.0 and later. 18 | takes_unaligned::(); 19 | } 20 | 21 | fn takes_unaligned() {} 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/diagnostic-not-implemented-unaligned.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::Unaligned` is not satisfied 2 | --> tests/ui-nightly/diagnostic-not-implemented-unaligned.rs:18:23 3 | | 4 | 18 | takes_unaligned::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(Unaligned)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::Unaligned`: 9 | () 10 | AtomicBool 11 | AtomicI8 12 | AtomicU8 13 | Cell 14 | F32 15 | F64 16 | I128 17 | and $N others 18 | note: required by a bound in `takes_unaligned` 19 | --> tests/ui-nightly/diagnostic-not-implemented-unaligned.rs:21:23 20 | | 21 | 21 | fn takes_unaligned() {} 22 | | ^^^^^^^^^ required by this bound in `takes_unaligned` 23 | -------------------------------------------------------------------------------- /tests/ui-nightly/include_value_not_from_bytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | #[macro_use] 12 | extern crate zerocopy; 13 | 14 | use util::NotZerocopy; 15 | 16 | fn main() {} 17 | 18 | // Should fail because `NotZerocopy: !FromBytes`. 19 | const NOT_FROM_BYTES: NotZerocopy = include_value!("../../testdata/include_value/data"); 20 | -------------------------------------------------------------------------------- /tests/ui-nightly/include_value_wrong_size.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | #[macro_use] 10 | extern crate zerocopy; 11 | 12 | fn main() {} 13 | 14 | // Should fail because the file is 4 bytes long, not 8. 15 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data"); 16 | -------------------------------------------------------------------------------- /tests/ui-nightly/include_value_wrong_size.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/include_value_wrong_size.rs:15:25 3 | | 4 | 15 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data"); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `[u8; 4]` (32 bits) 8 | = note: target type: `u64` (64 bits) 9 | = note: this error originates in the macro `$crate::transmute` which comes from the expansion of the macro `include_value` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/invalid-impls/invalid-impls.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // Since some macros from `macros.rs` are unused. 10 | #![allow(unused)] 11 | 12 | extern crate zerocopy; 13 | extern crate zerocopy_derive; 14 | 15 | include!("../../../src/util/macros.rs"); 16 | 17 | use zerocopy::*; 18 | use zerocopy_derive::*; 19 | 20 | fn main() {} 21 | 22 | #[derive(FromBytes, IntoBytes, Unaligned)] 23 | #[repr(transparent)] 24 | struct Foo(T); 25 | 26 | const _: () = unsafe { 27 | impl_or_verify!(T => TryFromBytes for Foo); 28 | impl_or_verify!(T => FromZeros for Foo); 29 | impl_or_verify!(T => FromBytes for Foo); 30 | impl_or_verify!(T => IntoBytes for Foo); 31 | impl_or_verify!(T => Unaligned for Foo); 32 | }; 33 | -------------------------------------------------------------------------------- /tests/ui-nightly/max-align.stderr: -------------------------------------------------------------------------------- 1 | error[E0589]: invalid `repr(align)` attribute: larger than 2^29 2 | --> tests/ui-nightly/max-align.rs:96:17 3 | | 4 | 96 | #[repr(C, align(1073741824))] 5 | | ^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /tests/ui-nightly/ptr-is-invariant-over-v.rs: -------------------------------------------------------------------------------- 1 | use zerocopy::pointer::{ 2 | invariant::{Aligned, Exclusive, Shared, Valid}, 3 | Ptr, 4 | }; 5 | 6 | fn _when_exclusive<'big: 'small, 'small>( 7 | big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>, 8 | mut _small: Ptr<'small, &'small u32, (Exclusive, Aligned, Valid)>, 9 | ) { 10 | _small = big; 11 | } 12 | 13 | fn _when_shared<'big: 'small, 'small>( 14 | big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>, 15 | mut _small: Ptr<'small, &'small u32, (Shared, Aligned, Valid)>, 16 | ) { 17 | _small = big; 18 | } 19 | 20 | fn main() {} 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::{NotZerocopy, AU16}; 14 | use zerocopy::transmute; 15 | 16 | fn main() {} 17 | 18 | // `transmute` requires that the destination type implements `FromBytes` 19 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); 20 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-const.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use zerocopy::transmute_mut; 14 | 15 | fn main() {} 16 | 17 | const ARRAY_OF_U8S: [u8; 2] = [0u8; 2]; 18 | 19 | // `transmute_mut!` cannot, generally speaking, be used in const contexts. 20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-const.stderr: -------------------------------------------------------------------------------- 1 | warning: taking a mutable reference to a `const` item 2 | --> tests/ui-nightly/transmute-mut-const.rs:20:52 3 | | 4 | 20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); 5 | | ^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: each usage of a `const` item creates a new temporary 8 | = note: the mutable reference will refer to this temporary, not the original `const` item 9 | note: `const` item defined here 10 | --> tests/ui-nightly/transmute-mut-const.rs:17:1 11 | | 12 | 17 | const ARRAY_OF_U8S: [u8; 2] = [0u8; 2]; 13 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14 | = note: `#[warn(const_item_mutation)]` on by default 15 | 16 | error[E0015]: cannot call non-const method `Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut` in constants 17 | --> tests/ui-nightly/transmute-mut-const.rs:20:37 18 | | 19 | 20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); 20 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21 | | 22 | = note: calls in constants are limited to constant functions, tuple structs and tuple variants 23 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 24 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | // `transmute_mut!` does not support transmuting into a non-reference 16 | // destination type. 17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36 3 | | 4 | 17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` 6 | | 7 | = note: expected type `usize` 8 | found mutable reference `&mut _` 9 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] 16 | #[repr(C)] 17 | struct Src; 18 | 19 | #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] 20 | #[repr(C)] 21 | struct Dst; 22 | 23 | // `transmute_mut` requires that the destination type implements `FromBytes` 24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 25 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: FromBytes` is not satisfied 2 | --> tests/ui-nightly/transmute-mut-dst-not-frombytes.rs:24:38 3 | | 4 | 24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` 6 | | 7 | = note: Consider adding `#[derive(FromBytes)]` to `Dst` 8 | = help: the following other types implement trait `FromBytes`: 9 | () 10 | AtomicI16 11 | AtomicI32 12 | AtomicI64 13 | AtomicI8 14 | AtomicIsize 15 | AtomicU16 16 | AtomicU32 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | ... 24 | | Dst: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] 16 | #[repr(C)] 17 | struct Src; 18 | 19 | #[derive(zerocopy::FromBytes, zerocopy::Immutable)] 20 | #[repr(C)] 21 | struct Dst; 22 | 23 | // `transmute_mut` requires that the destination type implements `IntoBytes` 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 25 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied 2 | --> tests/ui-nightly/transmute-mut-dst-not-intobytes.rs:24:36 3 | | 4 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` 8 | = help: the following other types implement trait `IntoBytes`: 9 | () 10 | AtomicBool 11 | AtomicI16 12 | AtomicI32 13 | AtomicI64 14 | AtomicI8 15 | AtomicIsize 16 | AtomicU16 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | ... 24 | | Dst: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-unsized.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | // `transmute_mut!` does not support transmuting into an unsized destination 16 | // type. 17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-dst-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time 2 | --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32 3 | | 4 | 17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 6 | | 7 | = help: the trait `Sized` is not implemented for `[u8]` 8 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 9 | --> src/util/macro_util.rs 10 | | 11 | | impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst> { 12 | | ^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 13 | ... 14 | | pub fn transmute_mut(self) -> &'a mut Dst 15 | | ------------- required by a bound in this associated function 16 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 17 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-illegal-lifetime.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | fn main() {} 10 | 11 | fn increase_lifetime() { 12 | let mut x = 0u64; 13 | // It is illegal to increase the lifetime scope. 14 | let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); 15 | } 16 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-illegal-lifetime.stderr: -------------------------------------------------------------------------------- 1 | error[E0597]: `x` does not live long enough 2 | --> tests/ui-nightly/transmute-mut-illegal-lifetime.rs:14:56 3 | | 4 | 12 | let mut x = 0u64; 5 | | ----- binding `x` declared here 6 | 13 | // It is illegal to increase the lifetime scope. 7 | 14 | let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); 8 | | ---------------- ^^^^^^ borrowed value does not live long enough 9 | | | 10 | | type annotation requires that `x` is borrowed for `'static` 11 | 15 | } 12 | | - `x` dropped here while still borrowed 13 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-dst-not-references.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | // `transmute_mut!` does not support transmuting between non-reference source 16 | // and destination types. 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-dst-not-references.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-nightly/transmute-mut-src-dst-not-references.rs:17:59 3 | | 4 | 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&mut _`, found `usize` 8 | | expected due to this 9 | | 10 | = note: expected mutable reference `&mut _` 11 | found type `usize` 12 | help: consider mutably borrowing here 13 | | 14 | 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(&mut 0usize); 15 | | ++++ 16 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-immutable.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | fn ref_src_immutable() { 16 | // `transmute_mut!` requires that its source type be a mutable reference. 17 | let _: &mut u8 = transmute_mut!(&0u8); 18 | } 19 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-immutable.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-nightly/transmute-mut-src-immutable.rs:17:37 3 | | 4 | 17 | let _: &mut u8 = transmute_mut!(&0u8); 5 | | ---------------^^^^- 6 | | | | 7 | | | types differ in mutability 8 | | expected due to this 9 | | 10 | = note: expected mutable reference `&mut _` 11 | found reference `&u8` 12 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | // `transmute_mut!` does not support transmuting from a non-reference source 16 | // type. 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-nightly/transmute-mut-src-not-a-reference.rs:17:53 3 | | 4 | 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&mut _`, found `usize` 8 | | expected due to this 9 | | 10 | = note: expected mutable reference `&mut _` 11 | found type `usize` 12 | help: consider mutably borrowing here 13 | | 14 | 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(&mut 0usize); 15 | | ++++ 16 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] 16 | #[repr(C)] 17 | struct Src; 18 | 19 | #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] 20 | #[repr(C)] 21 | struct Dst; 22 | 23 | // `transmute_mut` requires that the source type implements `FromBytes` 24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 25 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Src: FromBytes` is not satisfied 2 | --> tests/ui-nightly/transmute-mut-src-not-frombytes.rs:24:38 3 | | 4 | 24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` 6 | | 7 | = note: Consider adding `#[derive(FromBytes)]` to `Src` 8 | = help: the following other types implement trait `FromBytes`: 9 | () 10 | AtomicI16 11 | AtomicI32 12 | AtomicI64 13 | AtomicI8 14 | AtomicIsize 15 | AtomicU16 16 | AtomicU32 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | | where 24 | | Src: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | #[derive(zerocopy::FromBytes, zerocopy::Immutable)] 16 | #[repr(C)] 17 | struct Src; 18 | 19 | #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)] 20 | #[repr(C)] 21 | struct Dst; 22 | 23 | // `transmute_mut` requires that the source type implements `IntoBytes` 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 25 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Src: IntoBytes` is not satisfied 2 | --> tests/ui-nightly/transmute-mut-src-not-intobytes.rs:24:36 3 | | 4 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `Src` 8 | = help: the following other types implement trait `IntoBytes`: 9 | () 10 | AtomicBool 11 | AtomicI16 12 | AtomicI32 13 | AtomicI64 14 | AtomicI8 15 | AtomicIsize 16 | AtomicU16 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | | where 24 | | Src: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-unsized.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | fn main() {} 14 | 15 | // `transmute_mut!` does not support transmuting from an unsized source type to 16 | // a sized destination type. 17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-mut-src-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` 2 | --> tests/ui-nightly/transmute-mut-src-unsized.rs:17:35 3 | | 4 | 17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` 6 | | 7 | = note: required for `Wrap<&mut [u8], &mut [u8; 1]>` to implement `TransmuteMutDst<'_>` 8 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ptr-to-usize.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute; 12 | 13 | fn main() {} 14 | 15 | // It is unclear whether we can or should support this transmutation, especially 16 | // in a const context. This test ensures that even if such a transmutation 17 | // becomes valid due to the requisite implementations of `FromBytes` being 18 | // added, that we re-examine whether it should specifically be valid in a const 19 | // context. 20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-mutable.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_ref; 12 | 13 | fn main() {} 14 | 15 | fn ref_dst_mutable() { 16 | // `transmute_ref!` requires that its destination type be an immutable 17 | // reference. 18 | let _: &mut u8 = transmute_ref!(&0u8); 19 | } 20 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_ref; 12 | 13 | fn main() {} 14 | 15 | // `transmute_ref!` does not support transmuting into a non-reference 16 | // destination type. 17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::transmute_ref; 15 | 16 | fn main() {} 17 | 18 | #[derive(zerocopy::Immutable)] 19 | #[repr(transparent)] 20 | struct Dst(AU16); 21 | 22 | // `transmute_ref` requires that the destination type implements `FromBytes` 23 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); 24 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: zerocopy::FromBytes` is not satisfied 2 | --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:23:34 3 | | 4 | 23 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | | 7 | | the trait `zerocopy::FromBytes` is not implemented for `Dst` 8 | | required by a bound introduced by this call 9 | | 10 | = note: Consider adding `#[derive(FromBytes)]` to `Dst` 11 | = help: the following other types implement trait `zerocopy::FromBytes`: 12 | () 13 | AU16 14 | AtomicI16 15 | AtomicI32 16 | AtomicI64 17 | AtomicI8 18 | AtomicIsize 19 | AtomicU16 20 | and $N others 21 | note: required by a bound in `AssertDstIsFromBytes` 22 | --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:23:34 23 | | 24 | 23 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0)); 25 | | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes` 26 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-not-nocell.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::transmute_ref; 15 | 16 | fn main() {} 17 | 18 | #[derive(zerocopy::FromBytes)] 19 | #[repr(transparent)] 20 | struct Dst(AU16); 21 | 22 | // `transmute_ref` requires that the destination type implements `Immutable` 23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); 24 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-not-nocell.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: zerocopy::Immutable` is not satisfied 2 | --> tests/ui-nightly/transmute-ref-dst-not-nocell.rs:23:33 3 | | 4 | 23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | | 7 | | the trait `zerocopy::Immutable` is not implemented for `Dst` 8 | | required by a bound introduced by this call 9 | | 10 | = note: Consider adding `#[derive(Immutable)]` to `Dst` 11 | = help: the following other types implement trait `zerocopy::Immutable`: 12 | &T 13 | &mut T 14 | () 15 | *const T 16 | *mut T 17 | AU16 18 | Box 19 | F32 20 | and $N others 21 | note: required by a bound in `AssertDstIsImmutable` 22 | --> tests/ui-nightly/transmute-ref-dst-not-nocell.rs:23:33 23 | | 24 | 23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); 25 | | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsImmutable` 26 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-unsized.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_ref; 12 | 13 | fn main() {} 14 | 15 | // `transmute_ref!` does not support transmuting into an unsized destination 16 | // type. 17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-dst-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time 2 | --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28 3 | | 4 | 17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 6 | | 7 | = help: the trait `Sized` is not implemented for `[u8]` 8 | note: required by a bound in `Wrap::<&'a Src, &'a Dst>::transmute_ref` 9 | --> src/util/macro_util.rs 10 | | 11 | | impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst> { 12 | | ^^^ required by this bound in `Wrap::<&Src, &Dst>::transmute_ref` 13 | ... 14 | | pub const unsafe fn transmute_ref(self) -> &'a Dst { 15 | | ------------- required by a bound in this associated function 16 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 17 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-illegal-lifetime.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | fn main() {} 10 | 11 | fn increase_lifetime() { 12 | let x = 0u64; 13 | // It is illegal to increase the lifetime scope. 14 | let _: &'static u64 = zerocopy::transmute_ref!(&x); 15 | } 16 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-illegal-lifetime.stderr: -------------------------------------------------------------------------------- 1 | error[E0597]: `x` does not live long enough 2 | --> tests/ui-nightly/transmute-ref-illegal-lifetime.rs:14:52 3 | | 4 | 12 | let x = 0u64; 5 | | - binding `x` declared here 6 | 13 | // It is illegal to increase the lifetime scope. 7 | 14 | let _: &'static u64 = zerocopy::transmute_ref!(&x); 8 | | ------------ ^^ borrowed value does not live long enough 9 | | | 10 | | type annotation requires that `x` is borrowed for `'static` 11 | 15 | } 12 | | - `x` dropped here while still borrowed 13 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-src-dst-not-references.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_ref; 12 | 13 | fn main() {} 14 | 15 | // `transmute_ref!` does not support transmuting between non-reference source 16 | // and destination types. 17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-src-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_ref; 12 | 13 | fn main() {} 14 | 15 | // `transmute_ref!` does not support transmuting from a non-reference source 16 | // type. 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-src-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-nightly/transmute-ref-src-not-a-reference.rs:17:49 3 | | 4 | 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&_`, found `usize` 8 | | expected due to this 9 | | 10 | = note: expected reference `&_` 11 | found type `usize` 12 | help: consider borrowing here 13 | | 14 | 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(&0usize); 15 | | + 16 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::transmute_ref; 15 | 16 | fn main() {} 17 | 18 | #[derive(zerocopy::Immutable)] 19 | #[repr(transparent)] 20 | struct Src(AU16); 21 | 22 | // `transmute_ref` requires that the source type implements `IntoBytes` 23 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0))); 24 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-src-not-nocell.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::transmute_ref; 15 | 16 | fn main() {} 17 | 18 | #[derive(zerocopy::IntoBytes)] 19 | #[repr(transparent)] 20 | struct Src(AU16); 21 | 22 | // `transmute_ref` requires that the source type implements `Immutable` 23 | const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0))); 24 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-src-unsized.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_ref; 12 | 13 | fn main() {} 14 | 15 | // `transmute_ref!` does not support transmuting from an unsized source type. 16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); 17 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-ref-src-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` 2 | --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31 3 | | 4 | 16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` 6 | | 7 | = note: required for `Wrap<&[u8], &[u8; 1]>` to implement `TransmuteRefDst<'_>` 8 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-size-decrease.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::transmute; 15 | 16 | fn main() {} 17 | 18 | // Although this is not a soundness requirement, we currently require that the 19 | // size of the destination type is not smaller than the size of the source type. 20 | const DECREASE_SIZE: u8 = transmute!(AU16(0)); 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/transmute-size-decrease.rs:20:27 3 | | 4 | 20 | const DECREASE_SIZE: u8 = transmute!(AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-size-increase.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::transmute; 15 | 16 | fn main() {} 17 | 18 | // `transmute!` does not support transmuting from a smaller type to a larger 19 | // one. 20 | const INCREASE_SIZE: AU16 = transmute!(0u8); 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-size-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/transmute-size-increase.rs:20:29 3 | | 4 | 20 | const INCREASE_SIZE: AU16 = transmute!(0u8); 5 | | ^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `u8` (8 bits) 8 | = note: target type: `AU16` (16 bits) 9 | = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/transmute-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::{NotZerocopy, AU16}; 14 | use zerocopy::transmute; 15 | 16 | fn main() {} 17 | 18 | // `transmute` requires that the source type implements `IntoBytes` 19 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); 20 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute-dst-not-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::{NotZerocopy, AU16}; 14 | use zerocopy::try_transmute; 15 | 16 | fn main() { 17 | let dst_not_try_from_bytes: Result = try_transmute!(AU16(0)); 18 | } 19 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute-size-decrease.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute; 15 | 16 | // Although this is not a soundness requirement, we currently require that the 17 | // size of the destination type is not smaller than the size of the source type. 18 | fn main() { 19 | let decrease_size: Result = try_transmute!(AU16(0)); 20 | } 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/try_transmute-size-decrease.rs:19:40 3 | | 4 | 19 | let decrease_size: Result = try_transmute!(AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute-size-increase.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute; 15 | 16 | // `try_transmute!` does not support transmuting from a smaller type to a larger 17 | // one. 18 | fn main() { 19 | let increase_size: Result = try_transmute!(0u8); 20 | } 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute-size-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/try_transmute-size-increase.rs:19:42 3 | | 4 | 19 | let increase_size: Result = try_transmute!(0u8); 5 | | ^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `u8` (8 bits) 8 | = note: target type: `AU16` (16 bits) 9 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::{NotZerocopy, AU16}; 14 | use zerocopy::try_transmute; 15 | 16 | fn main() { 17 | // `try_transmute` requires that the source type implements `IntoBytes` 18 | let src_not_into_bytes: Result = try_transmute!(NotZerocopy(AU16(0))); 19 | } 20 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute-src-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied 2 | --> tests/ui-nightly/try_transmute-src-not-intobytes.rs:18:47 3 | | 4 | 18 | let src_not_into_bytes: Result = try_transmute!(NotZerocopy(AU16(0))); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::IntoBytes`: 9 | () 10 | AU16 11 | AtomicBool 12 | AtomicI16 13 | AtomicI32 14 | AtomicI64 15 | AtomicI8 16 | AtomicIsize 17 | and $N others 18 | note: required by a bound in `try_transmute` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn try_transmute(src: Src) -> Result> 22 | | ------------- required by a bound in this function 23 | | where 24 | | Src: IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `try_transmute` 26 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-alignment-increase.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute_mut; 15 | 16 | // `try_transmute_mut!` does not support transmuting from a type of smaller 17 | // alignment to one of larger alignment. 18 | fn main() { 19 | let src = &mut [0u8; 2]; 20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); 21 | } 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-alignment-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/try_transmute_mut-alignment-increase.rs:20:47 3 | | 4 | 20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 8 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 9 | = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::{NotZerocopy, AU16}; 14 | use zerocopy::try_transmute_mut; 15 | 16 | fn main() { 17 | // `try_transmute_mut` requires that the destination type implements 18 | // `IntoBytes` 19 | let src = &mut AU16(0); 20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src); 21 | } 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-size-decrease.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute_mut; 15 | 16 | // Although this is not a soundness requirement, we currently require that the 17 | // size of the destination type is not smaller than the size of the source type. 18 | fn main() { 19 | let src = &mut AU16(0); 20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); 21 | } 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/try_transmute_mut-size-decrease.rs:20:45 3 | | 4 | 20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-size-increase.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute_mut; 15 | 16 | // `try_transmute_mut!` does not support transmuting from a smaller type to a 17 | // larger one. 18 | fn main() { 19 | let src = &mut 0u8; 20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); 21 | } 22 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-size-increase.stderr: -------------------------------------------------------------------------------- 1 | warning: unused import: `util::AU16` 2 | --> tests/ui-nightly/try_transmute_mut-size-increase.rs:13:5 3 | | 4 | 13 | use util::AU16; 5 | | ^^^^^^^^^^ 6 | | 7 | = note: `#[warn(unused_imports)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-nightly/try_transmute_mut-size-increase.rs:20:50 11 | | 12 | 20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `u8` (8 bits) 16 | = note: target type: `[u8; 2]` (16 bits) 17 | = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-src-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | #[derive(zerocopy::IntoBytes)] 14 | #[repr(C)] 15 | struct Src; 16 | 17 | #[derive(zerocopy::TryFromBytes)] 18 | #[repr(C)] 19 | struct Dst; 20 | 21 | fn main() { 22 | // `try_transmute_mut` requires that the source type implements `FromBytes` 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); 24 | } 25 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_mut-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::transmute_mut; 12 | 13 | #[derive(zerocopy::FromBytes)] 14 | #[repr(C)] 15 | struct Src; 16 | 17 | #[derive(zerocopy::TryFromBytes)] 18 | #[repr(C)] 19 | struct Dst; 20 | 21 | fn main() { 22 | // `try_transmute_mut` requires that the source type implements `IntoBytes` 23 | let src_not_from_bytes: &mut Dst = transmute_mut!(&mut Src); 24 | } 25 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-alignment-increase.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute_ref; 15 | 16 | // `try_transmute_ref!` does not support transmuting from a type of smaller 17 | // alignment to one of larger alignment. 18 | fn main() { 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 20 | } 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-alignment-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/try_transmute_ref-alignment-increase.rs:19:43 3 | | 4 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 8 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 9 | = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-dst-mutable.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | extern crate zerocopy; 10 | 11 | use zerocopy::try_transmute_ref; 12 | 13 | fn main() {} 14 | 15 | fn ref_dst_mutable() { 16 | // `try_transmute_ref!` requires that its destination type be an immutable 17 | // reference. 18 | let _: Result<&mut u8, _> = try_transmute_ref!(&0u8); 19 | } 20 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::{NotZerocopy, AU16}; 14 | use zerocopy::try_transmute_ref; 15 | 16 | fn main() { 17 | // `try_transmute_ref` requires that the source type implements `Immutable` 18 | // and `IntoBytes` 19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0)); 20 | } 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-size-decrease.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute_ref; 15 | 16 | // Although this is not a soundness requirement, we currently require that the 17 | // size of the destination type is not smaller than the size of the source type. 18 | fn main() { 19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); 20 | } 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/try_transmute_ref-size-decrease.rs:19:41 3 | | 4 | 19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-size-increase.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::AU16; 14 | use zerocopy::try_transmute_ref; 15 | 16 | // `try_transmute_ref!` does not support transmuting from a smaller type to a 17 | // larger one. 18 | fn main() { 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 20 | } 21 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-size-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-nightly/try_transmute_ref-size-increase.rs:19:43 3 | | 4 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 8 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 9 | = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | include!("../../zerocopy-derive/tests/include.rs"); 10 | 11 | extern crate zerocopy; 12 | 13 | use util::{NotZerocopy, AU16}; 14 | use zerocopy::try_transmute_ref; 15 | 16 | fn main() { 17 | // `try_transmute_ref` requires that the source type implements `Immutable` 18 | // and `IntoBytes` 19 | let src_not_into_bytes: Result<&AU16, _> = try_transmute_ref!(&NotZerocopy(AU16(0))); 20 | } 21 | -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-from-bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-from-bytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-from-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied 2 | --> tests/ui-stable/diagnostic-not-implemented-from-bytes.rs:18:24 3 | | 4 | 18 | takes_from_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::FromBytes`: 9 | () 10 | AU16 11 | AtomicI16 12 | AtomicI32 13 | AtomicI64 14 | AtomicI8 15 | AtomicIsize 16 | AtomicU16 17 | and $N others 18 | note: required by a bound in `takes_from_bytes` 19 | --> tests/ui-stable/diagnostic-not-implemented-from-bytes.rs:21:24 20 | | 21 | 21 | fn takes_from_bytes() {} 22 | | ^^^^^^^^^ required by this bound in `takes_from_bytes` 23 | -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-from-zeros.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-from-zeros.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-from-zeros.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied 2 | --> tests/ui-stable/diagnostic-not-implemented-from-zeros.rs:18:24 3 | | 4 | 18 | takes_from_zeros::(); 5 | | ^^^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy` 8 | = help: the following other types implement trait `FromZeros`: 9 | () 10 | *const T 11 | *mut T 12 | AU16 13 | AtomicBool 14 | AtomicI16 15 | AtomicI32 16 | AtomicI64 17 | and $N others 18 | note: required by a bound in `takes_from_zeros` 19 | --> tests/ui-stable/diagnostic-not-implemented-from-zeros.rs:21:24 20 | | 21 | 21 | fn takes_from_zeros() {} 22 | | ^^^^^^^^^ required by this bound in `takes_from_zeros` 23 | -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-immutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-immutable.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-immutable.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied 2 | --> tests/ui-stable/diagnostic-not-implemented-immutable.rs:18:23 3 | | 4 | 18 | takes_immutable::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(Immutable)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::Immutable`: 9 | &T 10 | &mut T 11 | () 12 | *const T 13 | *mut T 14 | AU16 15 | Box 16 | F32 17 | and $N others 18 | note: required by a bound in `takes_immutable` 19 | --> tests/ui-stable/diagnostic-not-implemented-immutable.rs:21:23 20 | | 21 | 21 | fn takes_immutable() {} 22 | | ^^^^^^^^^ required by this bound in `takes_immutable` 23 | -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-into-bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-into-bytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-into-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied 2 | --> tests/ui-stable/diagnostic-not-implemented-into-bytes.rs:18:24 3 | | 4 | 18 | takes_into_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::IntoBytes`: 9 | () 10 | AU16 11 | AtomicBool 12 | AtomicI16 13 | AtomicI32 14 | AtomicI64 15 | AtomicI8 16 | AtomicIsize 17 | and $N others 18 | note: required by a bound in `takes_into_bytes` 19 | --> tests/ui-stable/diagnostic-not-implemented-into-bytes.rs:21:24 20 | | 21 | 21 | fn takes_into_bytes() {} 22 | | ^^^^^^^^^ required by this bound in `takes_into_bytes` 23 | -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-issue-1296.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-issue-1296.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-known-layout.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-known-layout.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-known-layout.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::KnownLayout` is not satisfied 2 | --> tests/ui-stable/diagnostic-not-implemented-known-layout.rs:18:26 3 | | 4 | 18 | takes_known_layout::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::KnownLayout` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(KnownLayout)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::KnownLayout`: 9 | &T 10 | &mut T 11 | () 12 | *const T 13 | *mut T 14 | AU16 15 | AtomicBool 16 | AtomicI16 17 | and $N others 18 | note: required by a bound in `takes_known_layout` 19 | --> tests/ui-stable/diagnostic-not-implemented-known-layout.rs:21:26 20 | | 21 | 21 | fn takes_known_layout() {} 22 | | ^^^^^^^^^^^ required by this bound in `takes_known_layout` 23 | -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-try-from-bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-try-from-bytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-try-from-bytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied 2 | --> tests/ui-stable/diagnostic-not-implemented-try-from-bytes.rs:18:28 3 | | 4 | 18 | takes_try_from_bytes::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::TryFromBytes`: 9 | () 10 | *const T 11 | *mut T 12 | AU16 13 | AtomicBool 14 | AtomicI16 15 | AtomicI32 16 | AtomicI64 17 | and $N others 18 | note: required by a bound in `takes_try_from_bytes` 19 | --> tests/ui-stable/diagnostic-not-implemented-try-from-bytes.rs:21:28 20 | | 21 | 21 | fn takes_try_from_bytes() {} 22 | | ^^^^^^^^^^^^ required by this bound in `takes_try_from_bytes` 23 | -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-unaligned.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/diagnostic-not-implemented-unaligned.rs -------------------------------------------------------------------------------- /tests/ui-stable/diagnostic-not-implemented-unaligned.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::Unaligned` is not satisfied 2 | --> tests/ui-stable/diagnostic-not-implemented-unaligned.rs:18:23 3 | | 4 | 18 | takes_unaligned::(); 5 | | ^^^^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(Unaligned)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::Unaligned`: 9 | () 10 | AtomicBool 11 | AtomicI8 12 | AtomicU8 13 | Cell 14 | F32 15 | F64 16 | I128 17 | and $N others 18 | note: required by a bound in `takes_unaligned` 19 | --> tests/ui-stable/diagnostic-not-implemented-unaligned.rs:21:23 20 | | 21 | 21 | fn takes_unaligned() {} 22 | | ^^^^^^^^^ required by this bound in `takes_unaligned` 23 | -------------------------------------------------------------------------------- /tests/ui-stable/include_value_not_from_bytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/include_value_not_from_bytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/include_value_wrong_size.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/include_value_wrong_size.rs -------------------------------------------------------------------------------- /tests/ui-stable/include_value_wrong_size.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/include_value_wrong_size.rs:15:25 3 | | 4 | 15 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data"); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `[u8; 4]` (32 bits) 8 | = note: target type: `u64` (64 bits) 9 | = note: this error originates in the macro `$crate::transmute` which comes from the expansion of the macro `include_value` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/invalid-impls/invalid-impls.rs: -------------------------------------------------------------------------------- 1 | ../../ui-nightly/invalid-impls/invalid-impls.rs -------------------------------------------------------------------------------- /tests/ui-stable/max-align.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/max-align.rs -------------------------------------------------------------------------------- /tests/ui-stable/max-align.stderr: -------------------------------------------------------------------------------- 1 | error[E0589]: invalid `repr(align)` attribute: larger than 2^29 2 | --> tests/ui-stable/max-align.rs:96:17 3 | | 4 | 96 | #[repr(C, align(1073741824))] 5 | | ^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /tests/ui-stable/ptr-is-invariant-over-v.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/ptr-is-invariant-over-v.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-dst-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-const.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-const.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-const.stderr: -------------------------------------------------------------------------------- 1 | warning: taking a mutable reference to a `const` item 2 | --> tests/ui-stable/transmute-mut-const.rs:20:52 3 | | 4 | 20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); 5 | | ^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: each usage of a `const` item creates a new temporary 8 | = note: the mutable reference will refer to this temporary, not the original `const` item 9 | note: `const` item defined here 10 | --> tests/ui-stable/transmute-mut-const.rs:17:1 11 | | 12 | 17 | const ARRAY_OF_U8S: [u8; 2] = [0u8; 2]; 13 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14 | = note: `#[warn(const_item_mutation)]` on by default 15 | 16 | error[E0015]: cannot call non-const method `Wrap::<&mut [u8; 2], &mut [u8; 2]>::transmute_mut` in constants 17 | --> tests/ui-stable/transmute-mut-const.rs:20:37 18 | | 19 | 20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S); 20 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21 | | 22 | = note: calls in constants are limited to constant functions, tuple structs and tuple variants 23 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 24 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36 3 | | 4 | 17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _` 6 | | 7 | = note: expected type `usize` 8 | found mutable reference `&mut _` 9 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: FromBytes` is not satisfied 2 | --> tests/ui-stable/transmute-mut-dst-not-frombytes.rs:24:38 3 | | 4 | 24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst` 6 | | 7 | = note: Consider adding `#[derive(FromBytes)]` to `Dst` 8 | = help: the following other types implement trait `FromBytes`: 9 | () 10 | AtomicI16 11 | AtomicI32 12 | AtomicI64 13 | AtomicI8 14 | AtomicIsize 15 | AtomicU16 16 | AtomicU32 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | ... 24 | | Dst: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied 2 | --> tests/ui-stable/transmute-mut-dst-not-intobytes.rs:24:36 3 | | 4 | 24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `Dst` 8 | = help: the following other types implement trait `IntoBytes`: 9 | () 10 | AtomicBool 11 | AtomicI16 12 | AtomicI32 13 | AtomicI64 14 | AtomicI8 15 | AtomicIsize 16 | AtomicU16 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | ... 24 | | Dst: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-dst-unsized.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-dst-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time 2 | --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32 3 | | 4 | 17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 6 | | 7 | = help: the trait `Sized` is not implemented for `[u8]` 8 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 9 | --> src/util/macro_util.rs 10 | | 11 | | impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst> { 12 | | ^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 13 | ... 14 | | pub fn transmute_mut(self) -> &'a mut Dst 15 | | ------------- required by a bound in this associated function 16 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 17 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-illegal-lifetime.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-illegal-lifetime.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-illegal-lifetime.stderr: -------------------------------------------------------------------------------- 1 | error[E0597]: `x` does not live long enough 2 | --> tests/ui-stable/transmute-mut-illegal-lifetime.rs:14:56 3 | | 4 | 12 | let mut x = 0u64; 5 | | ----- binding `x` declared here 6 | 13 | // It is illegal to increase the lifetime scope. 7 | 14 | let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x); 8 | | ---------------- ^^^^^^ borrowed value does not live long enough 9 | | | 10 | | type annotation requires that `x` is borrowed for `'static` 11 | 15 | } 12 | | - `x` dropped here while still borrowed 13 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-dst-not-references.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-dst-not-references.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-dst-not-references.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-stable/transmute-mut-src-dst-not-references.rs:17:59 3 | | 4 | 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&mut _`, found `usize` 8 | | expected due to this 9 | | 10 | = note: expected mutable reference `&mut _` 11 | found type `usize` 12 | help: consider mutably borrowing here 13 | | 14 | 17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(&mut 0usize); 15 | | ++++ 16 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-immutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-immutable.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-immutable.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-stable/transmute-mut-src-immutable.rs:17:37 3 | | 4 | 17 | let _: &mut u8 = transmute_mut!(&0u8); 5 | | ---------------^^^^- 6 | | | | 7 | | | types differ in mutability 8 | | expected due to this 9 | | 10 | = note: expected mutable reference `&mut _` 11 | found reference `&u8` 12 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-stable/transmute-mut-src-not-a-reference.rs:17:53 3 | | 4 | 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&mut _`, found `usize` 8 | | expected due to this 9 | | 10 | = note: expected mutable reference `&mut _` 11 | found type `usize` 12 | help: consider mutably borrowing here 13 | | 14 | 17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(&mut 0usize); 15 | | ++++ 16 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-not-frombytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Src: FromBytes` is not satisfied 2 | --> tests/ui-stable/transmute-mut-src-not-frombytes.rs:24:38 3 | | 4 | 24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src` 6 | | 7 | = note: Consider adding `#[derive(FromBytes)]` to `Src` 8 | = help: the following other types implement trait `FromBytes`: 9 | () 10 | AtomicI16 11 | AtomicI32 12 | AtomicI64 13 | AtomicI8 14 | AtomicIsize 15 | AtomicU16 16 | AtomicU32 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | | where 24 | | Src: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Src: IntoBytes` is not satisfied 2 | --> tests/ui-stable/transmute-mut-src-not-intobytes.rs:24:36 3 | | 4 | 24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `Src` 8 | = help: the following other types implement trait `IntoBytes`: 9 | () 10 | AtomicBool 11 | AtomicI16 12 | AtomicI32 13 | AtomicI64 14 | AtomicI8 15 | AtomicIsize 16 | AtomicU16 17 | and $N others 18 | note: required by a bound in `Wrap::<&'a mut Src, &'a mut Dst>::transmute_mut` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn transmute_mut(self) -> &'a mut Dst 22 | | ------------- required by a bound in this associated function 23 | | where 24 | | Src: FromBytes + IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `Wrap::<&mut Src, &mut Dst>::transmute_mut` 26 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-mut-src-unsized.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-mut-src-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` 2 | --> tests/ui-stable/transmute-mut-src-unsized.rs:17:35 3 | | 4 | 17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` 6 | | 7 | = note: required for `Wrap<&mut [u8], &mut [u8; 1]>` to implement `TransmuteMutDst<'_>` 8 | = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ptr-to-usize.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ptr-to-usize.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-dst-mutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-mutable.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-dst-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-dst-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-dst-not-nocell.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-not-nocell.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-dst-not-nocell.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `Dst: zerocopy::Immutable` is not satisfied 2 | --> tests/ui-stable/transmute-ref-dst-not-nocell.rs:23:33 3 | | 4 | 23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | | 7 | | the trait `zerocopy::Immutable` is not implemented for `Dst` 8 | | required by a bound introduced by this call 9 | | 10 | = note: Consider adding `#[derive(Immutable)]` to `Dst` 11 | = help: the following other types implement trait `zerocopy::Immutable`: 12 | &T 13 | &mut T 14 | () 15 | *const T 16 | *mut T 17 | AU16 18 | Box 19 | F32 20 | and $N others 21 | note: required by a bound in `AssertDstIsImmutable` 22 | --> tests/ui-stable/transmute-ref-dst-not-nocell.rs:23:33 23 | | 24 | 23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0)); 25 | | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsImmutable` 26 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-dst-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-dst-unsized.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-dst-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time 2 | --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28 3 | | 4 | 17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 6 | | 7 | = help: the trait `Sized` is not implemented for `[u8]` 8 | note: required by a bound in `Wrap::<&'a Src, &'a Dst>::transmute_ref` 9 | --> src/util/macro_util.rs 10 | | 11 | | impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst> { 12 | | ^^^ required by this bound in `Wrap::<&Src, &Dst>::transmute_ref` 13 | ... 14 | | pub const unsafe fn transmute_ref(self) -> &'a Dst { 15 | | ------------- required by a bound in this associated function 16 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 17 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-illegal-lifetime.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-illegal-lifetime.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-illegal-lifetime.stderr: -------------------------------------------------------------------------------- 1 | error[E0597]: `x` does not live long enough 2 | --> tests/ui-stable/transmute-ref-illegal-lifetime.rs:14:52 3 | | 4 | 12 | let x = 0u64; 5 | | - binding `x` declared here 6 | 13 | // It is illegal to increase the lifetime scope. 7 | 14 | let _: &'static u64 = zerocopy::transmute_ref!(&x); 8 | | ------------ ^^ borrowed value does not live long enough 9 | | | 10 | | type annotation requires that `x` is borrowed for `'static` 11 | 15 | } 12 | | - `x` dropped here while still borrowed 13 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-src-dst-not-references.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-dst-not-references.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-src-not-a-reference.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-not-a-reference.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-src-not-a-reference.stderr: -------------------------------------------------------------------------------- 1 | error[E0308]: mismatched types 2 | --> tests/ui-stable/transmute-ref-src-not-a-reference.rs:17:49 3 | | 4 | 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize); 5 | | ---------------^^^^^^- 6 | | | | 7 | | | expected `&_`, found `usize` 8 | | expected due to this 9 | | 10 | = note: expected reference `&_` 11 | found type `usize` 12 | help: consider borrowing here 13 | | 14 | 17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(&0usize); 15 | | + 16 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-src-not-nocell.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-not-nocell.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-src-unsized.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-ref-src-unsized.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-ref-src-unsized.stderr: -------------------------------------------------------------------------------- 1 | error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize` 2 | --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31 3 | | 4 | 16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `()` 6 | | 7 | = note: required for `Wrap<&[u8], &[u8; 1]>` to implement `TransmuteRefDst<'_>` 8 | = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/transmute-size-decrease.rs:20:27 3 | | 4 | 20 | const DECREASE_SIZE: u8 = transmute!(AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-stable/transmute-size-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/transmute-size-increase.rs:20:29 3 | | 4 | 20 | const INCREASE_SIZE: AU16 = transmute!(0u8); 5 | | ^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `u8` (8 bits) 8 | = note: target type: `AU16` (16 bits) 9 | = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/transmute-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/transmute-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute-dst-not-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-dst-not-tryfrombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/try_transmute-size-decrease.rs:19:40 3 | | 4 | 19 | let decrease_size: Result = try_transmute!(AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute-size-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/try_transmute-size-increase.rs:19:42 3 | | 4 | 19 | let increase_size: Result = try_transmute!(0u8); 5 | | ^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `u8` (8 bits) 8 | = note: target type: `AU16` (16 bits) 9 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute-src-not-intobytes.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied 2 | --> tests/ui-stable/try_transmute-src-not-intobytes.rs:18:47 3 | | 4 | 18 | let src_not_into_bytes: Result = try_transmute!(NotZerocopy(AU16(0))); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy` 6 | | 7 | = note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy` 8 | = help: the following other types implement trait `zerocopy::IntoBytes`: 9 | () 10 | AU16 11 | AtomicBool 12 | AtomicI16 13 | AtomicI32 14 | AtomicI64 15 | AtomicI8 16 | AtomicIsize 17 | and $N others 18 | note: required by a bound in `try_transmute` 19 | --> src/util/macro_util.rs 20 | | 21 | | pub fn try_transmute(src: Src) -> Result> 22 | | ------------- required by a bound in this function 23 | | where 24 | | Src: IntoBytes, 25 | | ^^^^^^^^^ required by this bound in `try_transmute` 26 | = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) 27 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-alignment-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-alignment-increase.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-alignment-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/try_transmute_mut-alignment-increase.rs:20:47 3 | | 4 | 20 | let increase_size: Result<&mut AU16, _> = try_transmute_mut!(src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 8 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 9 | = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/try_transmute_mut-size-decrease.rs:20:45 3 | | 4 | 20 | let decrease_size: Result<&mut u8, _> = try_transmute_mut!(src); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-size-increase.stderr: -------------------------------------------------------------------------------- 1 | warning: unused import: `util::AU16` 2 | --> tests/ui-stable/try_transmute_mut-size-increase.rs:13:5 3 | | 4 | 13 | use util::AU16; 5 | | ^^^^^^^^^^ 6 | | 7 | = note: `#[warn(unused_imports)]` on by default 8 | 9 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 10 | --> tests/ui-stable/try_transmute_mut-size-increase.rs:20:50 11 | | 12 | 20 | let increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^ 14 | | 15 | = note: source type: `u8` (8 bits) 16 | = note: target type: `[u8; 2]` (16 bits) 17 | = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) 18 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-src-not-frombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-src-not-frombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_mut-src-not-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_mut-src-not-intobytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-alignment-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-alignment-increase.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-alignment-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/try_transmute_ref-alignment-increase.rs:19:43 3 | | 4 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 8 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 9 | = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-dst-mutable.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-dst-mutable.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-size-decrease.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-size-decrease.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-size-decrease.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/try_transmute_ref-size-decrease.rs:19:41 3 | | 4 | 19 | let decrease_size: Result<&u8, _> = try_transmute_ref!(&AU16(0)); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AU16` (16 bits) 8 | = note: target type: `u8` (8 bits) 9 | = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-size-increase.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-size-increase.rs -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-size-increase.stderr: -------------------------------------------------------------------------------- 1 | error[E0512]: cannot transmute between types of different sizes, or dependently-sized types 2 | --> tests/ui-stable/try_transmute_ref-size-increase.rs:19:43 3 | | 4 | 19 | let increase_size: Result<&AU16, _> = try_transmute_ref!(&[0u8; 2]); 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | | 7 | = note: source type: `AlignOf<[u8; 2]>` (8 bits) 8 | = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits) 9 | = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) 10 | -------------------------------------------------------------------------------- /tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/try_transmute_ref-src-not-immutable-intobytes.rs -------------------------------------------------------------------------------- /tools/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | [workspace] 10 | members = [ 11 | "cargo-zerocopy", 12 | "generate-readme", 13 | ] 14 | resolver = "2" 15 | 16 | [workspace.package] 17 | edition = "2021" 18 | version = "0.0.0" 19 | authors = ["Joshua Liebow-Feeser "] 20 | license = "BSD-2-Clause OR Apache-2.0 OR MIT" 21 | publish = false 22 | 23 | [workspace.dependencies] 24 | regex = "1" 25 | toml = "0.8" 26 | -------------------------------------------------------------------------------- /tools/cargo-zerocopy/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | [package] 10 | edition.workspace = true 11 | name = "cargo-zerocopy" 12 | version.workspace = true 13 | authors.workspace = true 14 | license.workspace = true 15 | publish.workspace = true 16 | 17 | [dependencies] 18 | toml = { workspace = true, features = ["parse"] } 19 | -------------------------------------------------------------------------------- /tools/generate-readme/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Fuchsia Authors 2 | # 3 | # Licensed under a BSD-style license , Apache License, Version 2.0 4 | # , or the MIT 5 | # license , at your option. 6 | # This file may not be copied, modified, or distributed except according to 7 | # those terms. 8 | 9 | [package] 10 | edition.workspace = true 11 | name = "generate-readme" 12 | version.workspace = true 13 | authors.workspace = true 14 | license.workspace = true 15 | publish.workspace = true 16 | 17 | [dependencies] 18 | regex.workspace = true 19 | -------------------------------------------------------------------------------- /tools/update-ui-test-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2024 The Fuchsia Authors 4 | # 5 | # Licensed under a BSD-style license , Apache License, Version 2.0 6 | # , or the MIT 7 | # license , at your option. 8 | # This file may not be copied, modified, or distributed except according to 9 | # those terms. 10 | 11 | # Update the `.stderr` reference files used to validate our UI tests. 12 | 13 | set -e 14 | 15 | TRYBUILD=overwrite ./cargo.sh +nightly test ui --test trybuild -p zerocopy --all-features 16 | TRYBUILD=overwrite ./cargo.sh +stable test ui --test trybuild -p zerocopy --features=__internal_use_only_features_that_work_on_stable 17 | TRYBUILD=overwrite ./cargo.sh +msrv test ui --test trybuild -p zerocopy --features=__internal_use_only_features_that_work_on_stable 18 | 19 | TRYBUILD=overwrite ./cargo.sh +all test ui --test trybuild -p zerocopy-derive 20 | -------------------------------------------------------------------------------- /win-cargo.bat: -------------------------------------------------------------------------------- 1 | @rem Copyright 2024 The Fuchsia Authors 2 | 3 | @rem Licensed under a BSD-style license , Apache License, Version 2.0 4 | @rem , or the MIT 5 | @rem license , at your option. 6 | @rem This file may not be copied, modified, or distributed except according to 7 | @rem those terms. 8 | 9 | @rem Build `cargo-zerocopy` without any RUSTFLAGS set in the environment 10 | @set TEMP_RUSTFLAGS=%RUSTFLAGS% 11 | @set RUSTFLAGS= 12 | @cargo +stable build --manifest-path tools/Cargo.toml -p cargo-zerocopy -q 13 | @set RUSTFLAGS=%TEMP_RUSTFLAGS% 14 | @set TEMP_RUSTFLAGS= 15 | @rem Thin wrapper around the `cargo-zerocopy` binary in `tools/cargo-zerocopy` 16 | @tools\target\debug\cargo-zerocopy %* 17 | -------------------------------------------------------------------------------- /zerocopy-derive/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /zerocopy-derive/LICENSE-BSD: -------------------------------------------------------------------------------- 1 | ../LICENSE-BSD -------------------------------------------------------------------------------- /zerocopy-derive/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /zerocopy-derive/tests/enum_unaligned.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // See comment in `include.rs` for why we disable the prelude. 10 | #![no_implicit_prelude] 11 | #![allow(warnings)] 12 | 13 | include!("include.rs"); 14 | 15 | // An enum is `Unaligned` if: 16 | // - No `repr(align(N > 1))` 17 | // - `repr(u8)` or `repr(i8)` 18 | 19 | #[derive(imp::Unaligned)] 20 | #[repr(u8)] 21 | enum Foo { 22 | A, 23 | } 24 | 25 | util_assert_impl_all!(Foo: imp::Unaligned); 26 | 27 | #[derive(imp::Unaligned)] 28 | #[repr(i8)] 29 | enum Bar { 30 | A, 31 | } 32 | 33 | util_assert_impl_all!(Bar: imp::Unaligned); 34 | 35 | #[derive(imp::Unaligned)] 36 | #[repr(u8, align(1))] 37 | enum Baz { 38 | A, 39 | } 40 | 41 | util_assert_impl_all!(Baz: imp::Unaligned); 42 | 43 | #[derive(imp::Unaligned)] 44 | #[repr(i8, align(1))] 45 | enum Blah { 46 | B, 47 | } 48 | 49 | util_assert_impl_all!(Blah: imp::Unaligned); 50 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/eq.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // See comment in `include.rs` for why we disable the prelude. 10 | #![no_implicit_prelude] 11 | #![allow(warnings)] 12 | 13 | include!("include.rs"); 14 | 15 | #[derive(imp::Debug, imp::IntoBytes, imp::Immutable, imp::ByteEq)] 16 | #[repr(C)] 17 | struct Struct { 18 | a: u64, 19 | b: u32, 20 | c: u32, 21 | } 22 | 23 | util_assert_impl_all!(Struct: imp::IntoBytes, imp::PartialEq, imp::Eq); 24 | 25 | #[test] 26 | fn test_eq() { 27 | use imp::{assert_eq, assert_ne}; 28 | let a = Struct { a: 10, b: 15, c: 20 }; 29 | let b = Struct { a: 10, b: 15, c: 25 }; 30 | assert_eq!(a, a); 31 | assert_ne!(a, b); 32 | assert_ne!(b, a); 33 | } 34 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/hash.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // See comment in `include.rs` for why we disable the prelude. 10 | #![no_implicit_prelude] 11 | #![allow(warnings)] 12 | 13 | include!("include.rs"); 14 | 15 | #[derive(imp::IntoBytes, imp::Immutable, imp::ByteHash)] 16 | #[repr(C)] 17 | struct Struct { 18 | a: u64, 19 | b: u32, 20 | c: u32, 21 | } 22 | 23 | util_assert_impl_all!(Struct: imp::IntoBytes, imp::hash::Hash); 24 | 25 | #[test] 26 | fn test_hash() { 27 | use imp::{ 28 | hash::{Hash, Hasher}, 29 | DefaultHasher, 30 | }; 31 | fn hash(val: impl Hash) -> u64 { 32 | let mut hasher = DefaultHasher::new(); 33 | val.hash(&mut hasher); 34 | hasher.finish() 35 | } 36 | hash(Struct { a: 10, b: 15, c: 20 }); 37 | hash(&[Struct { a: 10, b: 15, c: 20 }, Struct { a: 5, b: 4, c: 3 }]); 38 | } 39 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/issue_2117.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // See comment in `include.rs` for why we disable the prelude. 10 | #![no_implicit_prelude] 11 | #![allow(warnings)] 12 | #![forbid(unexpected_cfgs)] 13 | 14 | include!("include.rs"); 15 | 16 | // Make sure no unexpected `cfg`s are emitted by our derives (see #2117). 17 | 18 | #[derive(imp::KnownLayout)] 19 | #[repr(C)] 20 | pub struct Test(pub [u8; 32]); 21 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/paths_and_modules.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // See comment in `include.rs` for why we disable the prelude. 10 | #![no_implicit_prelude] 11 | #![allow(warnings)] 12 | 13 | include!("include.rs"); 14 | 15 | // Ensure that types that are use'd and types that are referenced by path work. 16 | 17 | mod foo { 18 | use super::*; 19 | 20 | #[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)] 21 | #[repr(C)] 22 | pub struct Foo { 23 | foo: u8, 24 | } 25 | 26 | #[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)] 27 | #[repr(C)] 28 | pub struct Bar { 29 | bar: u8, 30 | } 31 | } 32 | 33 | use foo::Foo; 34 | 35 | #[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)] 36 | #[repr(C)] 37 | struct Baz { 38 | foo: Foo, 39 | bar: foo::Bar, 40 | } 41 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/priv_in_pub.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // See comment in `include.rs` for why we disable the prelude. 10 | #![no_implicit_prelude] 11 | #![allow(warnings)] 12 | 13 | include!("include.rs"); 14 | 15 | // FIXME(#847): Make this test succeed on earlier Rust versions. 16 | #[::rustversion::stable(1.59)] 17 | mod test { 18 | use super::*; 19 | 20 | // These derives do not result in E0446 as of Rust 1.59.0, because of 21 | // https://github.com/rust-lang/rust/pull/90586. 22 | // 23 | // This change eliminates one of the major downsides of emitting `where` 24 | // bounds for field types (i.e., the emission of E0446 for private field 25 | // types). 26 | 27 | #[derive(imp::KnownLayout, imp::IntoBytes, imp::FromZeros, imp::FromBytes, imp::Unaligned)] 28 | #[repr(C)] 29 | pub struct Public(Private); 30 | 31 | #[derive(imp::KnownLayout, imp::IntoBytes, imp::FromZeros, imp::FromBytes, imp::Unaligned)] 32 | #[repr(C)] 33 | struct Private(()); 34 | } 35 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/derive_transparent.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/derive_transparent.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/enum.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/enum.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/enum_from_bytes_u8_too_few.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/enum_from_bytes_u8_too_few.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/enum_from_bytes_u8_too_few.stderr: -------------------------------------------------------------------------------- 1 | error: FromBytes only supported on repr(u8) enum with 256 variants 2 | --> tests/ui-msrv/enum_from_bytes_u8_too_few.rs:15:1 3 | | 4 | 15 | / #[repr(u8)] 5 | 16 | | enum Foo { 6 | 17 | | Variant0, 7 | 18 | | Variant1, 8 | ... | 9 | 271 | | Variant254, 10 | 272 | | } 11 | | |_^ 12 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/late_compile_pass.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/late_compile_pass.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/mid_compile_pass.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/mid_compile_pass.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/msrv_specific.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // This file contains tests which trigger errors on MSRV during a different 10 | // compiler pass compared to the stable or nightly toolchains. 11 | 12 | #[macro_use] 13 | extern crate zerocopy; 14 | 15 | #[path = "../include.rs"] 16 | mod util; 17 | 18 | use self::util::util::AU16; 19 | use zerocopy::IntoBytes; 20 | 21 | fn main() {} 22 | 23 | // `repr(C, packed(2))` is not equivalent to `repr(C, packed)`. 24 | #[derive(IntoBytes)] 25 | #[repr(C, packed(2))] 26 | struct IntoBytes1 { 27 | t0: T, 28 | // Add a second field to avoid triggering the "repr(C) struct with one 29 | // field" special case. 30 | t1: T, 31 | } 32 | 33 | fn is_into_bytes_1() { 34 | if false { 35 | is_into_bytes_1::>(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/msrv_specific.stderr: -------------------------------------------------------------------------------- 1 | warning: unused `#[macro_use]` import 2 | --> tests/ui-msrv/msrv_specific.rs:12:1 3 | | 4 | 12 | #[macro_use] 5 | | ^^^^^^^^^^^^ 6 | | 7 | = note: `#[warn(unused_imports)]` on by default 8 | 9 | error[E0277]: the trait bound `AU16: zerocopy::Unaligned` is not satisfied 10 | --> tests/ui-msrv/msrv_specific.rs:35:9 11 | | 12 | 35 | is_into_bytes_1::>(); 13 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `AU16` 14 | | 15 | note: required because of the requirements on the impl of `zerocopy::IntoBytes` for `IntoBytes1` 16 | --> tests/ui-msrv/msrv_specific.rs:24:10 17 | | 18 | 24 | #[derive(IntoBytes)] 19 | | ^^^^^^^^^ 20 | note: required by a bound in `is_into_bytes_1` 21 | --> tests/ui-msrv/msrv_specific.rs:33:23 22 | | 23 | 33 | fn is_into_bytes_1() { 24 | | ^^^^^^^^^ required by this bound in `is_into_bytes_1` 25 | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) 26 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/struct.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/struct.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/union.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/union.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.rs: -------------------------------------------------------------------------------- 1 | ../../ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.stderr: -------------------------------------------------------------------------------- 1 | error: requires --cfg zerocopy_derive_union_into_bytes; 2 | please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802 3 | --> tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.rs:20:10 4 | | 5 | 20 | #[derive(IntoBytes)] 6 | | ^^^^^^^^^ 7 | | 8 | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) 9 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | //! See: https://github.com/google/zerocopy/issues/553 10 | //! zerocopy must still allow derives of deprecated types. 11 | //! This test has a hand-written impl of a deprecated type, and should result in a compilation 12 | //! error. If zerocopy does not tack an allow(deprecated) annotation onto its impls, then this 13 | //! test will fail because more than one compile error will be generated. 14 | #![deny(deprecated)] 15 | 16 | extern crate zerocopy; 17 | 18 | use zerocopy::IntoBytes; 19 | 20 | #[deprecated = "Do not use"] 21 | #[derive(IntoBytes)] 22 | #[repr(C)] 23 | struct OldHeader { 24 | field_a: usize, 25 | collection: [u8; 8], 26 | } 27 | 28 | trait T {} 29 | 30 | // Intentionally trigger a deprecation error 31 | impl T for OldHeader {} 32 | 33 | fn main() {} 34 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.stderr: -------------------------------------------------------------------------------- 1 | error: use of deprecated struct `OldHeader`: Do not use 2 | --> tests/ui-nightly/absence_of_deprecated_warning.rs:31:12 3 | | 4 | 31 | impl T for OldHeader {} 5 | | ^^^^^^^^^ 6 | | 7 | note: the lint level is defined here 8 | --> tests/ui-nightly/absence_of_deprecated_warning.rs:14:9 9 | | 10 | 14 | #![deny(deprecated)] 11 | | ^^^^^^^^^^ 12 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-nightly/enum_from_bytes_u8_too_few.stderr: -------------------------------------------------------------------------------- 1 | error: FromBytes only supported on repr(u8) enum with 256 variants 2 | --> tests/ui-nightly/enum_from_bytes_u8_too_few.rs:15:1 3 | | 4 | 15 | / #[repr(u8)] 5 | 16 | | enum Foo { 6 | 17 | | Variant0, 7 | 18 | | Variant1, 8 | ... | 9 | 271 | | Variant254, 10 | 272 | | } 11 | | |_^ 12 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | //! See: https://github.com/google/zerocopy/issues/553 10 | //! zerocopy must still allow derives of deprecated types. 11 | //! This test has a hand-written impl of a deprecated type, and should result in a compilation 12 | //! error. If zerocopy does not tack an allow(deprecated) annotation onto its impls, then this 13 | //! test will fail because more than one compile error will be generated. 14 | #![deny(deprecated)] 15 | 16 | extern crate zerocopy; 17 | 18 | use zerocopy::IntoBytes; 19 | 20 | #[derive(IntoBytes)] 21 | #[repr(C)] 22 | union Foo { 23 | a: u8, 24 | } 25 | 26 | fn main() {} 27 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/derive_transparent.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/derive_transparent.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/enum.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/enum.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/enum_from_bytes_u8_too_few.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/enum_from_bytes_u8_too_few.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/enum_from_bytes_u8_too_few.stderr: -------------------------------------------------------------------------------- 1 | error: FromBytes only supported on repr(u8) enum with 256 variants 2 | --> tests/ui-stable/enum_from_bytes_u8_too_few.rs:15:1 3 | | 4 | 15 | / #[repr(u8)] 5 | 16 | | enum Foo { 6 | 17 | | Variant0, 7 | 18 | | Variant1, 8 | ... | 9 | 271 | | Variant254, 10 | 272 | | } 11 | | |_^ 12 | -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/late_compile_pass.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/late_compile_pass.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/mid_compile_pass.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/mid_compile_pass.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/struct.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/struct.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/union.rs: -------------------------------------------------------------------------------- 1 | ../ui-nightly/union.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.rs: -------------------------------------------------------------------------------- 1 | ../../ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs -------------------------------------------------------------------------------- /zerocopy-derive/tests/unsafe_cell.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2025 The Fuchsia Authors 2 | // 3 | // Licensed under a BSD-style license , Apache License, Version 2.0 4 | // , or the MIT 5 | // license , at your option. 6 | // This file may not be copied, modified, or distributed except according to 7 | // those terms. 8 | 9 | // See comment in `include.rs` for why we disable the prelude. 10 | #![no_implicit_prelude] 11 | #![allow(warnings)] 12 | 13 | include!("include.rs"); 14 | 15 | // Test to make sure that all of our derives are compatible with `UnsafeCell`s. 16 | // 17 | // We test both `FromBytes` and `FromZeros`, as the `FromBytes` implied derive 18 | // of `TryFromBytes` emits a trivial `is_bit_valid` impl - we want to test the 19 | // non-trivial impl, which deriving `FromZeros` accomplishes. 20 | 21 | #[derive(imp::FromBytes, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)] 22 | #[repr(C)] 23 | struct StructFromBytes(imp::UnsafeCell); 24 | 25 | #[derive(imp::FromZeros, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)] 26 | #[repr(C)] 27 | struct StructFromZeros(imp::UnsafeCell); 28 | 29 | #[derive(imp::FromZeros, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)] 30 | #[repr(u8)] 31 | enum EnumFromZeros { 32 | A(imp::UnsafeCell), 33 | } 34 | --------------------------------------------------------------------------------