aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/trybuild.rs48
-rw-r--r--tests/ui-msrv/include_value_not_from_bytes.rs12
-rw-r--r--tests/ui-msrv/include_value_not_from_bytes.stderr12
-rw-r--r--tests/ui-msrv/include_value_wrong_size.rs (renamed from tests/ui-msrv/transmute-illegal.rs)5
-rw-r--r--tests/ui-msrv/include_value_wrong_size.stderr9
-rw-r--r--tests/ui-msrv/invalid-impls/invalid-impls.rs10
-rw-r--r--tests/ui-msrv/invalid-impls/invalid-impls.stderr72
-rw-r--r--tests/ui-msrv/max-align.rs99
-rw-r--r--tests/ui-msrv/max-align.stderr5
-rw-r--r--tests/ui-msrv/transmute-dst-not-frombytes.rs18
-rw-r--r--tests/ui-msrv/transmute-dst-not-frombytes.stderr12
-rw-r--r--tests/ui-msrv/transmute-illegal.stderr18
-rw-r--r--tests/ui-msrv/transmute-mut-alignment-increase.rs19
-rw-r--r--tests/ui-msrv/transmute-mut-alignment-increase.stderr36
-rw-r--r--tests/ui-msrv/transmute-mut-const.rs20
-rw-r--r--tests/ui-msrv/transmute-mut-const.stderr41
-rw-r--r--tests/ui-msrv/transmute-mut-dst-generic.rs18
-rw-r--r--tests/ui-msrv/transmute-mut-dst-generic.stderr19
-rw-r--r--tests/ui-msrv/transmute-mut-dst-not-a-reference.rs17
-rw-r--r--tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr39
-rw-r--r--tests/ui-msrv/transmute-mut-dst-not-asbytes.rs24
-rw-r--r--tests/ui-msrv/transmute-mut-dst-not-asbytes.stderr12
-rw-r--r--tests/ui-msrv/transmute-mut-dst-not-frombytes.rs24
-rw-r--r--tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr12
-rw-r--r--tests/ui-msrv/transmute-mut-dst-unsized.rs17
-rw-r--r--tests/ui-msrv/transmute-mut-dst-unsized.stderr108
-rw-r--r--tests/ui-msrv/transmute-mut-illegal-lifetime.rs15
-rw-r--r--tests/ui-msrv/transmute-mut-illegal-lifetime.stderr9
-rw-r--r--tests/ui-msrv/transmute-mut-size-decrease.rs17
-rw-r--r--tests/ui-msrv/transmute-mut-size-decrease.stderr36
-rw-r--r--tests/ui-msrv/transmute-mut-size-increase.rs17
-rw-r--r--tests/ui-msrv/transmute-mut-size-increase.stderr36
-rw-r--r--tests/ui-msrv/transmute-mut-src-dst-generic.rs19
-rw-r--r--tests/ui-msrv/transmute-mut-src-dst-generic.stderr19
-rw-r--r--tests/ui-msrv/transmute-mut-src-dst-not-references.rs17
-rw-r--r--tests/ui-msrv/transmute-mut-src-dst-not-references.stderr12
-rw-r--r--tests/ui-msrv/transmute-mut-src-dst-unsized.rs17
-rw-r--r--tests/ui-msrv/transmute-mut-src-dst-unsized.stderr237
-rw-r--r--tests/ui-msrv/transmute-mut-src-generic.rs18
-rw-r--r--tests/ui-msrv/transmute-mut-src-generic.stderr10
-rw-r--r--tests/ui-msrv/transmute-mut-src-immutable.rs18
-rw-r--r--tests/ui-msrv/transmute-mut-src-immutable.stderr11
-rw-r--r--tests/ui-msrv/transmute-mut-src-not-a-reference.rs17
-rw-r--r--tests/ui-msrv/transmute-mut-src-not-a-reference.stderr12
-rw-r--r--tests/ui-msrv/transmute-mut-src-not-asbytes.rs24
-rw-r--r--tests/ui-msrv/transmute-mut-src-not-asbytes.stderr25
-rw-r--r--tests/ui-msrv/transmute-mut-src-not-frombytes.rs24
-rw-r--r--tests/ui-msrv/transmute-mut-src-not-frombytes.stderr25
-rw-r--r--tests/ui-msrv/transmute-mut-src-unsized.rs16
-rw-r--r--tests/ui-msrv/transmute-mut-src-unsized.stderr198
-rw-r--r--tests/ui-msrv/transmute-ptr-to-usize.rs20
-rw-r--r--tests/ui-msrv/transmute-ptr-to-usize.stderr37
-rw-r--r--tests/ui-msrv/transmute-ref-alignment-increase.rs19
-rw-r--r--tests/ui-msrv/transmute-ref-alignment-increase.stderr9
-rw-r--r--tests/ui-msrv/transmute-ref-dst-generic.rs18
-rw-r--r--tests/ui-msrv/transmute-ref-dst-generic.stderr19
-rw-r--r--tests/ui-msrv/transmute-ref-dst-mutable.rs19
-rw-r--r--tests/ui-msrv/transmute-ref-dst-mutable.stderr29
-rw-r--r--tests/ui-msrv/transmute-ref-dst-not-a-reference.rs17
-rw-r--r--tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr29
-rw-r--r--tests/ui-msrv/transmute-ref-dst-not-frombytes.rs18
-rw-r--r--tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr12
-rw-r--r--tests/ui-msrv/transmute-ref-dst-unsized.rs17
-rw-r--r--tests/ui-msrv/transmute-ref-dst-unsized.stderr94
-rw-r--r--tests/ui-msrv/transmute-ref-illegal-lifetime.rs15
-rw-r--r--tests/ui-msrv/transmute-ref-illegal-lifetime.stderr9
-rw-r--r--tests/ui-msrv/transmute-ref-size-decrease.rs17
-rw-r--r--tests/ui-msrv/transmute-ref-size-decrease.stderr9
-rw-r--r--tests/ui-msrv/transmute-ref-size-increase.rs17
-rw-r--r--tests/ui-msrv/transmute-ref-size-increase.stderr9
-rw-r--r--tests/ui-msrv/transmute-ref-src-dst-generic.rs19
-rw-r--r--tests/ui-msrv/transmute-ref-src-dst-generic.stderr19
-rw-r--r--tests/ui-msrv/transmute-ref-src-dst-not-references.rs17
-rw-r--r--tests/ui-msrv/transmute-ref-src-dst-not-references.stderr42
-rw-r--r--tests/ui-msrv/transmute-ref-src-dst-unsized.rs17
-rw-r--r--tests/ui-msrv/transmute-ref-src-dst-unsized.stderr195
-rw-r--r--tests/ui-msrv/transmute-ref-src-generic.rs18
-rw-r--r--tests/ui-msrv/transmute-ref-src-generic.stderr19
-rw-r--r--tests/ui-msrv/transmute-ref-src-not-a-reference.rs17
-rw-r--r--tests/ui-msrv/transmute-ref-src-not-a-reference.stderr12
-rw-r--r--tests/ui-msrv/transmute-ref-src-not-asbytes.rs18
-rw-r--r--tests/ui-msrv/transmute-ref-src-not-asbytes.stderr25
-rw-r--r--tests/ui-msrv/transmute-ref-src-unsized.rs16
-rw-r--r--tests/ui-msrv/transmute-ref-src-unsized.stderr170
-rw-r--r--tests/ui-msrv/transmute-size-decrease.rs19
-rw-r--r--tests/ui-msrv/transmute-size-decrease.stderr9
-rw-r--r--tests/ui-msrv/transmute-size-increase.rs19
-rw-r--r--tests/ui-msrv/transmute-size-increase.stderr9
-rw-r--r--tests/ui-msrv/transmute-src-not-asbytes.rs18
-rw-r--r--tests/ui-msrv/transmute-src-not-asbytes.stderr25
-rw-r--r--tests/ui-nightly/include_value_not_from_bytes.rs12
-rw-r--r--tests/ui-nightly/include_value_not_from_bytes.stderr25
-rw-r--r--tests/ui-nightly/include_value_wrong_size.rs (renamed from tests/ui-stable/transmute-illegal.rs)5
-rw-r--r--tests/ui-nightly/include_value_wrong_size.stderr9
-rw-r--r--tests/ui-nightly/invalid-impls/invalid-impls.rs10
-rw-r--r--tests/ui-nightly/invalid-impls/invalid-impls.stderr72
-rw-r--r--tests/ui-nightly/max-align.rs99
-rw-r--r--tests/ui-nightly/max-align.stderr5
-rw-r--r--tests/ui-nightly/transmute-dst-not-frombytes.rs18
-rw-r--r--tests/ui-nightly/transmute-dst-not-frombytes.stderr25
-rw-r--r--tests/ui-nightly/transmute-illegal.stderr16
-rw-r--r--tests/ui-nightly/transmute-mut-alignment-increase.rs19
-rw-r--r--tests/ui-nightly/transmute-mut-alignment-increase.stderr9
-rw-r--r--tests/ui-nightly/transmute-mut-const.rs20
-rw-r--r--tests/ui-nightly/transmute-mut-const.stderr42
-rw-r--r--tests/ui-nightly/transmute-mut-dst-generic.rs18
-rw-r--r--tests/ui-nightly/transmute-mut-dst-generic.stderr19
-rw-r--r--tests/ui-nightly/transmute-mut-dst-not-a-reference.rs17
-rw-r--r--tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr39
-rw-r--r--tests/ui-nightly/transmute-mut-dst-not-asbytes.rs24
-rw-r--r--tests/ui-nightly/transmute-mut-dst-not-asbytes.stderr25
-rw-r--r--tests/ui-nightly/transmute-mut-dst-not-frombytes.rs24
-rw-r--r--tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr25
-rw-r--r--tests/ui-nightly/transmute-mut-dst-unsized.rs17
-rw-r--r--tests/ui-nightly/transmute-mut-dst-unsized.stderr86
-rw-r--r--tests/ui-nightly/transmute-mut-illegal-lifetime.rs15
-rw-r--r--tests/ui-nightly/transmute-mut-illegal-lifetime.stderr12
-rw-r--r--tests/ui-nightly/transmute-mut-size-decrease.rs17
-rw-r--r--tests/ui-nightly/transmute-mut-size-decrease.stderr9
-rw-r--r--tests/ui-nightly/transmute-mut-size-increase.rs17
-rw-r--r--tests/ui-nightly/transmute-mut-size-increase.stderr9
-rw-r--r--tests/ui-nightly/transmute-mut-src-dst-generic.rs19
-rw-r--r--tests/ui-nightly/transmute-mut-src-dst-generic.stderr19
-rw-r--r--tests/ui-nightly/transmute-mut-src-dst-not-references.rs17
-rw-r--r--tests/ui-nightly/transmute-mut-src-dst-not-references.stderr15
-rw-r--r--tests/ui-nightly/transmute-mut-src-dst-unsized.rs17
-rw-r--r--tests/ui-nightly/transmute-mut-src-dst-unsized.stderr231
-rw-r--r--tests/ui-nightly/transmute-mut-src-generic.rs18
-rw-r--r--tests/ui-nightly/transmute-mut-src-generic.stderr10
-rw-r--r--tests/ui-nightly/transmute-mut-src-immutable.rs18
-rw-r--r--tests/ui-nightly/transmute-mut-src-immutable.stderr11
-rw-r--r--tests/ui-nightly/transmute-mut-src-not-a-reference.rs17
-rw-r--r--tests/ui-nightly/transmute-mut-src-not-a-reference.stderr15
-rw-r--r--tests/ui-nightly/transmute-mut-src-not-asbytes.rs24
-rw-r--r--tests/ui-nightly/transmute-mut-src-not-asbytes.stderr48
-rw-r--r--tests/ui-nightly/transmute-mut-src-not-frombytes.rs24
-rw-r--r--tests/ui-nightly/transmute-mut-src-not-frombytes.stderr48
-rw-r--r--tests/ui-nightly/transmute-mut-src-unsized.rs16
-rw-r--r--tests/ui-nightly/transmute-mut-src-unsized.stderr158
-rw-r--r--tests/ui-nightly/transmute-ptr-to-usize.rs20
-rw-r--r--tests/ui-nightly/transmute-ptr-to-usize.stderr30
-rw-r--r--tests/ui-nightly/transmute-ref-alignment-increase.rs19
-rw-r--r--tests/ui-nightly/transmute-ref-alignment-increase.stderr9
-rw-r--r--tests/ui-nightly/transmute-ref-dst-generic.rs18
-rw-r--r--tests/ui-nightly/transmute-ref-dst-generic.stderr19
-rw-r--r--tests/ui-nightly/transmute-ref-dst-mutable.rs19
-rw-r--r--tests/ui-nightly/transmute-ref-dst-mutable.stderr29
-rw-r--r--tests/ui-nightly/transmute-ref-dst-not-a-reference.rs17
-rw-r--r--tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr29
-rw-r--r--tests/ui-nightly/transmute-ref-dst-not-frombytes.rs18
-rw-r--r--tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr25
-rw-r--r--tests/ui-nightly/transmute-ref-dst-unsized.rs17
-rw-r--r--tests/ui-nightly/transmute-ref-dst-unsized.stderr69
-rw-r--r--tests/ui-nightly/transmute-ref-illegal-lifetime.rs15
-rw-r--r--tests/ui-nightly/transmute-ref-illegal-lifetime.stderr12
-rw-r--r--tests/ui-nightly/transmute-ref-size-decrease.rs17
-rw-r--r--tests/ui-nightly/transmute-ref-size-decrease.stderr9
-rw-r--r--tests/ui-nightly/transmute-ref-size-increase.rs17
-rw-r--r--tests/ui-nightly/transmute-ref-size-increase.stderr9
-rw-r--r--tests/ui-nightly/transmute-ref-src-dst-generic.rs19
-rw-r--r--tests/ui-nightly/transmute-ref-src-dst-generic.stderr19
-rw-r--r--tests/ui-nightly/transmute-ref-src-dst-not-references.rs17
-rw-r--r--tests/ui-nightly/transmute-ref-src-dst-not-references.stderr45
-rw-r--r--tests/ui-nightly/transmute-ref-src-dst-unsized.rs17
-rw-r--r--tests/ui-nightly/transmute-ref-src-dst-unsized.stderr183
-rw-r--r--tests/ui-nightly/transmute-ref-src-generic.rs18
-rw-r--r--tests/ui-nightly/transmute-ref-src-generic.stderr19
-rw-r--r--tests/ui-nightly/transmute-ref-src-not-a-reference.rs17
-rw-r--r--tests/ui-nightly/transmute-ref-src-not-a-reference.stderr15
-rw-r--r--tests/ui-nightly/transmute-ref-src-not-asbytes.rs18
-rw-r--r--tests/ui-nightly/transmute-ref-src-not-asbytes.stderr48
-rw-r--r--tests/ui-nightly/transmute-ref-src-unsized.rs16
-rw-r--r--tests/ui-nightly/transmute-ref-src-unsized.stderr127
-rw-r--r--tests/ui-nightly/transmute-size-decrease.rs19
-rw-r--r--tests/ui-nightly/transmute-size-decrease.stderr9
-rw-r--r--tests/ui-nightly/transmute-size-increase.rs19
-rw-r--r--tests/ui-nightly/transmute-size-increase.stderr9
-rw-r--r--tests/ui-nightly/transmute-src-not-asbytes.rs18
-rw-r--r--tests/ui-nightly/transmute-src-not-asbytes.stderr48
-rw-r--r--tests/ui-stable/include_value_not_from_bytes.rs12
-rw-r--r--tests/ui-stable/include_value_not_from_bytes.stderr25
-rw-r--r--tests/ui-stable/include_value_wrong_size.rs (renamed from tests/ui-nightly/transmute-illegal.rs)5
-rw-r--r--tests/ui-stable/include_value_wrong_size.stderr9
-rw-r--r--tests/ui-stable/invalid-impls/invalid-impls.rs10
-rw-r--r--tests/ui-stable/invalid-impls/invalid-impls.stderr72
-rw-r--r--tests/ui-stable/max-align.rs99
-rw-r--r--tests/ui-stable/max-align.stderr5
-rw-r--r--tests/ui-stable/transmute-dst-not-frombytes.rs18
-rw-r--r--tests/ui-stable/transmute-dst-not-frombytes.stderr25
-rw-r--r--tests/ui-stable/transmute-illegal.stderr16
-rw-r--r--tests/ui-stable/transmute-mut-alignment-increase.rs19
-rw-r--r--tests/ui-stable/transmute-mut-alignment-increase.stderr9
-rw-r--r--tests/ui-stable/transmute-mut-const.rs20
-rw-r--r--tests/ui-stable/transmute-mut-const.stderr41
-rw-r--r--tests/ui-stable/transmute-mut-dst-generic.rs18
-rw-r--r--tests/ui-stable/transmute-mut-dst-generic.stderr19
-rw-r--r--tests/ui-stable/transmute-mut-dst-not-a-reference.rs17
-rw-r--r--tests/ui-stable/transmute-mut-dst-not-a-reference.stderr39
-rw-r--r--tests/ui-stable/transmute-mut-dst-not-asbytes.rs24
-rw-r--r--tests/ui-stable/transmute-mut-dst-not-asbytes.stderr25
-rw-r--r--tests/ui-stable/transmute-mut-dst-not-frombytes.rs24
-rw-r--r--tests/ui-stable/transmute-mut-dst-not-frombytes.stderr25
-rw-r--r--tests/ui-stable/transmute-mut-dst-unsized.rs17
-rw-r--r--tests/ui-stable/transmute-mut-dst-unsized.stderr106
-rw-r--r--tests/ui-stable/transmute-mut-illegal-lifetime.rs15
-rw-r--r--tests/ui-stable/transmute-mut-illegal-lifetime.stderr12
-rw-r--r--tests/ui-stable/transmute-mut-size-decrease.rs17
-rw-r--r--tests/ui-stable/transmute-mut-size-decrease.stderr9
-rw-r--r--tests/ui-stable/transmute-mut-size-increase.rs17
-rw-r--r--tests/ui-stable/transmute-mut-size-increase.stderr9
-rw-r--r--tests/ui-stable/transmute-mut-src-dst-generic.rs19
-rw-r--r--tests/ui-stable/transmute-mut-src-dst-generic.stderr19
-rw-r--r--tests/ui-stable/transmute-mut-src-dst-not-references.rs17
-rw-r--r--tests/ui-stable/transmute-mut-src-dst-not-references.stderr15
-rw-r--r--tests/ui-stable/transmute-mut-src-dst-unsized.rs17
-rw-r--r--tests/ui-stable/transmute-mut-src-dst-unsized.stderr288
-rw-r--r--tests/ui-stable/transmute-mut-src-generic.rs18
-rw-r--r--tests/ui-stable/transmute-mut-src-generic.stderr10
-rw-r--r--tests/ui-stable/transmute-mut-src-immutable.rs18
-rw-r--r--tests/ui-stable/transmute-mut-src-immutable.stderr11
-rw-r--r--tests/ui-stable/transmute-mut-src-not-a-reference.rs17
-rw-r--r--tests/ui-stable/transmute-mut-src-not-a-reference.stderr15
-rw-r--r--tests/ui-stable/transmute-mut-src-not-asbytes.rs24
-rw-r--r--tests/ui-stable/transmute-mut-src-not-asbytes.stderr48
-rw-r--r--tests/ui-stable/transmute-mut-src-not-frombytes.rs24
-rw-r--r--tests/ui-stable/transmute-mut-src-not-frombytes.stderr48
-rw-r--r--tests/ui-stable/transmute-mut-src-unsized.rs16
-rw-r--r--tests/ui-stable/transmute-mut-src-unsized.stderr195
-rw-r--r--tests/ui-stable/transmute-ptr-to-usize.rs20
-rw-r--r--tests/ui-stable/transmute-ptr-to-usize.stderr30
-rw-r--r--tests/ui-stable/transmute-ref-alignment-increase.rs19
-rw-r--r--tests/ui-stable/transmute-ref-alignment-increase.stderr9
-rw-r--r--tests/ui-stable/transmute-ref-dst-generic.rs18
-rw-r--r--tests/ui-stable/transmute-ref-dst-generic.stderr19
-rw-r--r--tests/ui-stable/transmute-ref-dst-mutable.rs19
-rw-r--r--tests/ui-stable/transmute-ref-dst-mutable.stderr29
-rw-r--r--tests/ui-stable/transmute-ref-dst-not-a-reference.rs17
-rw-r--r--tests/ui-stable/transmute-ref-dst-not-a-reference.stderr29
-rw-r--r--tests/ui-stable/transmute-ref-dst-not-frombytes.rs18
-rw-r--r--tests/ui-stable/transmute-ref-dst-not-frombytes.stderr25
-rw-r--r--tests/ui-stable/transmute-ref-dst-unsized.rs17
-rw-r--r--tests/ui-stable/transmute-ref-dst-unsized.stderr89
-rw-r--r--tests/ui-stable/transmute-ref-illegal-lifetime.rs15
-rw-r--r--tests/ui-stable/transmute-ref-illegal-lifetime.stderr12
-rw-r--r--tests/ui-stable/transmute-ref-size-decrease.rs17
-rw-r--r--tests/ui-stable/transmute-ref-size-decrease.stderr9
-rw-r--r--tests/ui-stable/transmute-ref-size-increase.rs17
-rw-r--r--tests/ui-stable/transmute-ref-size-increase.stderr9
-rw-r--r--tests/ui-stable/transmute-ref-src-dst-generic.rs19
-rw-r--r--tests/ui-stable/transmute-ref-src-dst-generic.stderr19
-rw-r--r--tests/ui-stable/transmute-ref-src-dst-not-references.rs17
-rw-r--r--tests/ui-stable/transmute-ref-src-dst-not-references.stderr45
-rw-r--r--tests/ui-stable/transmute-ref-src-dst-unsized.rs17
-rw-r--r--tests/ui-stable/transmute-ref-src-dst-unsized.stderr240
-rw-r--r--tests/ui-stable/transmute-ref-src-generic.rs18
-rw-r--r--tests/ui-stable/transmute-ref-src-generic.stderr19
-rw-r--r--tests/ui-stable/transmute-ref-src-not-a-reference.rs17
-rw-r--r--tests/ui-stable/transmute-ref-src-not-a-reference.stderr15
-rw-r--r--tests/ui-stable/transmute-ref-src-not-asbytes.rs18
-rw-r--r--tests/ui-stable/transmute-ref-src-not-asbytes.stderr48
-rw-r--r--tests/ui-stable/transmute-ref-src-unsized.rs16
-rw-r--r--tests/ui-stable/transmute-ref-src-unsized.stderr164
-rw-r--r--tests/ui-stable/transmute-size-decrease.rs19
-rw-r--r--tests/ui-stable/transmute-size-decrease.stderr9
-rw-r--r--tests/ui-stable/transmute-size-increase.rs19
-rw-r--r--tests/ui-stable/transmute-size-increase.stderr9
-rw-r--r--tests/ui-stable/transmute-src-not-asbytes.rs18
-rw-r--r--tests/ui-stable/transmute-src-not-asbytes.stderr48
268 files changed, 7941 insertions, 199 deletions
diff --git a/tests/trybuild.rs b/tests/trybuild.rs
index 4ed01f7..24abc28 100644
--- a/tests/trybuild.rs
+++ b/tests/trybuild.rs
@@ -1,33 +1,23 @@
-// Copyright 2019 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2019 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
-// UI tests depend on the exact error messages emitted by rustc, but those error
-// messages are not stable, and sometimes change between Rust versions. Thus, we
-// maintain one set of UI tests for each Rust version that we test in CI, and we
-// pin to specific versions in CI (a specific stable version, a specific date of
-// the nightly compiler, and a specific MSRV). Updating those pinned versions
-// may also require updating these tests.
-// - `tests/ui-nightly` - Contains the source of truth for our UI test source
-// files (`.rs`), and contains `.err` and `.out` files for nightly
-// - `tests/ui-stable` - Contains symlinks to the `.rs` files in
-// `tests/ui-nightly`, and contains `.err` and `.out` files for stable
-// - `tests/ui-msrv` - Contains symlinks to the `.rs` files in
-// `tests/ui-nightly`, and contains `.err` and `.out` files for MSRV
-
-#[rustversion::nightly]
-const SOURCE_FILES_DIR: &str = "tests/ui-nightly";
-#[rustversion::stable(1.69.0)]
-const SOURCE_FILES_DIR: &str = "tests/ui-stable";
-#[rustversion::stable(1.61.0)]
-const SOURCE_FILES_DIR: &str = "tests/ui-msrv";
-
-const SOURCE_FILES_DIR: &str = "tests/ui-stable";
+use testutil::ToolchainVersion;
#[test]
+#[cfg_attr(miri, ignore)]
fn ui() {
+ let version = ToolchainVersion::extract_from_pwd().unwrap();
+ // See the doc comment on this method for an explanation of what this does
+ // and why we store source files in different directories.
+ let source_files_dirname = version.get_ui_source_files_dirname_and_maybe_print_warning();
+
let t = trybuild::TestCases::new();
- t.compile_fail(format!("{SOURCE_FILES_DIR}/*.rs"));
+ t.compile_fail(format!("tests/{source_files_dirname}/*.rs"));
}
// The file `invalid-impls.rs` directly includes `src/macros.rs` in order to
@@ -39,7 +29,13 @@ fn ui() {
// tests the correct behavior when the "derive" feature is enabled.
#[cfg(feature = "derive")]
#[test]
+#[cfg_attr(miri, ignore)]
fn ui_invalid_impls() {
+ let version = ToolchainVersion::extract_from_pwd().unwrap();
+ // See the doc comment on this method for an explanation of what this does
+ // and why we store source files in different directories.
+ let source_files_dirname = version.get_ui_source_files_dirname_and_maybe_print_warning();
+
let t = trybuild::TestCases::new();
- t.compile_fail(format!("{SOURCE_FILES_DIR}/invalid-impls/*.rs"));
+ t.compile_fail(format!("tests/{source_files_dirname}/invalid-impls/*.rs"));
}
diff --git a/tests/ui-msrv/include_value_not_from_bytes.rs b/tests/ui-msrv/include_value_not_from_bytes.rs
new file mode 100644
index 0000000..45b6138
--- /dev/null
+++ b/tests/ui-msrv/include_value_not_from_bytes.rs
@@ -0,0 +1,12 @@
+// Copyright 2022 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#[macro_use]
+extern crate zerocopy;
+
+fn main() {}
+
+// Should fail because `UnsafeCell<u32>: !FromBytes`.
+const NOT_FROM_BYTES: core::cell::UnsafeCell<u32> =
+ include_value!("../../testdata/include_value/data");
diff --git a/tests/ui-msrv/include_value_not_from_bytes.stderr b/tests/ui-msrv/include_value_not_from_bytes.stderr
new file mode 100644
index 0000000..21f6443
--- /dev/null
+++ b/tests/ui-msrv/include_value_not_from_bytes.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the trait bound `UnsafeCell<u32>: FromBytes` is not satisfied
+ --> tests/ui-msrv/include_value_not_from_bytes.rs:12:5
+ |
+12 | include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `UnsafeCell<u32>`
+ |
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-msrv/include_value_not_from_bytes.rs:12:5
+ |
+12 | include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `$crate::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-illegal.rs b/tests/ui-msrv/include_value_wrong_size.rs
index 74b8439..d87b306 100644
--- a/tests/ui-msrv/transmute-illegal.rs
+++ b/tests/ui-msrv/include_value_wrong_size.rs
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#[macro_use]
extern crate zerocopy;
fn main() {}
-// It is unsound to inspect the usize value of a pointer during const eval.
-const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
+// Should fail because the file is 4 bytes long, not 8.
+const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");
diff --git a/tests/ui-msrv/include_value_wrong_size.stderr b/tests/ui-msrv/include_value_wrong_size.stderr
new file mode 100644
index 0000000..3004584
--- /dev/null
+++ b/tests/ui-msrv/include_value_wrong_size.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/include_value_wrong_size.rs:11:25
+ |
+11 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 4]` (32 bits)
+ = note: target type: `u64` (64 bits)
+ = note: this error originates in the macro `$crate::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/invalid-impls/invalid-impls.rs b/tests/ui-msrv/invalid-impls/invalid-impls.rs
index b9a60bd..ea96390 100644
--- a/tests/ui-msrv/invalid-impls/invalid-impls.rs
+++ b/tests/ui-msrv/invalid-impls/invalid-impls.rs
@@ -1,6 +1,10 @@
-// Copyright 2022 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
// Since some macros from `macros.rs` are unused.
#![allow(unused)]
diff --git a/tests/ui-msrv/invalid-impls/invalid-impls.stderr b/tests/ui-msrv/invalid-impls/invalid-impls.stderr
index fee0cd9..c1de466 100644
--- a/tests/ui-msrv/invalid-impls/invalid-impls.stderr
+++ b/tests/ui-msrv/invalid-impls/invalid-impls.stderr
@@ -4,15 +4,15 @@ error[E0277]: the trait bound `T: zerocopy::FromZeroes` is not satisfied
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:22:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:26:1
|
-22 | impl_or_verify!(T => FromZeroes for Foo<T>);
+26 | impl_or_verify!(T => FromZeroes for Foo<T>);
| ------------------------------------------- in this macro invocation
|
note: required because of the requirements on the impl of `zerocopy::FromZeroes` for `Foo<T>`
- --> tests/ui-msrv/invalid-impls/invalid-impls.rs:18:10
+ --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:10
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/macros.rs
@@ -20,15 +20,15 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:22:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:26:1
|
-22 | impl_or_verify!(T => FromZeroes for Foo<T>);
+26 | impl_or_verify!(T => FromZeroes for Foo<T>);
| ------------------------------------------- in this macro invocation
= note: this error originates in the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-22 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo<T>);
- | ++++++++++++++++++++++
+ |
+26 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo<T>);
+ | ++++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/macros.rs
@@ -36,15 +36,15 @@ error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:23:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:27:1
|
-23 | impl_or_verify!(T => FromBytes for Foo<T>);
+27 | impl_or_verify!(T => FromBytes for Foo<T>);
| ------------------------------------------ in this macro invocation
|
note: required because of the requirements on the impl of `zerocopy::FromBytes` for `Foo<T>`
- --> tests/ui-msrv/invalid-impls/invalid-impls.rs:18:22
+ --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:22
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/macros.rs
@@ -52,15 +52,15 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:23:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:27:1
|
-23 | impl_or_verify!(T => FromBytes for Foo<T>);
+27 | impl_or_verify!(T => FromBytes for Foo<T>);
| ------------------------------------------ in this macro invocation
= note: this error originates in the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-23 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo<T>);
- | +++++++++++++++++++++
+ |
+27 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo<T>);
+ | +++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/macros.rs
@@ -68,15 +68,15 @@ error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:24:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:28:1
|
-24 | impl_or_verify!(T => AsBytes for Foo<T>);
+28 | impl_or_verify!(T => AsBytes for Foo<T>);
| ---------------------------------------- in this macro invocation
|
note: required because of the requirements on the impl of `zerocopy::AsBytes` for `Foo<T>`
- --> tests/ui-msrv/invalid-impls/invalid-impls.rs:18:33
+ --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:33
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/macros.rs
@@ -84,15 +84,15 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:24:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:28:1
|
-24 | impl_or_verify!(T => AsBytes for Foo<T>);
+28 | impl_or_verify!(T => AsBytes for Foo<T>);
| ---------------------------------------- in this macro invocation
= note: this error originates in the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-24 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo<T>);
- | +++++++++++++++++++
+ |
+28 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo<T>);
+ | +++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/macros.rs
@@ -100,15 +100,15 @@ error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:25:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:29:1
|
-25 | impl_or_verify!(T => Unaligned for Foo<T>);
+29 | impl_or_verify!(T => Unaligned for Foo<T>);
| ------------------------------------------ in this macro invocation
|
note: required because of the requirements on the impl of `zerocopy::Unaligned` for `Foo<T>`
- --> tests/ui-msrv/invalid-impls/invalid-impls.rs:18:42
+ --> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:42
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/macros.rs
@@ -116,12 +116,12 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
- ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:25:1
+ ::: tests/ui-msrv/invalid-impls/invalid-impls.rs:29:1
|
-25 | impl_or_verify!(T => Unaligned for Foo<T>);
+29 | impl_or_verify!(T => Unaligned for Foo<T>);
| ------------------------------------------ in this macro invocation
= note: this error originates in the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-25 | impl_or_verify!(T: zerocopy::Unaligned => Unaligned for Foo<T>);
- | +++++++++++++++++++++
+ |
+29 | impl_or_verify!(T: zerocopy::Unaligned => Unaligned for Foo<T>);
+ | +++++++++++++++++++++
diff --git a/tests/ui-msrv/max-align.rs b/tests/ui-msrv/max-align.rs
new file mode 100644
index 0000000..53e3eb9
--- /dev/null
+++ b/tests/ui-msrv/max-align.rs
@@ -0,0 +1,99 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+#[repr(C, align(1))]
+struct Align1;
+
+#[repr(C, align(2))]
+struct Align2;
+
+#[repr(C, align(4))]
+struct Align4;
+
+#[repr(C, align(8))]
+struct Align8;
+
+#[repr(C, align(16))]
+struct Align16;
+
+#[repr(C, align(32))]
+struct Align32;
+
+#[repr(C, align(64))]
+struct Align64;
+
+#[repr(C, align(128))]
+struct Align128;
+
+#[repr(C, align(256))]
+struct Align256;
+
+#[repr(C, align(512))]
+struct Align512;
+
+#[repr(C, align(1024))]
+struct Align1024;
+
+#[repr(C, align(2048))]
+struct Align2048;
+
+#[repr(C, align(4096))]
+struct Align4096;
+
+#[repr(C, align(8192))]
+struct Align8192;
+
+#[repr(C, align(16384))]
+struct Align16384;
+
+#[repr(C, align(32768))]
+struct Align32768;
+
+#[repr(C, align(65536))]
+struct Align65536;
+
+#[repr(C, align(131072))]
+struct Align131072;
+
+#[repr(C, align(262144))]
+struct Align262144;
+
+#[repr(C, align(524288))]
+struct Align524288;
+
+#[repr(C, align(1048576))]
+struct Align1048576;
+
+#[repr(C, align(2097152))]
+struct Align2097152;
+
+#[repr(C, align(4194304))]
+struct Align4194304;
+
+#[repr(C, align(8388608))]
+struct Align8388608;
+
+#[repr(C, align(16777216))]
+struct Align16777216;
+
+#[repr(C, align(33554432))]
+struct Align33554432;
+
+#[repr(C, align(67108864))]
+struct Align67108864;
+
+#[repr(C, align(134217728))]
+struct Align13421772;
+
+#[repr(C, align(268435456))]
+struct Align26843545;
+
+#[repr(C, align(1073741824))]
+struct Align1073741824;
+
+fn main() {}
diff --git a/tests/ui-msrv/max-align.stderr b/tests/ui-msrv/max-align.stderr
new file mode 100644
index 0000000..6ab6e47
--- /dev/null
+++ b/tests/ui-msrv/max-align.stderr
@@ -0,0 +1,5 @@
+error[E0589]: invalid `repr(align)` attribute: larger than 2^29
+ --> tests/ui-msrv/max-align.rs:96:11
+ |
+96 | #[repr(C, align(1073741824))]
+ | ^^^^^^^^^^^^^^^^^
diff --git a/tests/ui-msrv/transmute-dst-not-frombytes.rs b/tests/ui-msrv/transmute-dst-not-frombytes.rs
new file mode 100644
index 0000000..c4caaff
--- /dev/null
+++ b/tests/ui-msrv/transmute-dst-not-frombytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
diff --git a/tests/ui-msrv/transmute-dst-not-frombytes.stderr b/tests/ui-msrv/transmute-dst-not-frombytes.stderr
new file mode 100644
index 0000000..b4afbbd
--- /dev/null
+++ b/tests/ui-msrv/transmute-dst-not-frombytes.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
+ --> tests/ui-msrv/transmute-dst-not-frombytes.rs:18:41
+ |
+18 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy`
+ |
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-msrv/transmute-dst-not-frombytes.rs:18:41
+ |
+18 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-illegal.stderr b/tests/ui-msrv/transmute-illegal.stderr
deleted file mode 100644
index 37c124a..0000000
--- a/tests/ui-msrv/transmute-illegal.stderr
+++ /dev/null
@@ -1,18 +0,0 @@
-error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
- --> tests/ui-msrv/transmute-illegal.rs:10:30
- |
-10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize`
- |
- = help: the following implementations were found:
- <usize as AsBytes>
- <f32 as AsBytes>
- <f64 as AsBytes>
- <i128 as AsBytes>
- and $N others
-note: required by a bound in `POINTER_VALUE::transmute`
- --> tests/ui-msrv/transmute-illegal.rs:10:30
- |
-10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `POINTER_VALUE::transmute`
- = note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-alignment-increase.rs b/tests/ui-msrv/transmute-mut-alignment-increase.rs
new file mode 100644
index 0000000..0928564
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-alignment-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a type of smaller
+// alignment to one of larger alignment.
+const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
diff --git a/tests/ui-msrv/transmute-mut-alignment-increase.stderr b/tests/ui-msrv/transmute-mut-alignment-increase.stderr
new file mode 100644
index 0000000..033031c
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-alignment-increase.stderr
@@ -0,0 +1,36 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-mut-alignment-increase.rs:19:39
+ |
+19 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<[u8; 2]>` (8 bits)
+ = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0658]: mutable references are not allowed in constants
+ --> tests/ui-msrv/transmute-mut-alignment-increase.rs:19:54
+ |
+19 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+
+error[E0015]: cannot call non-const fn `transmute_mut::<[u8; 2], AU16>` in constants
+ --> tests/ui-msrv/transmute-mut-alignment-increase.rs:19:39
+ |
+19 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0716]: temporary value dropped while borrowed
+ --> tests/ui-msrv/transmute-mut-alignment-increase.rs:19:59
+ |
+19 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
+ | --------------------^^^^^^^^-
+ | | |
+ | | creates a temporary which is freed while still in use
+ | temporary value is freed at the end of this statement
+ | using this value as a constant requires that borrow lasts for `'static`
diff --git a/tests/ui-msrv/transmute-mut-const.rs b/tests/ui-msrv/transmute-mut-const.rs
new file mode 100644
index 0000000..021b562
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-const.rs
@@ -0,0 +1,20 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+const ARRAY_OF_U8S: [u8; 2] = [0u8; 2];
+
+// `transmute_mut!` cannot, generally speaking, be used in const contexts.
+const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
diff --git a/tests/ui-msrv/transmute-mut-const.stderr b/tests/ui-msrv/transmute-mut-const.stderr
new file mode 100644
index 0000000..30bfe45
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-const.stderr
@@ -0,0 +1,41 @@
+warning: taking a mutable reference to a `const` item
+ --> tests/ui-msrv/transmute-mut-const.rs:20:52
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(const_item_mutation)]` on by default
+ = note: each usage of a `const` item creates a new temporary
+ = note: the mutable reference will refer to this temporary, not the original `const` item
+note: `const` item defined here
+ --> tests/ui-msrv/transmute-mut-const.rs:17:1
+ |
+17 | const ARRAY_OF_U8S: [u8; 2] = [0u8; 2];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0658]: mutable references are not allowed in constants
+ --> tests/ui-msrv/transmute-mut-const.rs:20:52
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+
+error[E0015]: cannot call non-const fn `transmute_mut::<[u8; 2], [u8; 2]>` in constants
+ --> tests/ui-msrv/transmute-mut-const.rs:20:37
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0716]: temporary value dropped while borrowed
+ --> tests/ui-msrv/transmute-mut-const.rs:20:57
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | --------------------^^^^^^^^^^^^-
+ | | |
+ | | creates a temporary which is freed while still in use
+ | temporary value is freed at the end of this statement
+ | using this value as a constant requires that borrow lasts for `'static`
diff --git a/tests/ui-msrv/transmute-mut-dst-generic.rs b/tests/ui-msrv/transmute-mut-dst-generic.rs
new file mode 100644
index 0000000..7068f10
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes>(u: &mut u8) -> &mut T {
+ // `transmute_mut!` requires the destination type to be concrete.
+ transmute_mut!(u)
+}
diff --git a/tests/ui-msrv/transmute-mut-dst-generic.stderr b/tests/ui-msrv/transmute-mut-dst-generic.stderr
new file mode 100644
index 0000000..f6b54ce
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-mut-dst-generic.rs:17:5
+ |
+17 | transmute_mut!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `T` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-mut-dst-generic.rs:17:5
+ |
+17 | transmute_mut!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<u8>` (8 bits)
+ = note: target type: `MaxAlignsOf<u8, T>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-dst-not-a-reference.rs b/tests/ui-msrv/transmute-mut-dst-not-a-reference.rs
new file mode 100644
index 0000000..33a9ecd
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting into a non-reference
+// destination type.
+const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
diff --git a/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr b/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr
new file mode 100644
index 0000000..8f0ea80
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr
@@ -0,0 +1,39 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-dst-not-asbytes.rs b/tests/ui-msrv/transmute-mut-dst-not-asbytes.rs
new file mode 100644
index 0000000..b72f129
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-not-asbytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the destination type implements `AsBytes`
+const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-msrv/transmute-mut-dst-not-asbytes.stderr b/tests/ui-msrv/transmute-mut-dst-not-asbytes.stderr
new file mode 100644
index 0000000..7e2dd78
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-not-asbytes.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the trait bound `Dst: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-mut-dst-not-asbytes.rs:24:36
+ |
+24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Dst`
+ |
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-dst-not-asbytes.rs:24:36
+ |
+24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-dst-not-frombytes.rs b/tests/ui-msrv/transmute-mut-dst-not-frombytes.rs
new file mode 100644
index 0000000..102fced
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-not-frombytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr b/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr
new file mode 100644
index 0000000..663e085
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-not-frombytes.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the trait bound `Dst: FromBytes` is not satisfied
+ --> tests/ui-msrv/transmute-mut-dst-not-frombytes.rs:24:38
+ |
+24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Dst`
+ |
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-dst-not-frombytes.rs:24:38
+ |
+24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-dst-unsized.rs b/tests/ui-msrv/transmute-mut-dst-unsized.rs
new file mode 100644
index 0000000..693ccda
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting into an unsized destination
+// type.
+const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
diff --git a/tests/ui-msrv/transmute-mut-dst-unsized.stderr b/tests/ui-msrv/transmute-mut-dst-unsized.stderr
new file mode 100644
index 0000000..cb60a82
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-dst-unsized.stderr
@@ -0,0 +1,108 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<T, U>(e: T) -> U;
+ | ^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-illegal-lifetime.rs b/tests/ui-msrv/transmute-mut-illegal-lifetime.rs
new file mode 100644
index 0000000..c31765e
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-illegal-lifetime.rs
@@ -0,0 +1,15 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+fn main() {}
+
+fn increase_lifetime() {
+ let mut x = 0u64;
+ // It is illegal to increase the lifetime scope.
+ let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x);
+}
diff --git a/tests/ui-msrv/transmute-mut-illegal-lifetime.stderr b/tests/ui-msrv/transmute-mut-illegal-lifetime.stderr
new file mode 100644
index 0000000..5ff7145
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-illegal-lifetime.stderr
@@ -0,0 +1,9 @@
+error[E0597]: `x` does not live long enough
+ --> tests/ui-msrv/transmute-mut-illegal-lifetime.rs:14:56
+ |
+14 | let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x);
+ | ---------------- ^^^^^^ borrowed value does not live long enough
+ | |
+ | type annotation requires that `x` is borrowed for `'static`
+15 | }
+ | - `x` dropped here while still borrowed
diff --git a/tests/ui-msrv/transmute-mut-size-decrease.rs b/tests/ui-msrv/transmute-mut-size-decrease.rs
new file mode 100644
index 0000000..c6eec3a
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-size-decrease.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// We require that the size of the destination type is not smaller than the size
+// of the source type.
+const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
diff --git a/tests/ui-msrv/transmute-mut-size-decrease.stderr b/tests/ui-msrv/transmute-mut-size-decrease.stderr
new file mode 100644
index 0000000..2bfc218
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-size-decrease.stderr
@@ -0,0 +1,36 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:32
+ |
+17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 2]` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0658]: mutable references are not allowed in constants
+ --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:47
+ |
+17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+
+error[E0015]: cannot call non-const fn `transmute_mut::<[u8; 2], u8>` in constants
+ --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:32
+ |
+17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0716]: temporary value dropped while borrowed
+ --> tests/ui-msrv/transmute-mut-size-decrease.rs:17:52
+ |
+17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
+ | --------------------^^^^^^^^-
+ | | |
+ | | creates a temporary which is freed while still in use
+ | temporary value is freed at the end of this statement
+ | using this value as a constant requires that borrow lasts for `'static`
diff --git a/tests/ui-msrv/transmute-mut-size-increase.rs b/tests/ui-msrv/transmute-mut-size-increase.rs
new file mode 100644
index 0000000..a4657c2
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-size-increase.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
diff --git a/tests/ui-msrv/transmute-mut-size-increase.stderr b/tests/ui-msrv/transmute-mut-size-increase.stderr
new file mode 100644
index 0000000..6e866a0
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-size-increase.stderr
@@ -0,0 +1,36 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-mut-size-increase.rs:17:37
+ |
+17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `[u8; 2]` (16 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0658]: mutable references are not allowed in constants
+ --> tests/ui-msrv/transmute-mut-size-increase.rs:17:52
+ |
+17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+
+error[E0015]: cannot call non-const fn `transmute_mut::<u8, [u8; 2]>` in constants
+ --> tests/ui-msrv/transmute-mut-size-increase.rs:17:37
+ |
+17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0716]: temporary value dropped while borrowed
+ --> tests/ui-msrv/transmute-mut-size-increase.rs:17:57
+ |
+17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
+ | --------------------^^^-
+ | | |
+ | | creates a temporary which is freed while still in use
+ | temporary value is freed at the end of this statement
+ | using this value as a constant requires that borrow lasts for `'static`
diff --git a/tests/ui-msrv/transmute-mut-src-dst-generic.rs b/tests/ui-msrv/transmute-mut-src-dst-generic.rs
new file mode 100644
index 0000000..aed7ded
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-dst-generic.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes, U: AsBytes + FromBytes>(t: &mut T) -> &mut U {
+ // `transmute_mut!` requires the source and destination types to be
+ // concrete.
+ transmute_mut!(t)
+}
diff --git a/tests/ui-msrv/transmute-mut-src-dst-generic.stderr b/tests/ui-msrv/transmute-mut-src-dst-generic.stderr
new file mode 100644
index 0000000..1162f21
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-mut-src-dst-generic.rs:18:5
+ |
+18 | transmute_mut!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `U` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-mut-src-dst-generic.rs:18:5
+ |
+18 | transmute_mut!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, U>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-src-dst-not-references.rs b/tests/ui-msrv/transmute-mut-src-dst-not-references.rs
new file mode 100644
index 0000000..98cc520
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-dst-not-references.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting between non-reference source
+// and destination types.
+const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize);
diff --git a/tests/ui-msrv/transmute-mut-src-dst-not-references.stderr b/tests/ui-msrv/transmute-mut-src-dst-not-references.stderr
new file mode 100644
index 0000000..c500a93
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-dst-not-references.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-mut-src-dst-not-references.rs:17:59
+ |
+17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&mut _`, found `usize`
+ | | help: consider mutably borrowing here: `&mut 0usize`
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found type `usize`
diff --git a/tests/ui-msrv/transmute-mut-src-dst-unsized.rs b/tests/ui-msrv/transmute-mut-src-dst-unsized.rs
new file mode 100644
index 0000000..1bebcf2
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting between unsized source and
+// destination types.
+const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
diff --git a/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr b/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr
new file mode 100644
index 0000000..00201a6
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-dst-unsized.stderr
@@ -0,0 +1,237 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<T, U>(e: T) -> U;
+ | ^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all function arguments must have a statically known size
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-src-generic.rs b/tests/ui-msrv/transmute-mut-src-generic.rs
new file mode 100644
index 0000000..a3ef397
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes>(t: &mut T) -> &mut u8 {
+ // `transmute_mut!` requires the source type to be concrete.
+ transmute_mut!(t)
+}
diff --git a/tests/ui-msrv/transmute-mut-src-generic.stderr b/tests/ui-msrv/transmute-mut-src-generic.stderr
new file mode 100644
index 0000000..8a9296c
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-generic.stderr
@@ -0,0 +1,10 @@
+error[E0405]: cannot find trait `FromBytes` in this scope
+ --> tests/ui-msrv/transmute-mut-src-generic.rs:15:31
+ |
+15 | fn transmute_mut<T: AsBytes + FromBytes>(t: &mut T) -> &mut u8 {
+ | ^^^^^^^^^ not found in this scope
+ |
+help: consider importing this trait
+ |
+11 | use zerocopy::FromBytes;
+ |
diff --git a/tests/ui-msrv/transmute-mut-src-immutable.rs b/tests/ui-msrv/transmute-mut-src-immutable.rs
new file mode 100644
index 0000000..08088d0
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-immutable.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+fn ref_src_immutable() {
+ // `transmute_mut!` requires that its source type be a mutable reference.
+ let _: &mut u8 = transmute_mut!(&0u8);
+}
diff --git a/tests/ui-msrv/transmute-mut-src-immutable.stderr b/tests/ui-msrv/transmute-mut-src-immutable.stderr
new file mode 100644
index 0000000..8262f16
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-immutable.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-mut-src-immutable.rs:17:37
+ |
+17 | let _: &mut u8 = transmute_mut!(&0u8);
+ | ---------------^^^^-
+ | | |
+ | | types differ in mutability
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found reference `&u8`
diff --git a/tests/ui-msrv/transmute-mut-src-not-a-reference.rs b/tests/ui-msrv/transmute-mut-src-not-a-reference.rs
new file mode 100644
index 0000000..bf8bc32
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a non-reference source
+// type.
+const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize);
diff --git a/tests/ui-msrv/transmute-mut-src-not-a-reference.stderr b/tests/ui-msrv/transmute-mut-src-not-a-reference.stderr
new file mode 100644
index 0000000..3a6bdf7
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-not-a-reference.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-mut-src-not-a-reference.rs:17:53
+ |
+17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&mut _`, found `usize`
+ | | help: consider mutably borrowing here: `&mut 0usize`
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found type `usize`
diff --git a/tests/ui-msrv/transmute-mut-src-not-asbytes.rs b/tests/ui-msrv/transmute-mut-src-not-asbytes.rs
new file mode 100644
index 0000000..6a14f12
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-not-asbytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-msrv/transmute-mut-src-not-asbytes.stderr b/tests/ui-msrv/transmute-mut-src-not-asbytes.stderr
new file mode 100644
index 0000000..4056975
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-not-asbytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `Src: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src`
+ |
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `Src: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src`
+ |
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-src-not-frombytes.rs b/tests/ui-msrv/transmute-mut-src-not-frombytes.rs
new file mode 100644
index 0000000..2ebe036
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-not-frombytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the source type implements `FromBytes`
+const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-msrv/transmute-mut-src-not-frombytes.stderr b/tests/ui-msrv/transmute-mut-src-not-frombytes.stderr
new file mode 100644
index 0000000..b859c41
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-not-frombytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `Src: FromBytes` is not satisfied
+ --> tests/ui-msrv/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src`
+ |
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `Src: FromBytes` is not satisfied
+ --> tests/ui-msrv/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src`
+ |
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-mut-src-unsized.rs b/tests/ui-msrv/transmute-mut-src-unsized.rs
new file mode 100644
index 0000000..413dd68
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-unsized.rs
@@ -0,0 +1,16 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from an unsized source type.
+const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
diff --git a/tests/ui-msrv/transmute-mut-src-unsized.stderr b/tests/ui-msrv/transmute-mut-src-unsized.stderr
new file mode 100644
index 0000000..6b18695
--- /dev/null
+++ b/tests/ui-msrv/transmute-mut-src-unsized.stderr
@@ -0,0 +1,198 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<T, U>(e: T) -> U;
+ | ^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all function arguments must have a statically known size
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ptr-to-usize.rs b/tests/ui-msrv/transmute-ptr-to-usize.rs
new file mode 100644
index 0000000..5af8859
--- /dev/null
+++ b/tests/ui-msrv/transmute-ptr-to-usize.rs
@@ -0,0 +1,20 @@
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// It is unclear whether we can or should support this transmutation, especially
+// in a const context. This test ensures that even if such a transmutation
+// becomes valid due to the requisite implementations of `FromBytes` being
+// added, that we re-examine whether it should specifically be valid in a const
+// context.
+const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
diff --git a/tests/ui-msrv/transmute-ptr-to-usize.stderr b/tests/ui-msrv/transmute-ptr-to-usize.stderr
new file mode 100644
index 0000000..06b1bba
--- /dev/null
+++ b/tests/ui-msrv/transmute-ptr-to-usize.stderr
@@ -0,0 +1,37 @@
+error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize`
+ |
+ = help: the following implementations were found:
+ <usize as AsBytes>
+ <f32 as AsBytes>
+ <f64 as AsBytes>
+ <i128 as AsBytes>
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize`
+ |
+ = help: the following implementations were found:
+ <usize as AsBytes>
+ <f32 as AsBytes>
+ <f64 as AsBytes>
+ <i128 as AsBytes>
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-alignment-increase.rs b/tests/ui-msrv/transmute-ref-alignment-increase.rs
new file mode 100644
index 0000000..bf1988c
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-alignment-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a type of smaller
+// alignment to one of larger alignment.
+const INCREASE_ALIGNMENT: &AU16 = transmute_ref!(&[0u8; 2]);
diff --git a/tests/ui-msrv/transmute-ref-alignment-increase.stderr b/tests/ui-msrv/transmute-ref-alignment-increase.stderr
new file mode 100644
index 0000000..72864e1
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-alignment-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-alignment-increase.rs:19:35
+ |
+19 | const INCREASE_ALIGNMENT: &AU16 = transmute_ref!(&[0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<[u8; 2]>` (8 bits)
+ = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-dst-generic.rs b/tests/ui-msrv/transmute-ref-dst-generic.rs
new file mode 100644
index 0000000..bf4a0f9
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, FromBytes};
+
+fn main() {}
+
+fn transmute_ref<T: FromBytes>(u: &u8) -> &T {
+ // `transmute_ref!` requires the destination type to be concrete.
+ transmute_ref!(u)
+}
diff --git a/tests/ui-msrv/transmute-ref-dst-generic.stderr b/tests/ui-msrv/transmute-ref-dst-generic.stderr
new file mode 100644
index 0000000..ec7ec74
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-dst-generic.rs:17:5
+ |
+17 | transmute_ref!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `T` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-dst-generic.rs:17:5
+ |
+17 | transmute_ref!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<u8>` (8 bits)
+ = note: target type: `MaxAlignsOf<u8, T>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-dst-mutable.rs b/tests/ui-msrv/transmute-ref-dst-mutable.rs
new file mode 100644
index 0000000..fa0e6e4
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-mutable.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+fn ref_dst_mutable() {
+ // `transmute_ref!` requires that its destination type be an immutable
+ // reference.
+ let _: &mut u8 = transmute_ref!(&0u8);
+}
diff --git a/tests/ui-msrv/transmute-ref-dst-mutable.stderr b/tests/ui-msrv/transmute-ref-dst-mutable.stderr
new file mode 100644
index 0000000..5ccf2cd
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-mutable.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-dst-not-a-reference.rs b/tests/ui-msrv/transmute-ref-dst-not-a-reference.rs
new file mode 100644
index 0000000..de55f9a
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting into a non-reference
+// destination type.
+const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
diff --git a/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr b/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr
new file mode 100644
index 0000000..9a61c4c
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-dst-not-frombytes.rs b/tests/ui-msrv/transmute-ref-dst-not-frombytes.rs
new file mode 100644
index 0000000..d81f64d
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-not-frombytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
diff --git a/tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr b/tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr
new file mode 100644
index 0000000..d317675
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-not-frombytes.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
+ --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:18:42
+ |
+18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy`
+ |
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:18:42
+ |
+18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-dst-unsized.rs b/tests/ui-msrv/transmute-ref-dst-unsized.rs
new file mode 100644
index 0000000..625f1fa
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting into an unsized destination
+// type.
+const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
diff --git a/tests/ui-msrv/transmute-ref-dst-unsized.stderr b/tests/ui-msrv/transmute-ref-dst-unsized.stderr
new file mode 100644
index 0000000..78135de
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-dst-unsized.stderr
@@ -0,0 +1,94 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<T, U>(e: T) -> U;
+ | ^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-illegal-lifetime.rs b/tests/ui-msrv/transmute-ref-illegal-lifetime.rs
new file mode 100644
index 0000000..8dd191e
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-illegal-lifetime.rs
@@ -0,0 +1,15 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+fn main() {}
+
+fn increase_lifetime() {
+ let x = 0u64;
+ // It is illegal to increase the lifetime scope.
+ let _: &'static u64 = zerocopy::transmute_ref!(&x);
+}
diff --git a/tests/ui-msrv/transmute-ref-illegal-lifetime.stderr b/tests/ui-msrv/transmute-ref-illegal-lifetime.stderr
new file mode 100644
index 0000000..866ea56
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-illegal-lifetime.stderr
@@ -0,0 +1,9 @@
+error[E0597]: `x` does not live long enough
+ --> tests/ui-msrv/transmute-ref-illegal-lifetime.rs:14:52
+ |
+14 | let _: &'static u64 = zerocopy::transmute_ref!(&x);
+ | ------------ ^^ borrowed value does not live long enough
+ | |
+ | type annotation requires that `x` is borrowed for `'static`
+15 | }
+ | - `x` dropped here while still borrowed
diff --git a/tests/ui-msrv/transmute-ref-size-decrease.rs b/tests/ui-msrv/transmute-ref-size-decrease.rs
new file mode 100644
index 0000000..1d66a54
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-size-decrease.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// Although this is not a soundness requirement, we currently require that the
+// size of the destination type is not smaller than the size of the source type.
+const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]);
diff --git a/tests/ui-msrv/transmute-ref-size-decrease.stderr b/tests/ui-msrv/transmute-ref-size-decrease.stderr
new file mode 100644
index 0000000..95669f9
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-size-decrease.rs:17:28
+ |
+17 | const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 2]` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-size-increase.rs b/tests/ui-msrv/transmute-ref-size-increase.rs
new file mode 100644
index 0000000..cdca560
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-size-increase.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8);
diff --git a/tests/ui-msrv/transmute-ref-size-increase.stderr b/tests/ui-msrv/transmute-ref-size-increase.stderr
new file mode 100644
index 0000000..10f0e10
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-size-increase.rs:17:33
+ |
+17 | const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `[u8; 2]` (16 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-src-dst-generic.rs b/tests/ui-msrv/transmute-ref-src-dst-generic.rs
new file mode 100644
index 0000000..409d785
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-dst-generic.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_ref<T: AsBytes, U: FromBytes>(t: &T) -> &U {
+ // `transmute_ref!` requires the source and destination types to be
+ // concrete.
+ transmute_ref!(t)
+}
diff --git a/tests/ui-msrv/transmute-ref-src-dst-generic.stderr b/tests/ui-msrv/transmute-ref-src-dst-generic.stderr
new file mode 100644
index 0000000..eb3268f
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-src-dst-generic.rs:18:5
+ |
+18 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `U` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-src-dst-generic.rs:18:5
+ |
+18 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, U>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-src-dst-not-references.rs b/tests/ui-msrv/transmute-ref-src-dst-not-references.rs
new file mode 100644
index 0000000..114e917
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-dst-not-references.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting between non-reference source
+// and destination types.
+const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
diff --git a/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr b/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr
new file mode 100644
index 0000000..2c5e23b
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr
@@ -0,0 +1,42 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-src-dst-not-references.rs:17:54
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected reference, found `usize`
+ | | help: consider borrowing here: `&0usize`
+ | expected due to this
+ |
+ = note: expected reference `&_`
+ found type `usize`
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-src-dst-unsized.rs b/tests/ui-msrv/transmute-ref-src-dst-unsized.rs
new file mode 100644
index 0000000..6bfe7ff
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting between unsized source and
+// destination types.
+const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
diff --git a/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr b/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr
new file mode 100644
index 0000000..adfd597
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-dst-unsized.stderr
@@ -0,0 +1,195 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<T, U>(e: T) -> U;
+ | ^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all function arguments must have a statically known size
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-src-generic.rs b/tests/ui-msrv/transmute-ref-src-generic.rs
new file mode 100644
index 0000000..010281c
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, AsBytes};
+
+fn main() {}
+
+fn transmute_ref<T: AsBytes>(t: &T) -> &u8 {
+ // `transmute_ref!` requires the source type to be concrete.
+ transmute_ref!(t)
+}
diff --git a/tests/ui-msrv/transmute-ref-src-generic.stderr b/tests/ui-msrv/transmute-ref-src-generic.stderr
new file mode 100644
index 0000000..4cb3e51
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-src-generic.rs:17:5
+ |
+17 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-ref-src-generic.rs:17:5
+ |
+17 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, u8>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-src-not-a-reference.rs b/tests/ui-msrv/transmute-ref-src-not-a-reference.rs
new file mode 100644
index 0000000..90661b3
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a non-reference source
+// type.
+const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize);
diff --git a/tests/ui-msrv/transmute-ref-src-not-a-reference.stderr b/tests/ui-msrv/transmute-ref-src-not-a-reference.stderr
new file mode 100644
index 0000000..0f4aeec
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-not-a-reference.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+ --> tests/ui-msrv/transmute-ref-src-not-a-reference.rs:17:49
+ |
+17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected reference, found `usize`
+ | | help: consider borrowing here: `&0usize`
+ | expected due to this
+ |
+ = note: expected reference `&_`
+ found type `usize`
diff --git a/tests/ui-msrv/transmute-ref-src-not-asbytes.rs b/tests/ui-msrv/transmute-ref-src-not-asbytes.rs
new file mode 100644
index 0000000..6ab19f3
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-not-asbytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
diff --git a/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr b/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr
new file mode 100644
index 0000000..6b80d4f
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-not-asbytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-ref-src-unsized.rs b/tests/ui-msrv/transmute-ref-src-unsized.rs
new file mode 100644
index 0000000..14e72b4
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-unsized.rs
@@ -0,0 +1,16 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from an unsized source type.
+const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
diff --git a/tests/ui-msrv/transmute-ref-src-unsized.stderr b/tests/ui-msrv/transmute-ref-src-unsized.stderr
new file mode 100644
index 0000000..43bac53
--- /dev/null
+++ b/tests/ui-msrv/transmute-ref-src-unsized.stderr
@@ -0,0 +1,170 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<T, U>(e: T) -> U;
+ | ^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all function arguments must have a statically known size
+ = note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-size-decrease.rs b/tests/ui-msrv/transmute-size-decrease.rs
new file mode 100644
index 0000000..1d56831
--- /dev/null
+++ b/tests/ui-msrv/transmute-size-decrease.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// Although this is not a soundness requirement, we currently require that the
+// size of the destination type is not smaller than the size of the source type.
+const DECREASE_SIZE: u8 = transmute!(AU16(0));
diff --git a/tests/ui-msrv/transmute-size-decrease.stderr b/tests/ui-msrv/transmute-size-decrease.stderr
new file mode 100644
index 0000000..ffa5688
--- /dev/null
+++ b/tests/ui-msrv/transmute-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-size-decrease.rs:19:27
+ |
+19 | const DECREASE_SIZE: u8 = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AU16` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-size-increase.rs b/tests/ui-msrv/transmute-size-increase.rs
new file mode 100644
index 0000000..32f9363
--- /dev/null
+++ b/tests/ui-msrv/transmute-size-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: AU16 = transmute!(0u8);
diff --git a/tests/ui-msrv/transmute-size-increase.stderr b/tests/ui-msrv/transmute-size-increase.stderr
new file mode 100644
index 0000000..865d0ca
--- /dev/null
+++ b/tests/ui-msrv/transmute-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-msrv/transmute-size-increase.rs:19:29
+ |
+19 | const INCREASE_SIZE: AU16 = transmute!(0u8);
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `AU16` (16 bits)
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-msrv/transmute-src-not-asbytes.rs b/tests/ui-msrv/transmute-src-not-asbytes.rs
new file mode 100644
index 0000000..dd73021
--- /dev/null
+++ b/tests/ui-msrv/transmute-src-not-asbytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
diff --git a/tests/ui-msrv/transmute-src-not-asbytes.stderr b/tests/ui-msrv/transmute-src-not-asbytes.stderr
new file mode 100644
index 0000000..93eeda0
--- /dev/null
+++ b/tests/ui-msrv/transmute-src-not-asbytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-msrv/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/include_value_not_from_bytes.rs b/tests/ui-nightly/include_value_not_from_bytes.rs
new file mode 100644
index 0000000..45b6138
--- /dev/null
+++ b/tests/ui-nightly/include_value_not_from_bytes.rs
@@ -0,0 +1,12 @@
+// Copyright 2022 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#[macro_use]
+extern crate zerocopy;
+
+fn main() {}
+
+// Should fail because `UnsafeCell<u32>: !FromBytes`.
+const NOT_FROM_BYTES: core::cell::UnsafeCell<u32> =
+ include_value!("../../testdata/include_value/data");
diff --git a/tests/ui-nightly/include_value_not_from_bytes.stderr b/tests/ui-nightly/include_value_not_from_bytes.stderr
new file mode 100644
index 0000000..d948a0d
--- /dev/null
+++ b/tests/ui-nightly/include_value_not_from_bytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `UnsafeCell<u32>: FromBytes` is not satisfied
+ --> tests/ui-nightly/include_value_not_from_bytes.rs:12:5
+ |
+12 | include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `UnsafeCell<u32>`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-nightly/include_value_not_from_bytes.rs:12:5
+ |
+12 | include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = 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)
diff --git a/tests/ui-stable/transmute-illegal.rs b/tests/ui-nightly/include_value_wrong_size.rs
index 74b8439..d87b306 100644
--- a/tests/ui-stable/transmute-illegal.rs
+++ b/tests/ui-nightly/include_value_wrong_size.rs
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#[macro_use]
extern crate zerocopy;
fn main() {}
-// It is unsound to inspect the usize value of a pointer during const eval.
-const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
+// Should fail because the file is 4 bytes long, not 8.
+const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");
diff --git a/tests/ui-nightly/include_value_wrong_size.stderr b/tests/ui-nightly/include_value_wrong_size.stderr
new file mode 100644
index 0000000..f592ece
--- /dev/null
+++ b/tests/ui-nightly/include_value_wrong_size.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/include_value_wrong_size.rs:11:25
+ |
+11 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 4]` (32 bits)
+ = note: target type: `u64` (64 bits)
+ = 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)
diff --git a/tests/ui-nightly/invalid-impls/invalid-impls.rs b/tests/ui-nightly/invalid-impls/invalid-impls.rs
index b9a60bd..ea96390 100644
--- a/tests/ui-nightly/invalid-impls/invalid-impls.rs
+++ b/tests/ui-nightly/invalid-impls/invalid-impls.rs
@@ -1,6 +1,10 @@
-// Copyright 2022 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
// Since some macros from `macros.rs` are unused.
#![allow(unused)]
diff --git a/tests/ui-nightly/invalid-impls/invalid-impls.stderr b/tests/ui-nightly/invalid-impls/invalid-impls.stderr
index 7d839ac..e5651d1 100644
--- a/tests/ui-nightly/invalid-impls/invalid-impls.stderr
+++ b/tests/ui-nightly/invalid-impls/invalid-impls.stderr
@@ -1,13 +1,13 @@
error[E0277]: the trait bound `T: zerocopy::FromZeroes` is not satisfied
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:37
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:26:37
|
-22 | impl_or_verify!(T => FromZeroes for Foo<T>);
+26 | impl_or_verify!(T => FromZeroes for Foo<T>);
| ^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::FromZeroes`
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:18:10
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:10
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-nightly/invalid-impls/../../../src/macros.rs
@@ -15,26 +15,26 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:22:1
+ ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:26:1
|
-22 | impl_or_verify!(T => FromZeroes for Foo<T>);
+26 | impl_or_verify!(T => FromZeroes for Foo<T>);
| ------------------------------------------- in this macro invocation
= note: this error originates in the derive macro `FromZeroes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-22 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo<T>);
- | ++++++++++++++++++++++
+ |
+26 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo<T>);
+ | ++++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:23:36
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:27:36
|
-23 | impl_or_verify!(T => FromBytes for Foo<T>);
+27 | impl_or_verify!(T => FromBytes for Foo<T>);
| ^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::FromBytes`
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:18:22
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:22
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-nightly/invalid-impls/../../../src/macros.rs
@@ -42,26 +42,26 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:23:1
+ ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:27:1
|
-23 | impl_or_verify!(T => FromBytes for Foo<T>);
+27 | impl_or_verify!(T => FromBytes for Foo<T>);
| ------------------------------------------ in this macro invocation
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-23 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo<T>);
- | +++++++++++++++++++++
+ |
+27 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo<T>);
+ | +++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:24:34
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:28:34
|
-24 | impl_or_verify!(T => AsBytes for Foo<T>);
+28 | impl_or_verify!(T => AsBytes for Foo<T>);
| ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::AsBytes`
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:18:33
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:33
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-nightly/invalid-impls/../../../src/macros.rs
@@ -69,26 +69,26 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:24:1
+ ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:28:1
|
-24 | impl_or_verify!(T => AsBytes for Foo<T>);
+28 | impl_or_verify!(T => AsBytes for Foo<T>);
| ---------------------------------------- in this macro invocation
= note: this error originates in the derive macro `AsBytes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-24 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo<T>);
- | +++++++++++++++++++
+ |
+28 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo<T>);
+ | +++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:25:36
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:29:36
|
-25 | impl_or_verify!(T => Unaligned for Foo<T>);
+29 | impl_or_verify!(T => Unaligned for Foo<T>);
| ^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::Unaligned`
- --> tests/ui-nightly/invalid-impls/invalid-impls.rs:18:42
+ --> tests/ui-nightly/invalid-impls/invalid-impls.rs:22:42
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-nightly/invalid-impls/../../../src/macros.rs
@@ -96,12 +96,12 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:25:1
+ ::: tests/ui-nightly/invalid-impls/invalid-impls.rs:29:1
|
-25 | impl_or_verify!(T => Unaligned for Foo<T>);
+29 | impl_or_verify!(T => Unaligned for Foo<T>);
| ------------------------------------------ in this macro invocation
= note: this error originates in the derive macro `Unaligned` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-25 | impl_or_verify!(T: zerocopy::Unaligned => Unaligned for Foo<T>);
- | +++++++++++++++++++++
+ |
+29 | impl_or_verify!(T: zerocopy::Unaligned => Unaligned for Foo<T>);
+ | +++++++++++++++++++++
diff --git a/tests/ui-nightly/max-align.rs b/tests/ui-nightly/max-align.rs
new file mode 100644
index 0000000..53e3eb9
--- /dev/null
+++ b/tests/ui-nightly/max-align.rs
@@ -0,0 +1,99 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+#[repr(C, align(1))]
+struct Align1;
+
+#[repr(C, align(2))]
+struct Align2;
+
+#[repr(C, align(4))]
+struct Align4;
+
+#[repr(C, align(8))]
+struct Align8;
+
+#[repr(C, align(16))]
+struct Align16;
+
+#[repr(C, align(32))]
+struct Align32;
+
+#[repr(C, align(64))]
+struct Align64;
+
+#[repr(C, align(128))]
+struct Align128;
+
+#[repr(C, align(256))]
+struct Align256;
+
+#[repr(C, align(512))]
+struct Align512;
+
+#[repr(C, align(1024))]
+struct Align1024;
+
+#[repr(C, align(2048))]
+struct Align2048;
+
+#[repr(C, align(4096))]
+struct Align4096;
+
+#[repr(C, align(8192))]
+struct Align8192;
+
+#[repr(C, align(16384))]
+struct Align16384;
+
+#[repr(C, align(32768))]
+struct Align32768;
+
+#[repr(C, align(65536))]
+struct Align65536;
+
+#[repr(C, align(131072))]
+struct Align131072;
+
+#[repr(C, align(262144))]
+struct Align262144;
+
+#[repr(C, align(524288))]
+struct Align524288;
+
+#[repr(C, align(1048576))]
+struct Align1048576;
+
+#[repr(C, align(2097152))]
+struct Align2097152;
+
+#[repr(C, align(4194304))]
+struct Align4194304;
+
+#[repr(C, align(8388608))]
+struct Align8388608;
+
+#[repr(C, align(16777216))]
+struct Align16777216;
+
+#[repr(C, align(33554432))]
+struct Align33554432;
+
+#[repr(C, align(67108864))]
+struct Align67108864;
+
+#[repr(C, align(134217728))]
+struct Align13421772;
+
+#[repr(C, align(268435456))]
+struct Align26843545;
+
+#[repr(C, align(1073741824))]
+struct Align1073741824;
+
+fn main() {}
diff --git a/tests/ui-nightly/max-align.stderr b/tests/ui-nightly/max-align.stderr
new file mode 100644
index 0000000..0cadb9a
--- /dev/null
+++ b/tests/ui-nightly/max-align.stderr
@@ -0,0 +1,5 @@
+error[E0589]: invalid `repr(align)` attribute: larger than 2^29
+ --> tests/ui-nightly/max-align.rs:96:11
+ |
+96 | #[repr(C, align(1073741824))]
+ | ^^^^^^^^^^^^^^^^^
diff --git a/tests/ui-nightly/transmute-dst-not-frombytes.rs b/tests/ui-nightly/transmute-dst-not-frombytes.rs
new file mode 100644
index 0000000..c4caaff
--- /dev/null
+++ b/tests/ui-nightly/transmute-dst-not-frombytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
diff --git a/tests/ui-nightly/transmute-dst-not-frombytes.stderr b/tests/ui-nightly/transmute-dst-not-frombytes.stderr
new file mode 100644
index 0000000..a9f1f7b
--- /dev/null
+++ b/tests/ui-nightly/transmute-dst-not-frombytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
+ --> tests/ui-nightly/transmute-dst-not-frombytes.rs:18:41
+ |
+18 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `NotZerocopy`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-nightly/transmute-dst-not-frombytes.rs:18:41
+ |
+18 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-illegal.stderr b/tests/ui-nightly/transmute-illegal.stderr
deleted file mode 100644
index a57544b..0000000
--- a/tests/ui-nightly/transmute-illegal.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
- --> tests/ui-nightly/transmute-illegal.rs:10:30
- |
-10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- | |
- | the trait `AsBytes` is not implemented for `*const usize`
- | required by a bound introduced by this call
- |
- = help: the trait `AsBytes` is implemented for `usize`
-note: required by a bound in `POINTER_VALUE::transmute`
- --> tests/ui-nightly/transmute-illegal.rs:10:30
- |
-10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute`
- = note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-alignment-increase.rs b/tests/ui-nightly/transmute-mut-alignment-increase.rs
new file mode 100644
index 0000000..0928564
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-alignment-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a type of smaller
+// alignment to one of larger alignment.
+const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
diff --git a/tests/ui-nightly/transmute-mut-alignment-increase.stderr b/tests/ui-nightly/transmute-mut-alignment-increase.stderr
new file mode 100644
index 0000000..0666f8b
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-alignment-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-mut-alignment-increase.rs:19:39
+ |
+19 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<[u8; 2]>` (8 bits)
+ = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-const.rs b/tests/ui-nightly/transmute-mut-const.rs
new file mode 100644
index 0000000..021b562
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-const.rs
@@ -0,0 +1,20 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+const ARRAY_OF_U8S: [u8; 2] = [0u8; 2];
+
+// `transmute_mut!` cannot, generally speaking, be used in const contexts.
+const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
diff --git a/tests/ui-nightly/transmute-mut-const.stderr b/tests/ui-nightly/transmute-mut-const.stderr
new file mode 100644
index 0000000..fa53ed0
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-const.stderr
@@ -0,0 +1,42 @@
+warning: taking a mutable reference to a `const` item
+ --> tests/ui-nightly/transmute-mut-const.rs:20:52
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: each usage of a `const` item creates a new temporary
+ = note: the mutable reference will refer to this temporary, not the original `const` item
+note: `const` item defined here
+ --> tests/ui-nightly/transmute-mut-const.rs:17:1
+ |
+17 | const ARRAY_OF_U8S: [u8; 2] = [0u8; 2];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `#[warn(const_item_mutation)]` on by default
+
+error[E0658]: mutable references are not allowed in constants
+ --> tests/ui-nightly/transmute-mut-const.rs:20:52
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0015]: cannot call non-const fn `transmute_mut::<'_, '_, [u8; 2], [u8; 2]>` in constants
+ --> tests/ui-nightly/transmute-mut-const.rs:20:37
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0716]: temporary value dropped while borrowed
+ --> tests/ui-nightly/transmute-mut-const.rs:20:57
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | --------------------^^^^^^^^^^^^-
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | temporary value is freed at the end of this statement
+ | using this value as a constant requires that borrow lasts for `'static`
diff --git a/tests/ui-nightly/transmute-mut-dst-generic.rs b/tests/ui-nightly/transmute-mut-dst-generic.rs
new file mode 100644
index 0000000..7068f10
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes>(u: &mut u8) -> &mut T {
+ // `transmute_mut!` requires the destination type to be concrete.
+ transmute_mut!(u)
+}
diff --git a/tests/ui-nightly/transmute-mut-dst-generic.stderr b/tests/ui-nightly/transmute-mut-dst-generic.stderr
new file mode 100644
index 0000000..f278558
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-mut-dst-generic.rs:17:5
+ |
+17 | transmute_mut!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `T` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-mut-dst-generic.rs:17:5
+ |
+17 | transmute_mut!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<u8>` (8 bits)
+ = note: target type: `MaxAlignsOf<u8, T>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-dst-not-a-reference.rs b/tests/ui-nightly/transmute-mut-dst-not-a-reference.rs
new file mode 100644
index 0000000..33a9ecd
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting into a non-reference
+// destination type.
+const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
diff --git a/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr b/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr
new file mode 100644
index 0000000..a84547b
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr
@@ -0,0 +1,39 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs b/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs
new file mode 100644
index 0000000..b72f129
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-not-asbytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the destination type implements `AsBytes`
+const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-nightly/transmute-mut-dst-not-asbytes.stderr b/tests/ui-nightly/transmute-mut-dst-not-asbytes.stderr
new file mode 100644
index 0000000..54c8e60
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-not-asbytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `Dst: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-mut-dst-not-asbytes.rs:24:36
+ |
+24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `Dst`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-dst-not-asbytes.rs:24:36
+ |
+24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs
new file mode 100644
index 0000000..102fced
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-not-frombytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr b/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr
new file mode 100644
index 0000000..ea2123b
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-not-frombytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `Dst: FromBytes` is not satisfied
+ --> tests/ui-nightly/transmute-mut-dst-not-frombytes.rs:24:38
+ |
+24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `Dst`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-dst-not-frombytes.rs:24:38
+ |
+24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-dst-unsized.rs b/tests/ui-nightly/transmute-mut-dst-unsized.rs
new file mode 100644
index 0000000..693ccda
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting into an unsized destination
+// type.
+const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
diff --git a/tests/ui-nightly/transmute-mut-dst-unsized.stderr b/tests/ui-nightly/transmute-mut-dst-unsized.stderr
new file mode 100644
index 0000000..a670e25
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-dst-unsized.stderr
@@ -0,0 +1,86 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-illegal-lifetime.rs b/tests/ui-nightly/transmute-mut-illegal-lifetime.rs
new file mode 100644
index 0000000..c31765e
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-illegal-lifetime.rs
@@ -0,0 +1,15 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+fn main() {}
+
+fn increase_lifetime() {
+ let mut x = 0u64;
+ // It is illegal to increase the lifetime scope.
+ let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x);
+}
diff --git a/tests/ui-nightly/transmute-mut-illegal-lifetime.stderr b/tests/ui-nightly/transmute-mut-illegal-lifetime.stderr
new file mode 100644
index 0000000..b826fcc
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-illegal-lifetime.stderr
@@ -0,0 +1,12 @@
+error[E0597]: `x` does not live long enough
+ --> tests/ui-nightly/transmute-mut-illegal-lifetime.rs:14:56
+ |
+12 | let mut x = 0u64;
+ | ----- binding `x` declared here
+13 | // It is illegal to increase the lifetime scope.
+14 | let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x);
+ | ---------------- ^^^^^^ borrowed value does not live long enough
+ | |
+ | type annotation requires that `x` is borrowed for `'static`
+15 | }
+ | - `x` dropped here while still borrowed
diff --git a/tests/ui-nightly/transmute-mut-size-decrease.rs b/tests/ui-nightly/transmute-mut-size-decrease.rs
new file mode 100644
index 0000000..c6eec3a
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-size-decrease.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// We require that the size of the destination type is not smaller than the size
+// of the source type.
+const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
diff --git a/tests/ui-nightly/transmute-mut-size-decrease.stderr b/tests/ui-nightly/transmute-mut-size-decrease.stderr
new file mode 100644
index 0000000..ac1e35c
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-mut-size-decrease.rs:17:32
+ |
+17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 2]` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-size-increase.rs b/tests/ui-nightly/transmute-mut-size-increase.rs
new file mode 100644
index 0000000..a4657c2
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-size-increase.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
diff --git a/tests/ui-nightly/transmute-mut-size-increase.stderr b/tests/ui-nightly/transmute-mut-size-increase.stderr
new file mode 100644
index 0000000..d343bd6
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-mut-size-increase.rs:17:37
+ |
+17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `[u8; 2]` (16 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-src-dst-generic.rs b/tests/ui-nightly/transmute-mut-src-dst-generic.rs
new file mode 100644
index 0000000..aed7ded
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-dst-generic.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes, U: AsBytes + FromBytes>(t: &mut T) -> &mut U {
+ // `transmute_mut!` requires the source and destination types to be
+ // concrete.
+ transmute_mut!(t)
+}
diff --git a/tests/ui-nightly/transmute-mut-src-dst-generic.stderr b/tests/ui-nightly/transmute-mut-src-dst-generic.stderr
new file mode 100644
index 0000000..e3f3a3f
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-mut-src-dst-generic.rs:18:5
+ |
+18 | transmute_mut!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `U` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-mut-src-dst-generic.rs:18:5
+ |
+18 | transmute_mut!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, U>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-src-dst-not-references.rs b/tests/ui-nightly/transmute-mut-src-dst-not-references.rs
new file mode 100644
index 0000000..98cc520
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-dst-not-references.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting between non-reference source
+// and destination types.
+const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize);
diff --git a/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr b/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr
new file mode 100644
index 0000000..df3cf2d
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-dst-not-references.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-mut-src-dst-not-references.rs:17:59
+ |
+17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&mut _`, found `usize`
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found type `usize`
+help: consider mutably borrowing here
+ |
+17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(&mut 0usize);
+ | ++++
diff --git a/tests/ui-nightly/transmute-mut-src-dst-unsized.rs b/tests/ui-nightly/transmute-mut-src-dst-unsized.rs
new file mode 100644
index 0000000..1bebcf2
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting between unsized source and
+// destination types.
+const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
diff --git a/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr b/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr
new file mode 100644
index 0000000..0f41a42
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-dst-unsized.stderr
@@ -0,0 +1,231 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-src-generic.rs b/tests/ui-nightly/transmute-mut-src-generic.rs
new file mode 100644
index 0000000..a3ef397
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes>(t: &mut T) -> &mut u8 {
+ // `transmute_mut!` requires the source type to be concrete.
+ transmute_mut!(t)
+}
diff --git a/tests/ui-nightly/transmute-mut-src-generic.stderr b/tests/ui-nightly/transmute-mut-src-generic.stderr
new file mode 100644
index 0000000..c06d775
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-generic.stderr
@@ -0,0 +1,10 @@
+error[E0405]: cannot find trait `FromBytes` in this scope
+ --> tests/ui-nightly/transmute-mut-src-generic.rs:15:31
+ |
+15 | fn transmute_mut<T: AsBytes + FromBytes>(t: &mut T) -> &mut u8 {
+ | ^^^^^^^^^ not found in this scope
+ |
+help: consider importing this trait
+ |
+11 + use zerocopy::FromBytes;
+ |
diff --git a/tests/ui-nightly/transmute-mut-src-immutable.rs b/tests/ui-nightly/transmute-mut-src-immutable.rs
new file mode 100644
index 0000000..08088d0
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-immutable.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+fn ref_src_immutable() {
+ // `transmute_mut!` requires that its source type be a mutable reference.
+ let _: &mut u8 = transmute_mut!(&0u8);
+}
diff --git a/tests/ui-nightly/transmute-mut-src-immutable.stderr b/tests/ui-nightly/transmute-mut-src-immutable.stderr
new file mode 100644
index 0000000..7b7969d
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-immutable.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-mut-src-immutable.rs:17:37
+ |
+17 | let _: &mut u8 = transmute_mut!(&0u8);
+ | ---------------^^^^-
+ | | |
+ | | types differ in mutability
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found reference `&u8`
diff --git a/tests/ui-nightly/transmute-mut-src-not-a-reference.rs b/tests/ui-nightly/transmute-mut-src-not-a-reference.rs
new file mode 100644
index 0000000..bf8bc32
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a non-reference source
+// type.
+const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize);
diff --git a/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr b/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr
new file mode 100644
index 0000000..12b7674
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-not-a-reference.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-mut-src-not-a-reference.rs:17:53
+ |
+17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&mut _`, found `usize`
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found type `usize`
+help: consider mutably borrowing here
+ |
+17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(&mut 0usize);
+ | ++++
diff --git a/tests/ui-nightly/transmute-mut-src-not-asbytes.rs b/tests/ui-nightly/transmute-mut-src-not-asbytes.rs
new file mode 100644
index 0000000..6a14f12
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-not-asbytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-nightly/transmute-mut-src-not-asbytes.stderr b/tests/ui-nightly/transmute-mut-src-not-asbytes.stderr
new file mode 100644
index 0000000..b755d3c
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-not-asbytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `Src: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `Src`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `Src: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src`
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-src-not-frombytes.rs b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs
new file mode 100644
index 0000000..2ebe036
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-not-frombytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the source type implements `FromBytes`
+const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr b/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr
new file mode 100644
index 0000000..5a9f0a7
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-not-frombytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `Src: FromBytes` is not satisfied
+ --> tests/ui-nightly/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `Src`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `Src: FromBytes` is not satisfied
+ --> tests/ui-nightly/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src`
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-mut-src-unsized.rs b/tests/ui-nightly/transmute-mut-src-unsized.rs
new file mode 100644
index 0000000..413dd68
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-unsized.rs
@@ -0,0 +1,16 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from an unsized source type.
+const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
diff --git a/tests/ui-nightly/transmute-mut-src-unsized.stderr b/tests/ui-nightly/transmute-mut-src-unsized.stderr
new file mode 100644
index 0000000..99475ad
--- /dev/null
+++ b/tests/ui-nightly/transmute-mut-src-unsized.stderr
@@ -0,0 +1,158 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ptr-to-usize.rs b/tests/ui-nightly/transmute-ptr-to-usize.rs
new file mode 100644
index 0000000..5af8859
--- /dev/null
+++ b/tests/ui-nightly/transmute-ptr-to-usize.rs
@@ -0,0 +1,20 @@
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// It is unclear whether we can or should support this transmutation, especially
+// in a const context. This test ensures that even if such a transmutation
+// becomes valid due to the requisite implementations of `FromBytes` being
+// added, that we re-examine whether it should specifically be valid in a const
+// context.
+const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
diff --git a/tests/ui-nightly/transmute-ptr-to-usize.stderr b/tests/ui-nightly/transmute-ptr-to-usize.stderr
new file mode 100644
index 0000000..2fcba2f
--- /dev/null
+++ b/tests/ui-nightly/transmute-ptr-to-usize.stderr
@@ -0,0 +1,30 @@
+error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `*const usize`
+ | required by a bound introduced by this call
+ |
+ = help: the trait `AsBytes` is implemented for `usize`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize`
+ |
+ = help: the trait `AsBytes` is implemented for `usize`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-alignment-increase.rs b/tests/ui-nightly/transmute-ref-alignment-increase.rs
new file mode 100644
index 0000000..bf1988c
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-alignment-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a type of smaller
+// alignment to one of larger alignment.
+const INCREASE_ALIGNMENT: &AU16 = transmute_ref!(&[0u8; 2]);
diff --git a/tests/ui-nightly/transmute-ref-alignment-increase.stderr b/tests/ui-nightly/transmute-ref-alignment-increase.stderr
new file mode 100644
index 0000000..1cef246
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-alignment-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-alignment-increase.rs:19:35
+ |
+19 | const INCREASE_ALIGNMENT: &AU16 = transmute_ref!(&[0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<[u8; 2]>` (8 bits)
+ = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-dst-generic.rs b/tests/ui-nightly/transmute-ref-dst-generic.rs
new file mode 100644
index 0000000..bf4a0f9
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, FromBytes};
+
+fn main() {}
+
+fn transmute_ref<T: FromBytes>(u: &u8) -> &T {
+ // `transmute_ref!` requires the destination type to be concrete.
+ transmute_ref!(u)
+}
diff --git a/tests/ui-nightly/transmute-ref-dst-generic.stderr b/tests/ui-nightly/transmute-ref-dst-generic.stderr
new file mode 100644
index 0000000..4c94d50
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-dst-generic.rs:17:5
+ |
+17 | transmute_ref!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `T` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-dst-generic.rs:17:5
+ |
+17 | transmute_ref!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<u8>` (8 bits)
+ = note: target type: `MaxAlignsOf<u8, T>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-dst-mutable.rs b/tests/ui-nightly/transmute-ref-dst-mutable.rs
new file mode 100644
index 0000000..fa0e6e4
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-mutable.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+fn ref_dst_mutable() {
+ // `transmute_ref!` requires that its destination type be an immutable
+ // reference.
+ let _: &mut u8 = transmute_ref!(&0u8);
+}
diff --git a/tests/ui-nightly/transmute-ref-dst-mutable.stderr b/tests/ui-nightly/transmute-ref-dst-mutable.stderr
new file mode 100644
index 0000000..0cbdd17
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-mutable.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-dst-not-a-reference.rs b/tests/ui-nightly/transmute-ref-dst-not-a-reference.rs
new file mode 100644
index 0000000..de55f9a
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting into a non-reference
+// destination type.
+const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
diff --git a/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr b/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr
new file mode 100644
index 0000000..847d547
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-dst-not-frombytes.rs b/tests/ui-nightly/transmute-ref-dst-not-frombytes.rs
new file mode 100644
index 0000000..d81f64d
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-not-frombytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
diff --git a/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr b/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr
new file mode 100644
index 0000000..e4791d7
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-not-frombytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
+ --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:18:42
+ |
+18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `NotZerocopy`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-nightly/transmute-ref-dst-not-frombytes.rs:18:42
+ |
+18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-dst-unsized.rs b/tests/ui-nightly/transmute-ref-dst-unsized.rs
new file mode 100644
index 0000000..625f1fa
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting into an unsized destination
+// type.
+const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
diff --git a/tests/ui-nightly/transmute-ref-dst-unsized.stderr b/tests/ui-nightly/transmute-ref-dst-unsized.stderr
new file mode 100644
index 0000000..3d0f6d0
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-dst-unsized.stderr
@@ -0,0 +1,69 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-illegal-lifetime.rs b/tests/ui-nightly/transmute-ref-illegal-lifetime.rs
new file mode 100644
index 0000000..8dd191e
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-illegal-lifetime.rs
@@ -0,0 +1,15 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+fn main() {}
+
+fn increase_lifetime() {
+ let x = 0u64;
+ // It is illegal to increase the lifetime scope.
+ let _: &'static u64 = zerocopy::transmute_ref!(&x);
+}
diff --git a/tests/ui-nightly/transmute-ref-illegal-lifetime.stderr b/tests/ui-nightly/transmute-ref-illegal-lifetime.stderr
new file mode 100644
index 0000000..e16a557
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-illegal-lifetime.stderr
@@ -0,0 +1,12 @@
+error[E0597]: `x` does not live long enough
+ --> tests/ui-nightly/transmute-ref-illegal-lifetime.rs:14:52
+ |
+12 | let x = 0u64;
+ | - binding `x` declared here
+13 | // It is illegal to increase the lifetime scope.
+14 | let _: &'static u64 = zerocopy::transmute_ref!(&x);
+ | ------------ ^^ borrowed value does not live long enough
+ | |
+ | type annotation requires that `x` is borrowed for `'static`
+15 | }
+ | - `x` dropped here while still borrowed
diff --git a/tests/ui-nightly/transmute-ref-size-decrease.rs b/tests/ui-nightly/transmute-ref-size-decrease.rs
new file mode 100644
index 0000000..1d66a54
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-size-decrease.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// Although this is not a soundness requirement, we currently require that the
+// size of the destination type is not smaller than the size of the source type.
+const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]);
diff --git a/tests/ui-nightly/transmute-ref-size-decrease.stderr b/tests/ui-nightly/transmute-ref-size-decrease.stderr
new file mode 100644
index 0000000..793ecc5
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-size-decrease.rs:17:28
+ |
+17 | const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 2]` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-size-increase.rs b/tests/ui-nightly/transmute-ref-size-increase.rs
new file mode 100644
index 0000000..cdca560
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-size-increase.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8);
diff --git a/tests/ui-nightly/transmute-ref-size-increase.stderr b/tests/ui-nightly/transmute-ref-size-increase.stderr
new file mode 100644
index 0000000..40c69f6
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-size-increase.rs:17:33
+ |
+17 | const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `[u8; 2]` (16 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-src-dst-generic.rs b/tests/ui-nightly/transmute-ref-src-dst-generic.rs
new file mode 100644
index 0000000..409d785
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-dst-generic.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_ref<T: AsBytes, U: FromBytes>(t: &T) -> &U {
+ // `transmute_ref!` requires the source and destination types to be
+ // concrete.
+ transmute_ref!(t)
+}
diff --git a/tests/ui-nightly/transmute-ref-src-dst-generic.stderr b/tests/ui-nightly/transmute-ref-src-dst-generic.stderr
new file mode 100644
index 0000000..6a3a4fd
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-src-dst-generic.rs:18:5
+ |
+18 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `U` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-src-dst-generic.rs:18:5
+ |
+18 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, U>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-src-dst-not-references.rs b/tests/ui-nightly/transmute-ref-src-dst-not-references.rs
new file mode 100644
index 0000000..114e917
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-dst-not-references.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting between non-reference source
+// and destination types.
+const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
diff --git a/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr b/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr
new file mode 100644
index 0000000..0f1f7fc
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr
@@ -0,0 +1,45 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:54
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&_`, found `usize`
+ | expected due to this
+ |
+ = note: expected reference `&_`
+ found type `usize`
+help: consider borrowing here
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(&0usize);
+ | +
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-src-dst-unsized.rs b/tests/ui-nightly/transmute-ref-src-dst-unsized.rs
new file mode 100644
index 0000000..6bfe7ff
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting between unsized source and
+// destination types.
+const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
diff --git a/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr b/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr
new file mode 100644
index 0000000..02e62bc
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-dst-unsized.stderr
@@ -0,0 +1,183 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-src-generic.rs b/tests/ui-nightly/transmute-ref-src-generic.rs
new file mode 100644
index 0000000..010281c
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, AsBytes};
+
+fn main() {}
+
+fn transmute_ref<T: AsBytes>(t: &T) -> &u8 {
+ // `transmute_ref!` requires the source type to be concrete.
+ transmute_ref!(t)
+}
diff --git a/tests/ui-nightly/transmute-ref-src-generic.stderr b/tests/ui-nightly/transmute-ref-src-generic.stderr
new file mode 100644
index 0000000..a168f44
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-src-generic.rs:17:5
+ |
+17 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-ref-src-generic.rs:17:5
+ |
+17 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, u8>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-src-not-a-reference.rs b/tests/ui-nightly/transmute-ref-src-not-a-reference.rs
new file mode 100644
index 0000000..90661b3
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a non-reference source
+// type.
+const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize);
diff --git a/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr b/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr
new file mode 100644
index 0000000..be477c6
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-not-a-reference.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> tests/ui-nightly/transmute-ref-src-not-a-reference.rs:17:49
+ |
+17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&_`, found `usize`
+ | expected due to this
+ |
+ = note: expected reference `&_`
+ found type `usize`
+help: consider borrowing here
+ |
+17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(&0usize);
+ | +
diff --git a/tests/ui-nightly/transmute-ref-src-not-asbytes.rs b/tests/ui-nightly/transmute-ref-src-not-asbytes.rs
new file mode 100644
index 0000000..6ab19f3
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-not-asbytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
diff --git a/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr b/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr
new file mode 100644
index 0000000..eb28ccf
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-not-asbytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-ref-src-unsized.rs b/tests/ui-nightly/transmute-ref-src-unsized.rs
new file mode 100644
index 0000000..14e72b4
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-unsized.rs
@@ -0,0 +1,16 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from an unsized source type.
+const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
diff --git a/tests/ui-nightly/transmute-ref-src-unsized.stderr b/tests/ui-nightly/transmute-ref-src-unsized.stderr
new file mode 100644
index 0000000..b280429
--- /dev/null
+++ b/tests/ui-nightly/transmute-ref-src-unsized.stderr
@@ -0,0 +1,127 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-nightly/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-size-decrease.rs b/tests/ui-nightly/transmute-size-decrease.rs
new file mode 100644
index 0000000..1d56831
--- /dev/null
+++ b/tests/ui-nightly/transmute-size-decrease.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// Although this is not a soundness requirement, we currently require that the
+// size of the destination type is not smaller than the size of the source type.
+const DECREASE_SIZE: u8 = transmute!(AU16(0));
diff --git a/tests/ui-nightly/transmute-size-decrease.stderr b/tests/ui-nightly/transmute-size-decrease.stderr
new file mode 100644
index 0000000..83742d7
--- /dev/null
+++ b/tests/ui-nightly/transmute-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-size-decrease.rs:19:27
+ |
+19 | const DECREASE_SIZE: u8 = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AU16` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-size-increase.rs b/tests/ui-nightly/transmute-size-increase.rs
new file mode 100644
index 0000000..32f9363
--- /dev/null
+++ b/tests/ui-nightly/transmute-size-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: AU16 = transmute!(0u8);
diff --git a/tests/ui-nightly/transmute-size-increase.stderr b/tests/ui-nightly/transmute-size-increase.stderr
new file mode 100644
index 0000000..230bb17
--- /dev/null
+++ b/tests/ui-nightly/transmute-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-nightly/transmute-size-increase.rs:19:29
+ |
+19 | const INCREASE_SIZE: AU16 = transmute!(0u8);
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `AU16` (16 bits)
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-nightly/transmute-src-not-asbytes.rs b/tests/ui-nightly/transmute-src-not-asbytes.rs
new file mode 100644
index 0000000..dd73021
--- /dev/null
+++ b/tests/ui-nightly/transmute-src-not-asbytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
diff --git a/tests/ui-nightly/transmute-src-not-asbytes.stderr b/tests/ui-nightly/transmute-src-not-asbytes.stderr
new file mode 100644
index 0000000..b36a820
--- /dev/null
+++ b/tests/ui-nightly/transmute-src-not-asbytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-nightly/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/include_value_not_from_bytes.rs b/tests/ui-stable/include_value_not_from_bytes.rs
new file mode 100644
index 0000000..45b6138
--- /dev/null
+++ b/tests/ui-stable/include_value_not_from_bytes.rs
@@ -0,0 +1,12 @@
+// Copyright 2022 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#[macro_use]
+extern crate zerocopy;
+
+fn main() {}
+
+// Should fail because `UnsafeCell<u32>: !FromBytes`.
+const NOT_FROM_BYTES: core::cell::UnsafeCell<u32> =
+ include_value!("../../testdata/include_value/data");
diff --git a/tests/ui-stable/include_value_not_from_bytes.stderr b/tests/ui-stable/include_value_not_from_bytes.stderr
new file mode 100644
index 0000000..7e9a035
--- /dev/null
+++ b/tests/ui-stable/include_value_not_from_bytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `UnsafeCell<u32>: FromBytes` is not satisfied
+ --> tests/ui-stable/include_value_not_from_bytes.rs:12:5
+ |
+12 | include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `UnsafeCell<u32>`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-stable/include_value_not_from_bytes.rs:12:5
+ |
+12 | include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = 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)
diff --git a/tests/ui-nightly/transmute-illegal.rs b/tests/ui-stable/include_value_wrong_size.rs
index 74b8439..d87b306 100644
--- a/tests/ui-nightly/transmute-illegal.rs
+++ b/tests/ui-stable/include_value_wrong_size.rs
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#[macro_use]
extern crate zerocopy;
fn main() {}
-// It is unsound to inspect the usize value of a pointer during const eval.
-const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
+// Should fail because the file is 4 bytes long, not 8.
+const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");
diff --git a/tests/ui-stable/include_value_wrong_size.stderr b/tests/ui-stable/include_value_wrong_size.stderr
new file mode 100644
index 0000000..956d74c
--- /dev/null
+++ b/tests/ui-stable/include_value_wrong_size.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/include_value_wrong_size.rs:11:25
+ |
+11 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 4]` (32 bits)
+ = note: target type: `u64` (64 bits)
+ = 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)
diff --git a/tests/ui-stable/invalid-impls/invalid-impls.rs b/tests/ui-stable/invalid-impls/invalid-impls.rs
index b9a60bd..ea96390 100644
--- a/tests/ui-stable/invalid-impls/invalid-impls.rs
+++ b/tests/ui-stable/invalid-impls/invalid-impls.rs
@@ -1,6 +1,10 @@
-// Copyright 2022 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
// Since some macros from `macros.rs` are unused.
#![allow(unused)]
diff --git a/tests/ui-stable/invalid-impls/invalid-impls.stderr b/tests/ui-stable/invalid-impls/invalid-impls.stderr
index f613377..7737d67 100644
--- a/tests/ui-stable/invalid-impls/invalid-impls.stderr
+++ b/tests/ui-stable/invalid-impls/invalid-impls.stderr
@@ -1,13 +1,13 @@
error[E0277]: the trait bound `T: zerocopy::FromZeroes` is not satisfied
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:37
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:26:37
|
-22 | impl_or_verify!(T => FromZeroes for Foo<T>);
+26 | impl_or_verify!(T => FromZeroes for Foo<T>);
| ^^^^^^ the trait `zerocopy::FromZeroes` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::FromZeroes`
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:18:10
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:10
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-stable/invalid-impls/../../../src/macros.rs
@@ -15,26 +15,26 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-stable/invalid-impls/invalid-impls.rs:22:1
+ ::: tests/ui-stable/invalid-impls/invalid-impls.rs:26:1
|
-22 | impl_or_verify!(T => FromZeroes for Foo<T>);
+26 | impl_or_verify!(T => FromZeroes for Foo<T>);
| ------------------------------------------- in this macro invocation
= note: this error originates in the derive macro `FromZeroes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-22 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo<T>);
- | ++++++++++++++++++++++
+ |
+26 | impl_or_verify!(T: zerocopy::FromZeroes => FromZeroes for Foo<T>);
+ | ++++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:23:36
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:27:36
|
-23 | impl_or_verify!(T => FromBytes for Foo<T>);
+27 | impl_or_verify!(T => FromBytes for Foo<T>);
| ^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::FromBytes`
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:18:22
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:22
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-stable/invalid-impls/../../../src/macros.rs
@@ -42,26 +42,26 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-stable/invalid-impls/invalid-impls.rs:23:1
+ ::: tests/ui-stable/invalid-impls/invalid-impls.rs:27:1
|
-23 | impl_or_verify!(T => FromBytes for Foo<T>);
+27 | impl_or_verify!(T => FromBytes for Foo<T>);
| ------------------------------------------ in this macro invocation
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-23 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo<T>);
- | +++++++++++++++++++++
+ |
+27 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo<T>);
+ | +++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::AsBytes` is not satisfied
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:24:34
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:28:34
|
-24 | impl_or_verify!(T => AsBytes for Foo<T>);
+28 | impl_or_verify!(T => AsBytes for Foo<T>);
| ^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::AsBytes`
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:18:33
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:33
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-stable/invalid-impls/../../../src/macros.rs
@@ -69,26 +69,26 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-stable/invalid-impls/invalid-impls.rs:24:1
+ ::: tests/ui-stable/invalid-impls/invalid-impls.rs:28:1
|
-24 | impl_or_verify!(T => AsBytes for Foo<T>);
+28 | impl_or_verify!(T => AsBytes for Foo<T>);
| ---------------------------------------- in this macro invocation
= note: this error originates in the derive macro `AsBytes` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-24 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo<T>);
- | +++++++++++++++++++
+ |
+28 | impl_or_verify!(T: zerocopy::AsBytes => AsBytes for Foo<T>);
+ | +++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:25:36
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:29:36
|
-25 | impl_or_verify!(T => Unaligned for Foo<T>);
+29 | impl_or_verify!(T => Unaligned for Foo<T>);
| ^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T`
|
note: required for `Foo<T>` to implement `zerocopy::Unaligned`
- --> tests/ui-stable/invalid-impls/invalid-impls.rs:18:42
+ --> tests/ui-stable/invalid-impls/invalid-impls.rs:22:42
|
-18 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
+22 | #[derive(FromZeroes, FromBytes, AsBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::Subtrait`
--> tests/ui-stable/invalid-impls/../../../src/macros.rs
@@ -96,12 +96,12 @@ note: required by a bound in `_::Subtrait`
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `Subtrait`
|
- ::: tests/ui-stable/invalid-impls/invalid-impls.rs:25:1
+ ::: tests/ui-stable/invalid-impls/invalid-impls.rs:29:1
|
-25 | impl_or_verify!(T => Unaligned for Foo<T>);
+29 | impl_or_verify!(T => Unaligned for Foo<T>);
| ------------------------------------------ in this macro invocation
= note: this error originates in the derive macro `Unaligned` which comes from the expansion of the macro `impl_or_verify` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
- |
-25 | impl_or_verify!(T: zerocopy::Unaligned => Unaligned for Foo<T>);
- | +++++++++++++++++++++
+ |
+29 | impl_or_verify!(T: zerocopy::Unaligned => Unaligned for Foo<T>);
+ | +++++++++++++++++++++
diff --git a/tests/ui-stable/max-align.rs b/tests/ui-stable/max-align.rs
new file mode 100644
index 0000000..53e3eb9
--- /dev/null
+++ b/tests/ui-stable/max-align.rs
@@ -0,0 +1,99 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+#[repr(C, align(1))]
+struct Align1;
+
+#[repr(C, align(2))]
+struct Align2;
+
+#[repr(C, align(4))]
+struct Align4;
+
+#[repr(C, align(8))]
+struct Align8;
+
+#[repr(C, align(16))]
+struct Align16;
+
+#[repr(C, align(32))]
+struct Align32;
+
+#[repr(C, align(64))]
+struct Align64;
+
+#[repr(C, align(128))]
+struct Align128;
+
+#[repr(C, align(256))]
+struct Align256;
+
+#[repr(C, align(512))]
+struct Align512;
+
+#[repr(C, align(1024))]
+struct Align1024;
+
+#[repr(C, align(2048))]
+struct Align2048;
+
+#[repr(C, align(4096))]
+struct Align4096;
+
+#[repr(C, align(8192))]
+struct Align8192;
+
+#[repr(C, align(16384))]
+struct Align16384;
+
+#[repr(C, align(32768))]
+struct Align32768;
+
+#[repr(C, align(65536))]
+struct Align65536;
+
+#[repr(C, align(131072))]
+struct Align131072;
+
+#[repr(C, align(262144))]
+struct Align262144;
+
+#[repr(C, align(524288))]
+struct Align524288;
+
+#[repr(C, align(1048576))]
+struct Align1048576;
+
+#[repr(C, align(2097152))]
+struct Align2097152;
+
+#[repr(C, align(4194304))]
+struct Align4194304;
+
+#[repr(C, align(8388608))]
+struct Align8388608;
+
+#[repr(C, align(16777216))]
+struct Align16777216;
+
+#[repr(C, align(33554432))]
+struct Align33554432;
+
+#[repr(C, align(67108864))]
+struct Align67108864;
+
+#[repr(C, align(134217728))]
+struct Align13421772;
+
+#[repr(C, align(268435456))]
+struct Align26843545;
+
+#[repr(C, align(1073741824))]
+struct Align1073741824;
+
+fn main() {}
diff --git a/tests/ui-stable/max-align.stderr b/tests/ui-stable/max-align.stderr
new file mode 100644
index 0000000..ea472f2
--- /dev/null
+++ b/tests/ui-stable/max-align.stderr
@@ -0,0 +1,5 @@
+error[E0589]: invalid `repr(align)` attribute: larger than 2^29
+ --> tests/ui-stable/max-align.rs:96:11
+ |
+96 | #[repr(C, align(1073741824))]
+ | ^^^^^^^^^^^^^^^^^
diff --git a/tests/ui-stable/transmute-dst-not-frombytes.rs b/tests/ui-stable/transmute-dst-not-frombytes.rs
new file mode 100644
index 0000000..c4caaff
--- /dev/null
+++ b/tests/ui-stable/transmute-dst-not-frombytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
diff --git a/tests/ui-stable/transmute-dst-not-frombytes.stderr b/tests/ui-stable/transmute-dst-not-frombytes.stderr
new file mode 100644
index 0000000..b008bcd
--- /dev/null
+++ b/tests/ui-stable/transmute-dst-not-frombytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
+ --> tests/ui-stable/transmute-dst-not-frombytes.rs:18:41
+ |
+18 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `NotZerocopy`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-stable/transmute-dst-not-frombytes.rs:18:41
+ |
+18 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-illegal.stderr b/tests/ui-stable/transmute-illegal.stderr
deleted file mode 100644
index e9ac240..0000000
--- a/tests/ui-stable/transmute-illegal.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
- --> tests/ui-stable/transmute-illegal.rs:10:30
- |
-10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- | |
- | the trait `AsBytes` is not implemented for `*const usize`
- | required by a bound introduced by this call
- |
- = help: the trait `AsBytes` is implemented for `usize`
-note: required by a bound in `POINTER_VALUE::transmute`
- --> tests/ui-stable/transmute-illegal.rs:10:30
- |
-10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute`
- = note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-alignment-increase.rs b/tests/ui-stable/transmute-mut-alignment-increase.rs
new file mode 100644
index 0000000..0928564
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-alignment-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a type of smaller
+// alignment to one of larger alignment.
+const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
diff --git a/tests/ui-stable/transmute-mut-alignment-increase.stderr b/tests/ui-stable/transmute-mut-alignment-increase.stderr
new file mode 100644
index 0000000..252fec9
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-alignment-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-mut-alignment-increase.rs:19:39
+ |
+19 | const INCREASE_ALIGNMENT: &mut AU16 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<[u8; 2]>` (8 bits)
+ = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-const.rs b/tests/ui-stable/transmute-mut-const.rs
new file mode 100644
index 0000000..021b562
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-const.rs
@@ -0,0 +1,20 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+const ARRAY_OF_U8S: [u8; 2] = [0u8; 2];
+
+// `transmute_mut!` cannot, generally speaking, be used in const contexts.
+const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
diff --git a/tests/ui-stable/transmute-mut-const.stderr b/tests/ui-stable/transmute-mut-const.stderr
new file mode 100644
index 0000000..a89ea67
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-const.stderr
@@ -0,0 +1,41 @@
+warning: taking a mutable reference to a `const` item
+ --> tests/ui-stable/transmute-mut-const.rs:20:52
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: each usage of a `const` item creates a new temporary
+ = note: the mutable reference will refer to this temporary, not the original `const` item
+note: `const` item defined here
+ --> tests/ui-stable/transmute-mut-const.rs:17:1
+ |
+17 | const ARRAY_OF_U8S: [u8; 2] = [0u8; 2];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `#[warn(const_item_mutation)]` on by default
+
+error[E0658]: mutable references are not allowed in constants
+ --> tests/ui-stable/transmute-mut-const.rs:20:52
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+
+error[E0015]: cannot call non-const fn `transmute_mut::<'_, '_, [u8; 2], [u8; 2]>` in constants
+ --> tests/ui-stable/transmute-mut-const.rs:20:37
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0716]: temporary value dropped while borrowed
+ --> tests/ui-stable/transmute-mut-const.rs:20:57
+ |
+20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
+ | --------------------^^^^^^^^^^^^-
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | temporary value is freed at the end of this statement
+ | using this value as a constant requires that borrow lasts for `'static`
diff --git a/tests/ui-stable/transmute-mut-dst-generic.rs b/tests/ui-stable/transmute-mut-dst-generic.rs
new file mode 100644
index 0000000..7068f10
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes>(u: &mut u8) -> &mut T {
+ // `transmute_mut!` requires the destination type to be concrete.
+ transmute_mut!(u)
+}
diff --git a/tests/ui-stable/transmute-mut-dst-generic.stderr b/tests/ui-stable/transmute-mut-dst-generic.stderr
new file mode 100644
index 0000000..0000eb0
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-mut-dst-generic.rs:17:5
+ |
+17 | transmute_mut!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `T` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-mut-dst-generic.rs:17:5
+ |
+17 | transmute_mut!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<u8>` (8 bits)
+ = note: target type: `MaxAlignsOf<u8, T>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-dst-not-a-reference.rs b/tests/ui-stable/transmute-mut-dst-not-a-reference.rs
new file mode 100644
index 0000000..33a9ecd
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting into a non-reference
+// destination type.
+const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
diff --git a/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr b/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr
new file mode 100644
index 0000000..14ee444
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr
@@ -0,0 +1,39 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-mut-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&mut _`
+ |
+ = note: expected type `usize`
+ found mutable reference `&mut _`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-dst-not-asbytes.rs b/tests/ui-stable/transmute-mut-dst-not-asbytes.rs
new file mode 100644
index 0000000..b72f129
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-not-asbytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the destination type implements `AsBytes`
+const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-stable/transmute-mut-dst-not-asbytes.stderr b/tests/ui-stable/transmute-mut-dst-not-asbytes.stderr
new file mode 100644
index 0000000..f3cacca
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-not-asbytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `Dst: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-mut-dst-not-asbytes.rs:24:36
+ |
+24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `Dst`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-stable/transmute-mut-dst-not-asbytes.rs:24:36
+ |
+24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-dst-not-frombytes.rs b/tests/ui-stable/transmute-mut-dst-not-frombytes.rs
new file mode 100644
index 0000000..102fced
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-not-frombytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr b/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr
new file mode 100644
index 0000000..39bb4fd
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-not-frombytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `Dst: FromBytes` is not satisfied
+ --> tests/ui-stable/transmute-mut-dst-not-frombytes.rs:24:38
+ |
+24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `Dst`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-stable/transmute-mut-dst-not-frombytes.rs:24:38
+ |
+24 | const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-dst-unsized.rs b/tests/ui-stable/transmute-mut-dst-unsized.rs
new file mode 100644
index 0000000..693ccda
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting into an unsized destination
+// type.
+const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
diff --git a/tests/ui-stable/transmute-mut-dst-unsized.stderr b/tests/ui-stable/transmute-mut-dst-unsized.stderr
new file mode 100644
index 0000000..0772785
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-dst-unsized.stderr
@@ -0,0 +1,106 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-dst-unsized.rs:17:32
+ |
+17 | const DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-illegal-lifetime.rs b/tests/ui-stable/transmute-mut-illegal-lifetime.rs
new file mode 100644
index 0000000..c31765e
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-illegal-lifetime.rs
@@ -0,0 +1,15 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+fn main() {}
+
+fn increase_lifetime() {
+ let mut x = 0u64;
+ // It is illegal to increase the lifetime scope.
+ let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x);
+}
diff --git a/tests/ui-stable/transmute-mut-illegal-lifetime.stderr b/tests/ui-stable/transmute-mut-illegal-lifetime.stderr
new file mode 100644
index 0000000..7f12813
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-illegal-lifetime.stderr
@@ -0,0 +1,12 @@
+error[E0597]: `x` does not live long enough
+ --> tests/ui-stable/transmute-mut-illegal-lifetime.rs:14:56
+ |
+12 | let mut x = 0u64;
+ | ----- binding `x` declared here
+13 | // It is illegal to increase the lifetime scope.
+14 | let _: &'static mut u64 = zerocopy::transmute_mut!(&mut x);
+ | ---------------- ^^^^^^ borrowed value does not live long enough
+ | |
+ | type annotation requires that `x` is borrowed for `'static`
+15 | }
+ | - `x` dropped here while still borrowed
diff --git a/tests/ui-stable/transmute-mut-size-decrease.rs b/tests/ui-stable/transmute-mut-size-decrease.rs
new file mode 100644
index 0000000..c6eec3a
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-size-decrease.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// We require that the size of the destination type is not smaller than the size
+// of the source type.
+const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
diff --git a/tests/ui-stable/transmute-mut-size-decrease.stderr b/tests/ui-stable/transmute-mut-size-decrease.stderr
new file mode 100644
index 0000000..2399913
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-mut-size-decrease.rs:17:32
+ |
+17 | const DECREASE_SIZE: &mut u8 = transmute_mut!(&mut [0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 2]` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-size-increase.rs b/tests/ui-stable/transmute-mut-size-increase.rs
new file mode 100644
index 0000000..a4657c2
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-size-increase.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
diff --git a/tests/ui-stable/transmute-mut-size-increase.stderr b/tests/ui-stable/transmute-mut-size-increase.stderr
new file mode 100644
index 0000000..1427c7b
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-mut-size-increase.rs:17:37
+ |
+17 | const INCREASE_SIZE: &mut [u8; 2] = transmute_mut!(&mut 0u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `[u8; 2]` (16 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-src-dst-generic.rs b/tests/ui-stable/transmute-mut-src-dst-generic.rs
new file mode 100644
index 0000000..aed7ded
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-dst-generic.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes, U: AsBytes + FromBytes>(t: &mut T) -> &mut U {
+ // `transmute_mut!` requires the source and destination types to be
+ // concrete.
+ transmute_mut!(t)
+}
diff --git a/tests/ui-stable/transmute-mut-src-dst-generic.stderr b/tests/ui-stable/transmute-mut-src-dst-generic.stderr
new file mode 100644
index 0000000..ddb8bb6
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-mut-src-dst-generic.rs:18:5
+ |
+18 | transmute_mut!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `U` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-mut-src-dst-generic.rs:18:5
+ |
+18 | transmute_mut!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, U>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-src-dst-not-references.rs b/tests/ui-stable/transmute-mut-src-dst-not-references.rs
new file mode 100644
index 0000000..98cc520
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-dst-not-references.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting between non-reference source
+// and destination types.
+const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize);
diff --git a/tests/ui-stable/transmute-mut-src-dst-not-references.stderr b/tests/ui-stable/transmute-mut-src-dst-not-references.stderr
new file mode 100644
index 0000000..c0d9e0f
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-dst-not-references.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-mut-src-dst-not-references.rs:17:59
+ |
+17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&mut _`, found `usize`
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found type `usize`
+help: consider mutably borrowing here
+ |
+17 | const SRC_DST_NOT_REFERENCES: &mut usize = transmute_mut!(&mut 0usize);
+ | ++++
diff --git a/tests/ui-stable/transmute-mut-src-dst-unsized.rs b/tests/ui-stable/transmute-mut-src-dst-unsized.rs
new file mode 100644
index 0000000..1bebcf2
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting between unsized source and
+// destination types.
+const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
diff --git a/tests/ui-stable/transmute-mut-src-dst-unsized.stderr b/tests/ui-stable/transmute-mut-src-dst-unsized.stderr
new file mode 100644
index 0000000..8cf7664
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-dst-unsized.stderr
@@ -0,0 +1,288 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsFromBytes`
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertDstIsAsBytes`
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertDstIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-dst-unsized.rs:17:36
+ |
+17 | const SRC_DST_UNSIZED: &mut [u8] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-src-generic.rs b/tests/ui-stable/transmute-mut-src-generic.rs
new file mode 100644
index 0000000..a3ef397
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_mut, AsBytes};
+
+fn main() {}
+
+fn transmute_mut<T: AsBytes + FromBytes>(t: &mut T) -> &mut u8 {
+ // `transmute_mut!` requires the source type to be concrete.
+ transmute_mut!(t)
+}
diff --git a/tests/ui-stable/transmute-mut-src-generic.stderr b/tests/ui-stable/transmute-mut-src-generic.stderr
new file mode 100644
index 0000000..fc4809e
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-generic.stderr
@@ -0,0 +1,10 @@
+error[E0405]: cannot find trait `FromBytes` in this scope
+ --> tests/ui-stable/transmute-mut-src-generic.rs:15:31
+ |
+15 | fn transmute_mut<T: AsBytes + FromBytes>(t: &mut T) -> &mut u8 {
+ | ^^^^^^^^^ not found in this scope
+ |
+help: consider importing this trait
+ |
+11 + use zerocopy::FromBytes;
+ |
diff --git a/tests/ui-stable/transmute-mut-src-immutable.rs b/tests/ui-stable/transmute-mut-src-immutable.rs
new file mode 100644
index 0000000..08088d0
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-immutable.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+fn ref_src_immutable() {
+ // `transmute_mut!` requires that its source type be a mutable reference.
+ let _: &mut u8 = transmute_mut!(&0u8);
+}
diff --git a/tests/ui-stable/transmute-mut-src-immutable.stderr b/tests/ui-stable/transmute-mut-src-immutable.stderr
new file mode 100644
index 0000000..0115c79
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-immutable.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-mut-src-immutable.rs:17:37
+ |
+17 | let _: &mut u8 = transmute_mut!(&0u8);
+ | ---------------^^^^-
+ | | |
+ | | types differ in mutability
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found reference `&u8`
diff --git a/tests/ui-stable/transmute-mut-src-not-a-reference.rs b/tests/ui-stable/transmute-mut-src-not-a-reference.rs
new file mode 100644
index 0000000..bf8bc32
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from a non-reference source
+// type.
+const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize);
diff --git a/tests/ui-stable/transmute-mut-src-not-a-reference.stderr b/tests/ui-stable/transmute-mut-src-not-a-reference.stderr
new file mode 100644
index 0000000..8c1d9b4
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-not-a-reference.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-mut-src-not-a-reference.rs:17:53
+ |
+17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&mut _`, found `usize`
+ | expected due to this
+ |
+ = note: expected mutable reference `&mut _`
+ found type `usize`
+help: consider mutably borrowing here
+ |
+17 | const SRC_NOT_A_REFERENCE: &mut u8 = transmute_mut!(&mut 0usize);
+ | ++++
diff --git a/tests/ui-stable/transmute-mut-src-not-asbytes.rs b/tests/ui-stable/transmute-mut-src-not-asbytes.rs
new file mode 100644
index 0000000..6a14f12
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-not-asbytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-stable/transmute-mut-src-not-asbytes.stderr b/tests/ui-stable/transmute-mut-src-not-asbytes.stderr
new file mode 100644
index 0000000..9fc9546
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-not-asbytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `Src: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `Src`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `Src: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `Src`
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-stable/transmute-mut-src-not-asbytes.rs:24:36
+ |
+24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-src-not-frombytes.rs b/tests/ui-stable/transmute-mut-src-not-frombytes.rs
new file mode 100644
index 0000000..2ebe036
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-not-frombytes.rs
@@ -0,0 +1,24 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+#[derive(zerocopy::AsBytes)]
+#[repr(C)]
+struct Src;
+
+#[derive(zerocopy::FromZeroes, zerocopy::FromBytes, zerocopy::AsBytes)]
+#[repr(C)]
+struct Dst;
+
+// `transmute_mut` requires that the source type implements `FromBytes`
+const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
diff --git a/tests/ui-stable/transmute-mut-src-not-frombytes.stderr b/tests/ui-stable/transmute-mut-src-not-frombytes.stderr
new file mode 100644
index 0000000..cc4a19d
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-not-frombytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `Src: FromBytes` is not satisfied
+ --> tests/ui-stable/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `Src`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-stable/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `Src: FromBytes` is not satisfied
+ --> tests/ui-stable/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `Src`
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-stable/transmute-mut-src-not-frombytes.rs:24:38
+ |
+24 | const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-mut-src-unsized.rs b/tests/ui-stable/transmute-mut-src-unsized.rs
new file mode 100644
index 0000000..413dd68
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-unsized.rs
@@ -0,0 +1,16 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_mut;
+
+fn main() {}
+
+// `transmute_mut!` does not support transmuting from an unsized source type.
+const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
diff --git a/tests/ui-stable/transmute-mut-src-unsized.stderr b/tests/ui-stable/transmute-mut-src-unsized.stderr
new file mode 100644
index 0000000..7f6def9
--- /dev/null
+++ b/tests/ui-stable/transmute-mut-src-unsized.stderr
@@ -0,0 +1,195 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsFromBytes`
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsFromBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertSrcIsAsBytes`
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsAsBytes`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-mut-src-unsized.rs:16:35
+ |
+16 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_mut`
+ --> src/macro_util.rs
+ |
+ | pub unsafe fn transmute_mut<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_mut`
+ = note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ptr-to-usize.rs b/tests/ui-stable/transmute-ptr-to-usize.rs
new file mode 100644
index 0000000..5af8859
--- /dev/null
+++ b/tests/ui-stable/transmute-ptr-to-usize.rs
@@ -0,0 +1,20 @@
+// Copyright 2022 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// It is unclear whether we can or should support this transmutation, especially
+// in a const context. This test ensures that even if such a transmutation
+// becomes valid due to the requisite implementations of `FromBytes` being
+// added, that we re-examine whether it should specifically be valid in a const
+// context.
+const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
diff --git a/tests/ui-stable/transmute-ptr-to-usize.stderr b/tests/ui-stable/transmute-ptr-to-usize.stderr
new file mode 100644
index 0000000..4f4d583
--- /dev/null
+++ b/tests/ui-stable/transmute-ptr-to-usize.stderr
@@ -0,0 +1,30 @@
+error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `*const usize`
+ | required by a bound introduced by this call
+ |
+ = help: the trait `AsBytes` is implemented for `usize`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize`
+ |
+ = help: the trait `AsBytes` is implemented for `usize`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ptr-to-usize.rs:20:30
+ |
+20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-alignment-increase.rs b/tests/ui-stable/transmute-ref-alignment-increase.rs
new file mode 100644
index 0000000..bf1988c
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-alignment-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a type of smaller
+// alignment to one of larger alignment.
+const INCREASE_ALIGNMENT: &AU16 = transmute_ref!(&[0u8; 2]);
diff --git a/tests/ui-stable/transmute-ref-alignment-increase.stderr b/tests/ui-stable/transmute-ref-alignment-increase.stderr
new file mode 100644
index 0000000..a34c406
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-alignment-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-alignment-increase.rs:19:35
+ |
+19 | const INCREASE_ALIGNMENT: &AU16 = transmute_ref!(&[0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<[u8; 2]>` (8 bits)
+ = note: target type: `MaxAlignsOf<[u8; 2], AU16>` (16 bits)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-dst-generic.rs b/tests/ui-stable/transmute-ref-dst-generic.rs
new file mode 100644
index 0000000..bf4a0f9
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, FromBytes};
+
+fn main() {}
+
+fn transmute_ref<T: FromBytes>(u: &u8) -> &T {
+ // `transmute_ref!` requires the destination type to be concrete.
+ transmute_ref!(u)
+}
diff --git a/tests/ui-stable/transmute-ref-dst-generic.stderr b/tests/ui-stable/transmute-ref-dst-generic.stderr
new file mode 100644
index 0000000..e30b9f6
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-dst-generic.rs:17:5
+ |
+17 | transmute_ref!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `T` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-dst-generic.rs:17:5
+ |
+17 | transmute_ref!(u)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<u8>` (8 bits)
+ = note: target type: `MaxAlignsOf<u8, T>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-dst-mutable.rs b/tests/ui-stable/transmute-ref-dst-mutable.rs
new file mode 100644
index 0000000..fa0e6e4
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-mutable.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+fn ref_dst_mutable() {
+ // `transmute_ref!` requires that its destination type be an immutable
+ // reference.
+ let _: &mut u8 = transmute_ref!(&0u8);
+}
diff --git a/tests/ui-stable/transmute-ref-dst-mutable.stderr b/tests/ui-stable/transmute-ref-dst-mutable.stderr
new file mode 100644
index 0000000..c70f6ea
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-mutable.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-dst-mutable.rs:18:22
+ |
+18 | let _: &mut u8 = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
+ |
+ = note: expected mutable reference `&mut u8`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-dst-not-a-reference.rs b/tests/ui-stable/transmute-ref-dst-not-a-reference.rs
new file mode 100644
index 0000000..de55f9a
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting into a non-reference
+// destination type.
+const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
diff --git a/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr b/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr
new file mode 100644
index 0000000..ab3f90c
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-dst-not-a-reference.rs:17:36
+ |
+17 | const DST_NOT_A_REFERENCE: usize = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-dst-not-frombytes.rs b/tests/ui-stable/transmute-ref-dst-not-frombytes.rs
new file mode 100644
index 0000000..d81f64d
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-not-frombytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref` requires that the destination type implements `FromBytes`
+const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
diff --git a/tests/ui-stable/transmute-ref-dst-not-frombytes.stderr b/tests/ui-stable/transmute-ref-dst-not-frombytes.stderr
new file mode 100644
index 0000000..76d18c5
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-not-frombytes.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
+ --> tests/ui-stable/transmute-ref-dst-not-frombytes.rs:18:42
+ |
+18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `FromBytes` is not implemented for `NotZerocopy`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `FromBytes`:
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ usize
+ u8
+ and $N others
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-stable/transmute-ref-dst-not-frombytes.rs:18:42
+ |
+18 | const DST_NOT_FROM_BYTES: &NotZerocopy = transmute_ref!(&AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-dst-unsized.rs b/tests/ui-stable/transmute-ref-dst-unsized.rs
new file mode 100644
index 0000000..625f1fa
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting into an unsized destination
+// type.
+const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
diff --git a/tests/ui-stable/transmute-ref-dst-unsized.stderr b/tests/ui-stable/transmute-ref-dst-unsized.stderr
new file mode 100644
index 0000000..8a0c761
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-dst-unsized.stderr
@@ -0,0 +1,89 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-dst-unsized.rs:17:28
+ |
+17 | const DST_UNSIZED: &[u8] = transmute_ref!(&[0u8; 1]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-illegal-lifetime.rs b/tests/ui-stable/transmute-ref-illegal-lifetime.rs
new file mode 100644
index 0000000..8dd191e
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-illegal-lifetime.rs
@@ -0,0 +1,15 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+fn main() {}
+
+fn increase_lifetime() {
+ let x = 0u64;
+ // It is illegal to increase the lifetime scope.
+ let _: &'static u64 = zerocopy::transmute_ref!(&x);
+}
diff --git a/tests/ui-stable/transmute-ref-illegal-lifetime.stderr b/tests/ui-stable/transmute-ref-illegal-lifetime.stderr
new file mode 100644
index 0000000..1ef34fe
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-illegal-lifetime.stderr
@@ -0,0 +1,12 @@
+error[E0597]: `x` does not live long enough
+ --> tests/ui-stable/transmute-ref-illegal-lifetime.rs:14:52
+ |
+12 | let x = 0u64;
+ | - binding `x` declared here
+13 | // It is illegal to increase the lifetime scope.
+14 | let _: &'static u64 = zerocopy::transmute_ref!(&x);
+ | ------------ ^^ borrowed value does not live long enough
+ | |
+ | type annotation requires that `x` is borrowed for `'static`
+15 | }
+ | - `x` dropped here while still borrowed
diff --git a/tests/ui-stable/transmute-ref-size-decrease.rs b/tests/ui-stable/transmute-ref-size-decrease.rs
new file mode 100644
index 0000000..1d66a54
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-size-decrease.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// Although this is not a soundness requirement, we currently require that the
+// size of the destination type is not smaller than the size of the source type.
+const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]);
diff --git a/tests/ui-stable/transmute-ref-size-decrease.stderr b/tests/ui-stable/transmute-ref-size-decrease.stderr
new file mode 100644
index 0000000..f353b26
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-size-decrease.rs:17:28
+ |
+17 | const DECREASE_SIZE: &u8 = transmute_ref!(&[0u8; 2]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; 2]` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-size-increase.rs b/tests/ui-stable/transmute-ref-size-increase.rs
new file mode 100644
index 0000000..cdca560
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-size-increase.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8);
diff --git a/tests/ui-stable/transmute-ref-size-increase.stderr b/tests/ui-stable/transmute-ref-size-increase.stderr
new file mode 100644
index 0000000..f51eb63
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-size-increase.rs:17:33
+ |
+17 | const INCREASE_SIZE: &[u8; 2] = transmute_ref!(&0u8);
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `[u8; 2]` (16 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-src-dst-generic.rs b/tests/ui-stable/transmute-ref-src-dst-generic.rs
new file mode 100644
index 0000000..409d785
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-dst-generic.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, AsBytes, FromBytes};
+
+fn main() {}
+
+fn transmute_ref<T: AsBytes, U: FromBytes>(t: &T) -> &U {
+ // `transmute_ref!` requires the source and destination types to be
+ // concrete.
+ transmute_ref!(t)
+}
diff --git a/tests/ui-stable/transmute-ref-src-dst-generic.stderr b/tests/ui-stable/transmute-ref-src-dst-generic.stderr
new file mode 100644
index 0000000..0905dc6
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-dst-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-src-dst-generic.rs:18:5
+ |
+18 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `U` (this type does not have a fixed size)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-src-dst-generic.rs:18:5
+ |
+18 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, U>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-src-dst-not-references.rs b/tests/ui-stable/transmute-ref-src-dst-not-references.rs
new file mode 100644
index 0000000..114e917
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-dst-not-references.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting between non-reference source
+// and destination types.
+const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
diff --git a/tests/ui-stable/transmute-ref-src-dst-not-references.stderr b/tests/ui-stable/transmute-ref-src-dst-not-references.stderr
new file mode 100644
index 0000000..8a80e99
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-dst-not-references.stderr
@@ -0,0 +1,45 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:54
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&_`, found `usize`
+ | expected due to this
+ |
+ = note: expected reference `&_`
+ found type `usize`
+help: consider borrowing here
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(&0usize);
+ | +
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-src-dst-not-references.rs:17:39
+ |
+17 | const SRC_DST_NOT_REFERENCES: usize = transmute_ref!(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
+ |
+ = note: expected type `usize`
+ found reference `&_`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-src-dst-unsized.rs b/tests/ui-stable/transmute-ref-src-dst-unsized.rs
new file mode 100644
index 0000000..6bfe7ff
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-dst-unsized.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting between unsized source and
+// destination types.
+const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
diff --git a/tests/ui-stable/transmute-ref-src-dst-unsized.stderr b/tests/ui-stable/transmute-ref-src-dst-unsized.stderr
new file mode 100644
index 0000000..ca62fcf
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-dst-unsized.stderr
@@ -0,0 +1,240 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsFromBytes`
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsFromBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-dst-unsized.rs:17:32
+ |
+17 | const SRC_DST_UNSIZED: &[u8] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-src-generic.rs b/tests/ui-stable/transmute-ref-src-generic.rs
new file mode 100644
index 0000000..010281c
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-generic.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::{transmute_ref, AsBytes};
+
+fn main() {}
+
+fn transmute_ref<T: AsBytes>(t: &T) -> &u8 {
+ // `transmute_ref!` requires the source type to be concrete.
+ transmute_ref!(t)
+}
diff --git a/tests/ui-stable/transmute-ref-src-generic.stderr b/tests/ui-stable/transmute-ref-src-generic.stderr
new file mode 100644
index 0000000..b6bbd16
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-generic.stderr
@@ -0,0 +1,19 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-src-generic.rs:17:5
+ |
+17 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `T` (this type does not have a fixed size)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-ref-src-generic.rs:17:5
+ |
+17 | transmute_ref!(t)
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AlignOf<T>` (size can vary because of T)
+ = note: target type: `MaxAlignsOf<T, u8>` (size can vary because of T)
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-src-not-a-reference.rs b/tests/ui-stable/transmute-ref-src-not-a-reference.rs
new file mode 100644
index 0000000..90661b3
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-not-a-reference.rs
@@ -0,0 +1,17 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from a non-reference source
+// type.
+const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize);
diff --git a/tests/ui-stable/transmute-ref-src-not-a-reference.stderr b/tests/ui-stable/transmute-ref-src-not-a-reference.stderr
new file mode 100644
index 0000000..622c3db
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-not-a-reference.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> tests/ui-stable/transmute-ref-src-not-a-reference.rs:17:49
+ |
+17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(0usize);
+ | ---------------^^^^^^-
+ | | |
+ | | expected `&_`, found `usize`
+ | expected due to this
+ |
+ = note: expected reference `&_`
+ found type `usize`
+help: consider borrowing here
+ |
+17 | const SRC_NOT_A_REFERENCE: &u8 = transmute_ref!(&0usize);
+ | +
diff --git a/tests/ui-stable/transmute-ref-src-not-asbytes.rs b/tests/ui-stable/transmute-ref-src-not-asbytes.rs
new file mode 100644
index 0000000..6ab19f3
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-not-asbytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
diff --git a/tests/ui-stable/transmute-ref-src-not-asbytes.stderr b/tests/ui-stable/transmute-ref-src-not-asbytes.stderr
new file mode 100644
index 0000000..2ded6ba
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-not-asbytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ref-src-not-asbytes.rs:18:33
+ |
+18 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-ref-src-unsized.rs b/tests/ui-stable/transmute-ref-src-unsized.rs
new file mode 100644
index 0000000..14e72b4
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-unsized.rs
@@ -0,0 +1,16 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+extern crate zerocopy;
+
+use zerocopy::transmute_ref;
+
+fn main() {}
+
+// `transmute_ref!` does not support transmuting from an unsized source type.
+const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
diff --git a/tests/ui-stable/transmute-ref-src-unsized.stderr b/tests/ui-stable/transmute-ref-src-unsized.stderr
new file mode 100644
index 0000000..b194d67
--- /dev/null
+++ b/tests/ui-stable/transmute-ref-src-unsized.stderr
@@ -0,0 +1,164 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all local variables must have a statically known size
+ = help: unsized locals are gated as an unstable feature
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute`
+ --> $RUST/core/src/intrinsics.rs
+ |
+ | pub fn transmute<Src, Dst>(src: Src) -> Dst;
+ | ^^^ required by this bound in `transmute`
+ = note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf::<T>::into_t`
+ --> src/macro_util.rs
+ |
+ | impl<T> AlignOf<T> {
+ | ^ required by this bound in `AlignOf::<T>::into_t`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn into_t(self) -> T {
+ | ------ required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: the left-hand-side of an assignment must have a statically known size
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf::<T, U>::new`
+ --> src/macro_util.rs
+ |
+ | impl<T, U> MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf::<T, U>::new`
+ | #[inline(never)] // Make `missing_inline_in_public_items` happy.
+ | pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
+ | --- required by a bound in this associated function
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `MaxAlignsOf`
+ --> src/macro_util.rs
+ |
+ | pub union MaxAlignsOf<T, U> {
+ | ^ required by this bound in `MaxAlignsOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `AlignOf`
+ --> src/macro_util.rs
+ |
+ | pub struct AlignOf<T> {
+ | ^ required by this bound in `AlignOf`
+ = note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> tests/ui-stable/transmute-ref-src-unsized.rs:16:31
+ |
+16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | doesn't have a size known at compile-time
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+note: required by a bound in `transmute_ref`
+ --> src/macro_util.rs
+ |
+ | pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
+ | ^^^ required by this bound in `transmute_ref`
+ = note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-size-decrease.rs b/tests/ui-stable/transmute-size-decrease.rs
new file mode 100644
index 0000000..1d56831
--- /dev/null
+++ b/tests/ui-stable/transmute-size-decrease.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// Although this is not a soundness requirement, we currently require that the
+// size of the destination type is not smaller than the size of the source type.
+const DECREASE_SIZE: u8 = transmute!(AU16(0));
diff --git a/tests/ui-stable/transmute-size-decrease.stderr b/tests/ui-stable/transmute-size-decrease.stderr
new file mode 100644
index 0000000..0241662
--- /dev/null
+++ b/tests/ui-stable/transmute-size-decrease.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-size-decrease.rs:19:27
+ |
+19 | const DECREASE_SIZE: u8 = transmute!(AU16(0));
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `AU16` (16 bits)
+ = note: target type: `u8` (8 bits)
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-size-increase.rs b/tests/ui-stable/transmute-size-increase.rs
new file mode 100644
index 0000000..32f9363
--- /dev/null
+++ b/tests/ui-stable/transmute-size-increase.rs
@@ -0,0 +1,19 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute!` does not support transmuting from a smaller type to a larger
+// one.
+const INCREASE_SIZE: AU16 = transmute!(0u8);
diff --git a/tests/ui-stable/transmute-size-increase.stderr b/tests/ui-stable/transmute-size-increase.stderr
new file mode 100644
index 0000000..87d82a2
--- /dev/null
+++ b/tests/ui-stable/transmute-size-increase.stderr
@@ -0,0 +1,9 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> tests/ui-stable/transmute-size-increase.rs:19:29
+ |
+19 | const INCREASE_SIZE: AU16 = transmute!(0u8);
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: source type: `u8` (8 bits)
+ = note: target type: `AU16` (16 bits)
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui-stable/transmute-src-not-asbytes.rs b/tests/ui-stable/transmute-src-not-asbytes.rs
new file mode 100644
index 0000000..dd73021
--- /dev/null
+++ b/tests/ui-stable/transmute-src-not-asbytes.rs
@@ -0,0 +1,18 @@
+// Copyright 2023 The Fuchsia Authors
+//
+// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
+// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
+// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
+// This file may not be copied, modified, or distributed except according to
+// those terms.
+
+include!("../../zerocopy-derive/tests/util.rs");
+
+extern crate zerocopy;
+
+use zerocopy::transmute;
+
+fn main() {}
+
+// `transmute` requires that the source type implements `AsBytes`
+const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
diff --git a/tests/ui-stable/transmute-src-not-asbytes.stderr b/tests/ui-stable/transmute-src-not-asbytes.stderr
new file mode 100644
index 0000000..f2e834e
--- /dev/null
+++ b/tests/ui-stable/transmute-src-not-asbytes.stderr
@@ -0,0 +1,48 @@
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ | required by a bound introduced by this call
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
+ --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
+ |
+ = help: the following other types implement trait `AsBytes`:
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
+note: required by a bound in `AssertIsAsBytes`
+ --> tests/ui-stable/transmute-src-not-asbytes.rs:18:32
+ |
+18 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertIsAsBytes`
+ = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)