Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

55
vendor/zerocopy/tests/trybuild.rs vendored Normal file
View File

@@ -0,0 +1,55 @@
// 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.
// Many of our UI tests require the "derive" feature to function properly. In
// particular:
// - Some tests directly include `zerocopy-derive/tests/include.rs`, which
// derives traits on the `AU16` type.
// - The file `invalid-impls.rs` directly includes `src/util/macros.rs` in order
// to test the `impl_or_verify!` macro which is defined in that file.
// Specifically, it tests the verification portion of that macro, which is
// enabled when `cfg(any(feature = "derive", test))`. While `--cfg test` is of
// course passed to the code in the file you're reading right now, `trybuild`
// does not pass `--cfg test` when it invokes Cargo. As a result, this
// `trybuild` test only tests the correct behavior when the "derive" feature
// is enabled.
#![cfg(feature = "derive")]
use testutil::{set_rustflags_w_warnings, 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();
// Set `-Wwarnings` in the `RUSTFLAGS` environment variable to ensure that
// `.stderr` files reflect what the typical user would encounter.
set_rustflags_w_warnings();
let t = trybuild::TestCases::new();
t.compile_fail(format!("tests/{}/*.rs", source_files_dirname));
}
#[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();
// Set `-Wwarnings` in the `RUSTFLAGS` environment variable to ensure that
// `.stderr` files reflect what the typical user would encounter.
set_rustflags_w_warnings();
let t = trybuild::TestCases::new();
t.compile_fail(format!("tests/{}/invalid-impls/*.rs", source_files_dirname));
}

View File

@@ -0,0 +1,21 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::FromBytes;
fn main() {
// We expect the proper diagnostic to be emitted on Rust 1.78.0 and later.
takes_from_bytes::<NotZerocopy>();
}
fn takes_from_bytes<T: FromBytes>() {}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:18:24
|
18 | takes_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_from_bytes`
--> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:21:24
|
21 | fn takes_from_bytes<T: FromBytes>() {}
| ^^^^^^^^^ required by this bound in `takes_from_bytes`

View File

@@ -0,0 +1,21 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::FromZeros;
fn main() {
// We expect the proper diagnostic to be emitted on Rust 1.78.0 and later.
takes_from_zeros::<NotZerocopy>();
}
fn takes_from_zeros<T: FromZeros>() {}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:18:24
|
18 | takes_from_zeros::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_from_zeros`
--> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:21:24
|
21 | fn takes_from_zeros<T: FromZeros>() {}
| ^^^^^^^^^ required by this bound in `takes_from_zeros`

View File

@@ -0,0 +1,21 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::Immutable;
fn main() {
// We expect the proper diagnostic to be emitted on Rust 1.78.0 and later.
takes_immutable::<NotZerocopy>();
}
fn takes_immutable<T: Immutable>() {}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:18:23
|
18 | takes_immutable::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_immutable`
--> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:21:23
|
21 | fn takes_immutable<T: Immutable>() {}
| ^^^^^^^^^ required by this bound in `takes_immutable`

View File

@@ -0,0 +1,21 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::IntoBytes;
fn main() {
// We expect the proper diagnostic to be emitted on Rust 1.78.0 and later.
takes_into_bytes::<NotZerocopy>();
}
fn takes_into_bytes<T: IntoBytes>() {}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:18:24
|
18 | takes_into_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_into_bytes`
--> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:21:24
|
21 | fn takes_into_bytes<T: IntoBytes>() {}
| ^^^^^^^^^ required by this bound in `takes_into_bytes`

View File

@@ -0,0 +1,59 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::{Immutable, IntoBytes};
fn main() {
// This is adapted from #1296, which includes the following text:
//
// The compiler errors when a type is missing Immutable are somewhat
// misleading, although I'm not sure there's much zerocopy can do about
// this. An example where the compiler recommends adding a reference
// rather than implementing Immutable (some were even more confusing than
// this):
//
// error[E0277]: the trait bound `virtio::wl::CtrlVfdNewDmabuf: zerocopy::Immutable` is not satisfied
// --> devices/src/virtio/wl.rs:317:20
// |
// 317 | .write_obj(ctrl_vfd_new_dmabuf)
// | --------- ^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `virtio::wl::CtrlVfdNewDmabuf`
// | |
// | required by a bound introduced by this call
// |
// note: required by a bound in `virtio::descriptor_utils::Writer::write_obj`
// --> devices/src/virtio/descriptor_utils.rs:536:25
// |
// 536 | pub fn write_obj<T: Immutable + IntoBytes>(&mut self, val: T) -> io::Result<()> {
// | ^^^^^^^^^ required by this bound in `Writer::write_obj`
// help: consider borrowing here
// |
// 317 | .write_obj(&ctrl_vfd_new_dmabuf)
// | +
// 317 | .write_obj(&mut ctrl_vfd_new_dmabuf)
// | ++++
//
// Taking the compiler's suggestion results in a different error with a
// recommendation to remove the reference (back to the original code).
//
// As of this writing, the described problem is still happening thanks to
// https://github.com/rust-lang/rust/issues/130563. We include this test so
// that we can capture the current behavior, but we will update it once that
// Rust issue is fixed.
Foo.write_obj(NotZerocopy(()));
}
struct Foo;
impl Foo {
fn write_obj<T: Immutable + IntoBytes>(&mut self, _val: T) {}
}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:52:19
|
52 | Foo.write_obj(NotZerocopy(()));
| ^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:52:19
|
52 | Foo.write_obj(NotZerocopy(()));
| ^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy`

View File

@@ -0,0 +1,21 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::KnownLayout;
fn main() {
// We expect the proper diagnostic to be emitted on Rust 1.78.0 and later.
takes_known_layout::<NotZerocopy>();
}
fn takes_known_layout<T: KnownLayout>() {}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::KnownLayout` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:18:26
|
18 | takes_known_layout::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::KnownLayout` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_known_layout`
--> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:21:26
|
21 | fn takes_known_layout<T: KnownLayout>() {}
| ^^^^^^^^^^^ required by this bound in `takes_known_layout`

View File

@@ -0,0 +1,21 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::TryFromBytes;
fn main() {
// We expect the proper diagnostic to be emitted on Rust 1.78.0 and later.
takes_try_from_bytes::<NotZerocopy>();
}
fn takes_try_from_bytes<T: TryFromBytes>() {}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:18:28
|
18 | takes_try_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_try_from_bytes`
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:21:28
|
21 | fn takes_try_from_bytes<T: TryFromBytes>() {}
| ^^^^^^^^^^^^ required by this bound in `takes_try_from_bytes`

View File

@@ -0,0 +1,21 @@
// 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/include.rs");
extern crate zerocopy;
use util::NotZerocopy;
use zerocopy::Unaligned;
fn main() {
// We expect the proper diagnostic to be emitted on Rust 1.78.0 and later.
takes_unaligned::<NotZerocopy>();
}
fn takes_unaligned<T: Unaligned>() {}

View File

@@ -0,0 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::Unaligned` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:18:23
|
18 | takes_unaligned::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_unaligned`
--> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:21:23
|
21 | fn takes_unaligned<T: Unaligned>() {}
| ^^^^^^^^^ required by this bound in `takes_unaligned`

View File

@@ -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/include.rs");
#[macro_use]
extern crate zerocopy;
use util::NotZerocopy;
fn main() {}
// Should fail because `NotZerocopy<u32>: !FromBytes`.
const NOT_FROM_BYTES: NotZerocopy<u32> = include_value!("../../testdata/include_value/data");

View File

@@ -0,0 +1,15 @@
error[E0277]: the trait bound `NotZerocopy<u32>: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/include_value_not_from_bytes.rs:19:42
|
19 | const NOT_FROM_BYTES: NotZerocopy<u32> = include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy<u32>`
|
note: required by a bound in `NOT_FROM_BYTES::transmute`
--> tests/ui-msrv/include_value_not_from_bytes.rs:19:42
|
19 | const NOT_FROM_BYTES: NotZerocopy<u32> = include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| required by a bound in this
| required by this bound in `NOT_FROM_BYTES::transmute`
= note: this error originates in the macro `$crate::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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.
#[macro_use]
extern crate zerocopy;
fn main() {}
// Should fail because the file is 4 bytes long, not 8.
const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");

View File

@@ -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:15:25
|
15 | 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)

View File

@@ -0,0 +1,32 @@
// 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)]
extern crate zerocopy;
extern crate zerocopy_derive;
include!("../../../src/util/macros.rs");
use zerocopy::*;
use zerocopy_derive::*;
fn main() {}
#[derive(FromBytes, IntoBytes, Unaligned)]
#[repr(transparent)]
struct Foo<T>(T);
const _: () = unsafe {
impl_or_verify!(T => TryFromBytes for Foo<T>);
impl_or_verify!(T => FromZeros for Foo<T>);
impl_or_verify!(T => FromBytes for Foo<T>);
impl_or_verify!(T => IntoBytes for Foo<T>);
impl_or_verify!(T => Unaligned for Foo<T>);
};

View File

@@ -0,0 +1,159 @@
error[E0277]: the trait bound `T: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `T`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:27:5
|
27 | impl_or_verify!(T => TryFromBytes for Foo<T>);
| ---------------------------------------------- in this macro invocation
|
note: required because of the requirements on the impl of `zerocopy::TryFromBytes` for `Foo<T>`
--> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:10
|
22 | #[derive(FromBytes, IntoBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:27:5
|
27 | impl_or_verify!(T => TryFromBytes 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`
|
27 | impl_or_verify!(T: zerocopy::TryFromBytes => TryFromBytes for Foo<T>);
| ++++++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::FromZeros` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::FromZeros` is not implemented for `T`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:28:5
|
28 | impl_or_verify!(T => FromZeros for Foo<T>);
| ------------------------------------------- in this macro invocation
|
note: required because of the requirements on the impl of `zerocopy::FromZeros` for `Foo<T>`
--> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:10
|
22 | #[derive(FromBytes, IntoBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:28:5
|
28 | impl_or_verify!(T => FromZeros 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`
|
28 | impl_or_verify!(T: zerocopy::FromZeros => FromZeros for Foo<T>);
| +++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `T`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:29:5
|
29 | 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:22:10
|
22 | #[derive(FromBytes, IntoBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:29:5
|
29 | 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`
|
29 | impl_or_verify!(T: zerocopy::FromBytes => FromBytes for Foo<T>);
| +++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `T`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:30:5
|
30 | impl_or_verify!(T => IntoBytes for Foo<T>);
| ------------------------------------------- in this macro invocation
|
note: required because of the requirements on the impl of `zerocopy::IntoBytes` for `Foo<T>`
--> tests/ui-msrv/invalid-impls/invalid-impls.rs:22:21
|
22 | #[derive(FromBytes, IntoBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:30:5
|
30 | impl_or_verify!(T => IntoBytes 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`
|
30 | impl_or_verify!(T: zerocopy::IntoBytes => IntoBytes for Foo<T>);
| +++++++++++++++++++++
error[E0277]: the trait bound `T: zerocopy::Unaligned` is not satisfied
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
| ^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `T`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:31:5
|
31 | 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:22:32
|
22 | #[derive(FromBytes, IntoBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::Subtrait`
--> tests/ui-msrv/invalid-impls/../../../src/util/macros.rs
|
| trait Subtrait: $trait {}
| ^^^^^^ required by this bound in `_::Subtrait`
|
::: tests/ui-msrv/invalid-impls/invalid-impls.rs:31:5
|
31 | 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`
|
31 | impl_or_verify!(T: zerocopy::Unaligned => Unaligned for Foo<T>);
| +++++++++++++++++++++

View File

@@ -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() {}

View File

@@ -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))]
| ^^^^^^^^^^^^^^^^^

View File

@@ -0,0 +1,20 @@
use zerocopy::pointer::{
invariant::{Aligned, Exclusive, Shared, Valid},
Ptr,
};
fn _when_exclusive<'big: 'small, 'small>(
big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>,
mut _small: Ptr<'small, &'small u32, (Exclusive, Aligned, Valid)>,
) {
_small = big;
}
fn _when_shared<'big: 'small, 'small>(
big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>,
mut _small: Ptr<'small, &'small u32, (Shared, Aligned, Valid)>,
) {
_small = big;
}
fn main() {}

View File

@@ -0,0 +1,17 @@
error[E0623]: lifetime mismatch
--> tests/ui-msrv/ptr-is-invariant-over-v.rs:10:14
|
7 | big: Ptr<'small, &'big u32, (Exclusive, Aligned, Valid)>,
| --------------------------------------------------- these two types are declared with different lifetimes...
...
10 | _small = big;
| ^^^ ...but data from `big` flows into `big` here
error[E0623]: lifetime mismatch
--> tests/ui-msrv/ptr-is-invariant-over-v.rs:17:14
|
14 | big: Ptr<'small, &'big u32, (Shared, Aligned, Valid)>,
| ------------------------------------------------ these two types are declared with different lifetimes...
...
17 | _small = big;
| ^^^ ...but data from `big` flows into `big` here

View File

@@ -0,0 +1,19 @@
// 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/include.rs");
extern crate zerocopy;
use util::{NotZerocopy, AU16};
use zerocopy::transmute;
fn main() {}
// `transmute` requires that the destination type implements `FromBytes`
const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));

View File

@@ -0,0 +1,15 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/transmute-dst-not-frombytes.rs:19:41
|
19 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `DST_NOT_FROM_BYTES::transmute`
--> tests/ui-msrv/transmute-dst-not-frombytes.rs:19:41
|
19 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^
| |
| required by a bound in this
| required by this bound in `DST_NOT_FROM_BYTES::transmute`
= note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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/include.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);

View File

@@ -0,0 +1,40 @@
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]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> tests/ui-msrv/transmute-mut-const.rs:20:37
|
20 | const CONST_CONTEXT: &mut [u8; 2] = transmute_mut!(&mut ARRAY_OF_U8S);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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`

View File

@@ -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);

View File

@@ -0,0 +1,9 @@
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)

View File

@@ -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::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
#[repr(C)]
struct Src;
#[derive(zerocopy::IntoBytes, zerocopy::Immutable)]
#[repr(C)]
struct Dst;
// `transmute_mut` requires that the destination type implements `FromBytes`
const DST_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);

View File

@@ -0,0 +1,7 @@
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: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
#[repr(C)]
struct Src;
#[derive(zerocopy::FromBytes, zerocopy::Immutable)]
#[repr(C)]
struct Dst;
// `transmute_mut` requires that the destination type implements `IntoBytes`
const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);

View File

@@ -0,0 +1,7 @@
error[E0277]: the trait bound `Dst: IntoBytes` is not satisfied
--> tests/ui-msrv/transmute-mut-dst-not-intobytes.rs:24:36
|
24 | const DST_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Dst`
|
= note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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]);

View File

@@ -0,0 +1,8 @@
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: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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`

View File

@@ -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);
}

View File

@@ -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`

View File

@@ -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);

View File

@@ -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`

View File

@@ -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::IntoBytes, zerocopy::Immutable)]
#[repr(C)]
struct Src;
#[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
#[repr(C)]
struct Dst;
// `transmute_mut` requires that the source type implements `FromBytes`
const SRC_NOT_FROM_BYTES: &mut Dst = transmute_mut!(&mut Src);

View File

@@ -0,0 +1,7 @@
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: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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::FromBytes, zerocopy::Immutable)]
#[repr(C)]
struct Src;
#[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
#[repr(C)]
struct Dst;
// `transmute_mut` requires that the source type implements `IntoBytes`
const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);

View File

@@ -0,0 +1,7 @@
error[E0277]: the trait bound `Src: IntoBytes` is not satisfied
--> tests/ui-msrv/transmute-mut-src-not-intobytes.rs:24:36
|
24 | const SRC_NOT_AS_BYTES: &mut Dst = transmute_mut!(&mut Src);
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `Src`
|
= note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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 an unsized source type to
// a sized destination type.
const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);

View File

@@ -0,0 +1,8 @@
error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize`
--> tests/ui-msrv/transmute-mut-src-unsized.rs:17:35
|
17 | const SRC_UNSIZED: &mut [u8; 1] = transmute_mut!(&mut [0u8][..]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
|
= note: required because of the requirements on the impl of `TransmuteMutDst<'_>` for `Wrap<&mut [u8], &mut [u8; 1]>`
= note: this error originates in the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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);

View File

@@ -0,0 +1,15 @@
error[E0277]: the trait bound `*const usize: IntoBytes` 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 `IntoBytes` is not implemented for `*const usize`
|
note: required by a bound in `POINTER_VALUE::transmute`
--> tests/ui-msrv/transmute-ptr-to-usize.rs:20:30
|
20 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| required by a bound in this
| required by this bound in `POINTER_VALUE::transmute`
= note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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);

View File

@@ -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)

View File

@@ -0,0 +1,23 @@
// 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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::transmute_ref;
fn main() {}
#[derive(zerocopy::Immutable)]
#[repr(transparent)]
struct Dst(AU16);
// `transmute_ref` requires that the destination type implements `FromBytes`
const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0));

View File

@@ -0,0 +1,12 @@
error[E0277]: the trait bound `Dst: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:23:34
|
23 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `Dst`
|
note: required by `AssertDstIsFromBytes`
--> tests/ui-msrv/transmute-ref-dst-not-frombytes.rs:23:34
|
23 | const DST_NOT_FROM_BYTES: &Dst = transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -0,0 +1,23 @@
// 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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::transmute_ref;
fn main() {}
#[derive(zerocopy::FromBytes)]
#[repr(transparent)]
struct Dst(AU16);
// `transmute_ref` requires that the destination type implements `Immutable`
const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0));

View File

@@ -0,0 +1,12 @@
error[E0277]: the trait bound `Dst: zerocopy::Immutable` is not satisfied
--> tests/ui-msrv/transmute-ref-dst-not-nocell.rs:23:33
|
23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `Dst`
|
note: required by `AssertDstIsImmutable`
--> tests/ui-msrv/transmute-ref-dst-not-nocell.rs:23:33
|
23 | const DST_NOT_IMMUTABLE: &Dst = transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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]);

View File

@@ -0,0 +1,8 @@
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: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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)

View File

@@ -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);

View File

@@ -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`

View File

@@ -0,0 +1,23 @@
// 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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::transmute_ref;
fn main() {}
#[derive(zerocopy::Immutable)]
#[repr(transparent)]
struct Src(AU16);
// `transmute_ref` requires that the source type implements `IntoBytes`
const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0)));

View File

@@ -0,0 +1,25 @@
error[E0277]: the trait bound `Src: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:23:33
|
23 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `Src`
|
note: required by `AssertSrcIsIntoBytes`
--> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:23:33
|
23 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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 `Src: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:23:33
|
23 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `Src`
|
note: required by a bound in `AssertSrcIsIntoBytes`
--> tests/ui-msrv/transmute-ref-src-not-intobytes.rs:23:33
|
23 | const SRC_NOT_AS_BYTES: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsIntoBytes`
= note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -0,0 +1,23 @@
// 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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::transmute_ref;
fn main() {}
#[derive(zerocopy::IntoBytes)]
#[repr(transparent)]
struct Src(AU16);
// `transmute_ref` requires that the source type implements `Immutable`
const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0)));

View File

@@ -0,0 +1,25 @@
error[E0277]: the trait bound `Src: zerocopy::Immutable` is not satisfied
--> tests/ui-msrv/transmute-ref-src-not-nocell.rs:23:34
|
23 | const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `zerocopy::Immutable`
|
note: required by `AssertSrcIsImmutable`
--> tests/ui-msrv/transmute-ref-src-not-nocell.rs:23:34
|
23 | const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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 `Src: zerocopy::Immutable` is not satisfied
--> tests/ui-msrv/transmute-ref-src-not-nocell.rs:23:34
|
23 | const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `Src`
|
note: required by a bound in `AssertSrcIsImmutable`
--> tests/ui-msrv/transmute-ref-src-not-nocell.rs:23:34
|
23 | const SRC_NOT_IMMUTABLE: &AU16 = transmute_ref!(&Src(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssertSrcIsImmutable`
= note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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][..]);

View File

@@ -0,0 +1,8 @@
error[E0271]: type mismatch resolving `<[u8; 1] as KnownLayout>::PointerMetadata == usize`
--> tests/ui-msrv/transmute-ref-src-unsized.rs:16:31
|
16 | const SRC_UNSIZED: &[u8; 1] = transmute_ref!(&[0u8][..]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
|
= note: required because of the requirements on the impl of `TransmuteRefDst<'_>` for `Wrap<&[u8], &[u8; 1]>`
= note: this error originates in the macro `transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::AU16;
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));

View File

@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/transmute-size-decrease.rs:20:27
|
20 | 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)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::transmute;
fn main() {}
// `transmute!` does not support transmuting from a smaller type to a larger
// one.
const INCREASE_SIZE: AU16 = transmute!(#![allow(shrink)] 0u8);

View File

@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/transmute-size-increase-allow-shrink.rs:20:29
|
20 | const INCREASE_SIZE: AU16 = transmute!(#![allow(shrink)] 0u8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `u8` (8 bits)
= note: target type: `Transmute<u8, AU16>` (16 bits)
= note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::transmute;
fn main() {}
// `transmute!` does not support transmuting from a smaller type to a larger
// one.
const INCREASE_SIZE: AU16 = transmute!(0u8);

View File

@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/transmute-size-increase.rs:20:29
|
20 | 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)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::{NotZerocopy, AU16};
use zerocopy::transmute;
fn main() {}
// `transmute` requires that the source type implements `IntoBytes`
const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));

View File

@@ -0,0 +1,15 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/transmute-src-not-intobytes.rs:19:32
|
19 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy<AU16>`
|
note: required by a bound in `SRC_NOT_AS_BYTES::transmute`
--> tests/ui-msrv/transmute-src-not-intobytes.rs:19:32
|
19 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| required by a bound in this
| required by this bound in `SRC_NOT_AS_BYTES::transmute`
= note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::{NotZerocopy, AU16};
use zerocopy::try_transmute;
fn main() {
let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
}

View File

@@ -0,0 +1,37 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:58
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `try_transmute`
--> src/util/macro_util.rs
|
| Dst: TryFromBytes,
| ^^^^^^^^^^^^ required by this bound in `try_transmute`
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:33
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
|
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:58
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
|
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::try_transmute;
// 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.
fn main() {
let _decrease_size: Result<u8, _> = try_transmute!(AU16(0));
}

View File

@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/try_transmute-size-decrease.rs:19:41
|
19 | let _decrease_size: Result<u8, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `AU16` (16 bits)
= note: target type: `u8` (8 bits)
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::try_transmute;
// `try_transmute!` does not support transmuting from a smaller type to a larger
// one.
fn main() {
let _increase_size: Result<AU16, _> = try_transmute!(0u8);
}

View File

@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/try_transmute-size-increase.rs:19:43
|
19 | let _increase_size: Result<AU16, _> = try_transmute!(0u8);
| ^^^^^^^^^^^^^^^^^^^
|
= note: source type: `u8` (8 bits)
= note: target type: `AU16` (16 bits)
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -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/include.rs");
extern crate zerocopy;
use util::{NotZerocopy, AU16};
use zerocopy::try_transmute;
fn main() {
// `try_transmute` requires that the source type implements `IntoBytes`
let src_not_into_bytes: Result<AU16, _> = try_transmute!(NotZerocopy(AU16(0)));
}

View File

@@ -0,0 +1,12 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/try_transmute-src-not-intobytes.rs:18:47
|
18 | let src_not_into_bytes: Result<AU16, _> = try_transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy<AU16>`
|
note: required by a bound in `try_transmute`
--> src/util/macro_util.rs
|
| Src: IntoBytes,
| ^^^^^^^^^ required by this bound in `try_transmute`
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -0,0 +1,21 @@
// Copyright 2024 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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::try_transmute_mut;
// `try_transmute_mut!` does not support transmuting from a type of smaller
// alignment to one of larger alignment.
fn main() {
let src = &mut [0u8; 2];
let _increase_size: Result<&mut AU16, _> = try_transmute_mut!(src);
}

View File

@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/try_transmute_mut-alignment-increase.rs:20:48
|
20 | let _increase_size: Result<&mut AU16, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= 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)

View File

@@ -0,0 +1,21 @@
// Copyright 2024 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/include.rs");
extern crate zerocopy;
use util::{NotZerocopy, AU16};
use zerocopy::try_transmute_mut;
fn main() {
// `try_transmute_mut` requires that the destination type implements
// `IntoBytes`
let src = &mut AU16(0);
let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
}

View File

@@ -0,0 +1,50 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `try_transmute_mut`
--> src/util/macro_util.rs
|
| Dst: TryFromBytes + IntoBytes,
| ^^^^^^^^^^^^ required by this bound in `try_transmute_mut`
= note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `try_transmute_mut`
--> src/util/macro_util.rs
|
| Dst: TryFromBytes + IntoBytes,
| ^^^^^^^^^ required by this bound in `try_transmute_mut`
= note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:33
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
|
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
|
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`
= note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -0,0 +1,21 @@
// Copyright 2024 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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::try_transmute_mut;
// 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.
fn main() {
let src = &mut AU16(0);
let _decrease_size: Result<&mut u8, _> = try_transmute_mut!(src);
}

View File

@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/try_transmute_mut-size-decrease.rs:20:46
|
20 | let _decrease_size: Result<&mut u8, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `AU16` (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)

View File

@@ -0,0 +1,21 @@
// Copyright 2024 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/include.rs");
extern crate zerocopy;
use util::AU16;
use zerocopy::try_transmute_mut;
// `try_transmute_mut!` does not support transmuting from a smaller type to a
// larger one.
fn main() {
let src = &mut 0u8;
let _increase_size: Result<&mut [u8; 2], _> = try_transmute_mut!(src);
}

Some files were not shown because too many files have changed in this diff Show More