Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ exclude = [".*"]
# `stdarch_x86_avx512` feature).
zerocopy-simd-x86-avx12-1-89-0 = "1.89.0"

# From 1.85.0, Rust supports the `#[diagnostic::do_not_recommend]` attribute.
zerocopy-diagnostic-do-not-recommend-1-85-0 = "1.85.0"

# From 1.81.0, Rust supports the `core::error::Error` trait.
zerocopy-core-error-1-81-0 = "1.81.0"

Expand Down
10 changes: 8 additions & 2 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,14 @@ const _: () = unsafe { unsafe_impl!(T: ?Sized => Immutable for NonNull<T>) };
// SAFETY: Reference types do not contain any `UnsafeCell`s.
#[allow(clippy::multiple_unsafe_ops_per_block)]
const _: () = unsafe {
unsafe_impl!(T: ?Sized => Immutable for &'_ T);
unsafe_impl!(T: ?Sized => Immutable for &'_ mut T);
unsafe_impl!(
#[cfg_attr(zerocopy_diagnostic_do_not_recommend_1_85_0, diagnostic::do_not_recommend)]
T: ?Sized => Immutable for &'_ T
);
unsafe_impl!(
#[cfg_attr(zerocopy_diagnostic_do_not_recommend_1_85_0, diagnostic::do_not_recommend)]
T: ?Sized => Immutable for &'_ mut T
);
};

// SAFETY: `Option` is not `#[non_exhaustive]` [1], which means that the types
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-nightly/diagnostic-not-implemented-immutable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `takes_immutable`
--> tests/ui-nightly/diagnostic-not-implemented-immutable.rs:21:23
Expand Down
8 changes: 4 additions & 4 deletions tests/ui-nightly/diagnostic-not-implemented-issue-1296.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fn main() {
// 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.
// This problem was mitigated in Rust 1.85.0 with the stabilization of
// `#[diagnostic::do_not_recommend]`. We apply this attribute to the
// `Immutable` impls for `&T` and `&mut T` on supported versions, which
// suppresses the "consider borrowing here" recommendation.
Foo.write_obj(NotZerocopy(()));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ui-nightly/transmute-ref-dst-not-nocell.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `Dst`
| ^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `Dst`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `AssertDstIsImmutable`
--> tests/ui-nightly/transmute-ref-dst-not-nocell.rs:23:33
Expand Down
8 changes: 4 additions & 4 deletions tests/ui-nightly/transmute-ref-src-not-nocell.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `Src`
| ^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `Src`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `AssertSrcIsImmutable`
--> tests/ui-nightly/transmute-ref-src-not-nocell.rs:23:34
Expand All @@ -43,14 +43,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `Src`
| ^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `Src`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `AssertSrcIsImmutable`
--> tests/ui-nightly/transmute-ref-src-not-nocell.rs:23:34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `try_transmute_ref`
--> src/util/macro_util.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `NotZerocopy<AU16>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `NotZerocopy<AU16>`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `try_transmute_ref`
--> src/util/macro_util.rs
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-stable/diagnostic-not-implemented-immutable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `takes_immutable`
--> tests/ui-stable/diagnostic-not-implemented-immutable.rs:21:23
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-stable/transmute-ref-dst-not-nocell.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `Dst`
| ^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `Dst`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `AssertDstIsImmutable`
--> tests/ui-stable/transmute-ref-dst-not-nocell.rs:23:33
Expand Down
8 changes: 4 additions & 4 deletions tests/ui-stable/transmute-ref-src-not-nocell.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `Src`
| ^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `Src`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `AssertSrcIsImmutable`
--> tests/ui-stable/transmute-ref-src-not-nocell.rs:23:34
Expand All @@ -43,14 +43,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `Src`
| ^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `Src`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `AssertSrcIsImmutable`
--> tests/ui-stable/transmute-ref-src-not-nocell.rs:23:34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `try_transmute_ref`
--> src/util/macro_util.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ help: the trait `zerocopy::Immutable` is not implemented for `NotZerocopy<AU16>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Immutable)]` to `NotZerocopy<AU16>`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
Box<T>
F32<O>
F64<O>
I128<O>
and $N others
note: required by a bound in `try_transmute_ref`
--> src/util/macro_util.rs
Expand Down
8 changes: 4 additions & 4 deletions zerocopy-derive/tests/ui-nightly/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ error[E0277]: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
*const T
*mut T
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -331,14 +331,14 @@ error[E0277]: the trait bound `UnsafeCell<u8>: Immutable` is not satisfied
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
*const T
*mut T
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand Down
8 changes: 4 additions & 4 deletions zerocopy-derive/tests/ui-nightly/struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satis
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
F32<O>
F64<O>
I128<O>
I16<O>
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -217,14 +217,14 @@ error[E0277]: the trait bound `UnsafeCell<u8>: zerocopy::Immutable` is not satis
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
F32<O>
F64<O>
I128<O>
I16<O>
and $N others
= note: required for `[UnsafeCell<u8>; 0]` to implement `zerocopy::Immutable`
= help: see issue #48214
Expand Down
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/ui-nightly/union.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satis
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
F32<O>
F64<O>
I128<O>
I16<O>
and $N others
= note: required for `ManuallyDrop<UnsafeCell<()>>` to implement `zerocopy::Immutable`
= help: see issue #48214
Expand Down
8 changes: 4 additions & 4 deletions zerocopy-derive/tests/ui-stable/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ error[E0277]: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
*const T
*mut T
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -326,14 +326,14 @@ error[E0277]: the trait bound `UnsafeCell<u8>: Immutable` is not satisfied
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
*const T
*mut T
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand Down
8 changes: 4 additions & 4 deletions zerocopy-derive/tests/ui-stable/struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satis
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
F32<O>
F64<O>
I128<O>
I16<O>
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -194,14 +194,14 @@ error[E0277]: the trait bound `UnsafeCell<u8>: zerocopy::Immutable` is not satis
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `zerocopy::Immutable`:
&T
&mut T
()
*const T
*mut T
AU16
F32<O>
F64<O>
I128<O>
I16<O>
and $N others
= note: required for `[UnsafeCell<u8>; 0]` to implement `zerocopy::Immutable`
= help: see issue #48214
Expand Down
Loading
Loading