From a42684dde12a4d9cbdd2bbb4a4b35075dde08c4e Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 28 Mar 2021 07:47:28 +0900 Subject: [PATCH 1/2] Format ui test files --- tests/ui/cfg/cfg_attr-type-mismatch.rs | 3 +- tests/ui/cfg/cfg_attr-type-mismatch.stderr | 8 +- tests/ui/pin_project/add-attr-to-struct.rs | 3 +- .../ui/pin_project/add-attr-to-struct.stderr | 8 +- tests/ui/pin_project/conflict-drop.rs | 3 +- tests/ui/pin_project/conflict-drop.stderr | 10 +- .../pin_project/overlapping_unpin_struct.rs | 3 +- .../overlapping_unpin_struct.stderr | 6 +- tests/ui/pin_project/packed_sneaky-1.rs | 3 +- tests/ui/pin_project/packed_sneaky-1.stderr | 12 +-- .../ui/pin_project/remove-attr-from-field.rs | 3 +- .../pin_project/remove-attr-from-field.stderr | 8 +- .../ui/pin_project/remove-attr-from-struct.rs | 3 +- .../remove-attr-from-struct.stderr | 40 +++---- tests/ui/pinned_drop/call-drop-inner.rs | 3 +- tests/ui/pinned_drop/call-drop-inner.stderr | 8 +- tests/ui/pinned_drop/conditional-drop-impl.rs | 3 +- .../pinned_drop/conditional-drop-impl.stderr | 18 ++-- tests/ui/pinned_drop/invalid.rs | 6 +- tests/ui/pinned_drop/invalid.stderr | 100 +++++++++--------- .../ui/pinned_drop/pinned-drop-no-attr-arg.rs | 3 +- .../pinned-drop-no-attr-arg.stderr | 6 +- tests/ui/pinned_drop/self.rs | 6 +- tests/ui/pinned_drop/self.stderr | 34 +++--- tests/ui/pinned_drop/unsafe-call.rs | 3 +- tests/ui/pinned_drop/unsafe-call.stderr | 4 +- .../marker_trait_attr-feature-gate.rs | 3 +- .../marker_trait_attr-feature-gate.stderr | 6 +- .../ui/unstable-features/marker_trait_attr.rs | 3 +- .../marker_trait_attr.stderr | 6 +- .../overlapping_marker_traits-feature-gate.rs | 3 +- ...rlapping_marker_traits-feature-gate.stderr | 6 +- .../overlapping_marker_traits.rs | 7 +- .../overlapping_marker_traits.stderr | 6 +- 34 files changed, 183 insertions(+), 164 deletions(-) diff --git a/tests/ui/cfg/cfg_attr-type-mismatch.rs b/tests/ui/cfg/cfg_attr-type-mismatch.rs index b075af9b..1b9664b5 100644 --- a/tests/ui/cfg/cfg_attr-type-mismatch.rs +++ b/tests/ui/cfg/cfg_attr-type-mismatch.rs @@ -1,6 +1,7 @@ -use pin_project::pin_project; use std::pin::Pin; +use pin_project::pin_project; + #[cfg_attr(not(any()), pin_project)] struct Foo { #[cfg_attr(any(), pin)] diff --git a/tests/ui/cfg/cfg_attr-type-mismatch.stderr b/tests/ui/cfg/cfg_attr-type-mismatch.stderr index 89172a24..576a08c2 100644 --- a/tests/ui/cfg/cfg_attr-type-mismatch.stderr +++ b/tests/ui/cfg/cfg_attr-type-mismatch.stderr @@ -1,7 +1,7 @@ error[E0308]: mismatched types - --> $DIR/cfg_attr-type-mismatch.rs:19:27 + --> $DIR/cfg_attr-type-mismatch.rs:20:27 | -19 | let _: Pin<&mut u8> = x.f; //~ ERROR E0308 +20 | let _: Pin<&mut u8> = x.f; //~ ERROR E0308 | ------------ ^^^ expected struct `Pin`, found `&mut u8` | | | expected due to this @@ -10,9 +10,9 @@ error[E0308]: mismatched types found mutable reference `&mut u8` error[E0308]: mismatched types - --> $DIR/cfg_attr-type-mismatch.rs:23:22 + --> $DIR/cfg_attr-type-mismatch.rs:24:22 | -23 | let _: &mut u8 = x.f; //~ ERROR E0308 +24 | let _: &mut u8 = x.f; //~ ERROR E0308 | ------- ^^^ | | | | | expected `&mut u8`, found struct `Pin` diff --git a/tests/ui/pin_project/add-attr-to-struct.rs b/tests/ui/pin_project/add-attr-to-struct.rs index 55f1561e..045e7966 100644 --- a/tests/ui/pin_project/add-attr-to-struct.rs +++ b/tests/ui/pin_project/add-attr-to-struct.rs @@ -1,6 +1,7 @@ +use std::marker::PhantomPinned; + use auxiliary_macro::add_pin_attr; use pin_project::pin_project; -use std::marker::PhantomPinned; #[pin_project] #[add_pin_attr(struct)] //~ ERROR duplicate #[pin] attribute diff --git a/tests/ui/pin_project/add-attr-to-struct.stderr b/tests/ui/pin_project/add-attr-to-struct.stderr index 27656d66..f3ee9e44 100644 --- a/tests/ui/pin_project/add-attr-to-struct.stderr +++ b/tests/ui/pin_project/add-attr-to-struct.stderr @@ -1,15 +1,15 @@ error: duplicate #[pin] attribute - --> $DIR/add-attr-to-struct.rs:6:1 + --> $DIR/add-attr-to-struct.rs:7:1 | -6 | #[add_pin_attr(struct)] //~ ERROR duplicate #[pin] attribute +7 | #[add_pin_attr(struct)] //~ ERROR duplicate #[pin] attribute | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) error: #[pin] attribute may only be used on fields of structs or variants - --> $DIR/add-attr-to-struct.rs:12:1 + --> $DIR/add-attr-to-struct.rs:13:1 | -12 | #[add_pin_attr(struct)] //~ ERROR #[pin] attribute may only be used on fields of structs or variants +13 | #[add_pin_attr(struct)] //~ ERROR #[pin] attribute may only be used on fields of structs or variants | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pin_project/conflict-drop.rs b/tests/ui/pin_project/conflict-drop.rs index 908f5c0a..4fdb118d 100644 --- a/tests/ui/pin_project/conflict-drop.rs +++ b/tests/ui/pin_project/conflict-drop.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[pin_project] //~ ERROR E0119 struct Foo { #[pin] diff --git a/tests/ui/pin_project/conflict-drop.stderr b/tests/ui/pin_project/conflict-drop.stderr index d5ca7b3d..4979c575 100644 --- a/tests/ui/pin_project/conflict-drop.stderr +++ b/tests/ui/pin_project/conflict-drop.stderr @@ -1,7 +1,7 @@ error[E0119]: conflicting implementations of trait `_::FooMustNotImplDrop` for type `Foo<_, _>`: - --> $DIR/conflict-drop.rs:4:1 + --> $DIR/conflict-drop.rs:5:1 | -4 | #[pin_project] //~ ERROR E0119 +5 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ | | | first implementation here @@ -10,10 +10,10 @@ error[E0119]: conflicting implementations of trait `_::FooMustNotImplDrop` for t = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `Bar<_, _>`: - --> $DIR/conflict-drop.rs:15:15 + --> $DIR/conflict-drop.rs:16:15 | -15 | #[pin_project(PinnedDrop)] //~ ERROR E0119 +16 | #[pin_project(PinnedDrop)] //~ ERROR E0119 | ^^^^^^^^^^ conflicting implementation for `Bar<_, _>` ... -27 | impl Drop for Bar { +28 | impl Drop for Bar { | ----------------------------- first implementation here diff --git a/tests/ui/pin_project/overlapping_unpin_struct.rs b/tests/ui/pin_project/overlapping_unpin_struct.rs index 8db0855c..abfd5d13 100644 --- a/tests/ui/pin_project/overlapping_unpin_struct.rs +++ b/tests/ui/pin_project/overlapping_unpin_struct.rs @@ -1,6 +1,7 @@ -use pin_project::pin_project; use std::marker::PhantomPinned; +use pin_project::pin_project; + #[pin_project] struct S { #[pin] diff --git a/tests/ui/pin_project/overlapping_unpin_struct.stderr b/tests/ui/pin_project/overlapping_unpin_struct.stderr index 296b063a..b4a207a3 100644 --- a/tests/ui/pin_project/overlapping_unpin_struct.stderr +++ b/tests/ui/pin_project/overlapping_unpin_struct.stderr @@ -1,10 +1,10 @@ error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/overlapping_unpin_struct.rs:17:5 + --> $DIR/overlapping_unpin_struct.rs:18:5 | -14 | fn is_unpin() {} +15 | fn is_unpin() {} | ----- required by this bound in `is_unpin` ... -17 | is_unpin::>(); //~ ERROR E0277 +18 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__S<'_, PhantomPinned>`, the trait `Unpin` is not implemented for `PhantomPinned` | = note: required because it appears within the type `_::__S<'_, PhantomPinned>` diff --git a/tests/ui/pin_project/packed_sneaky-1.rs b/tests/ui/pin_project/packed_sneaky-1.rs index 38f6fe08..72d3d3e8 100644 --- a/tests/ui/pin_project/packed_sneaky-1.rs +++ b/tests/ui/pin_project/packed_sneaky-1.rs @@ -1,6 +1,7 @@ +use std::pin::Pin; + use auxiliary_macro::hidden_repr; use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; -use std::pin::Pin; #[pin_project] //~ ERROR may not be used on #[repr(packed)] types #[hidden_repr(packed)] diff --git a/tests/ui/pin_project/packed_sneaky-1.stderr b/tests/ui/pin_project/packed_sneaky-1.stderr index 510200ee..67bcd1b1 100644 --- a/tests/ui/pin_project/packed_sneaky-1.stderr +++ b/tests/ui/pin_project/packed_sneaky-1.stderr @@ -1,17 +1,17 @@ error: #[pin_project] attribute may not be used on #[repr(packed)] types - --> $DIR/packed_sneaky-1.rs:6:15 + --> $DIR/packed_sneaky-1.rs:7:15 | -6 | #[hidden_repr(packed)] +7 | #[hidden_repr(packed)] | ^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types - --> $DIR/packed_sneaky-1.rs:13:15 + --> $DIR/packed_sneaky-1.rs:14:15 | -13 | #[hidden_repr(packed)] +14 | #[hidden_repr(packed)] | ^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types - --> $DIR/packed_sneaky-1.rs:22:15 + --> $DIR/packed_sneaky-1.rs:23:15 | -22 | #[hidden_repr(packed)] +23 | #[hidden_repr(packed)] | ^^^^^^ diff --git a/tests/ui/pin_project/remove-attr-from-field.rs b/tests/ui/pin_project/remove-attr-from-field.rs index bec83023..fd14da37 100644 --- a/tests/ui/pin_project/remove-attr-from-field.rs +++ b/tests/ui/pin_project/remove-attr-from-field.rs @@ -1,6 +1,7 @@ +use std::{marker::PhantomPinned, pin::Pin}; + use auxiliary_macro::remove_attr; use pin_project::pin_project; -use std::{marker::PhantomPinned, pin::Pin}; fn is_unpin() {} diff --git a/tests/ui/pin_project/remove-attr-from-field.stderr b/tests/ui/pin_project/remove-attr-from-field.stderr index 5d8caacd..486bc00b 100644 --- a/tests/ui/pin_project/remove-attr-from-field.stderr +++ b/tests/ui/pin_project/remove-attr-from-field.stderr @@ -1,7 +1,7 @@ error[E0308]: mismatched types - --> $DIR/remove-attr-from-field.rs:27:38 + --> $DIR/remove-attr-from-field.rs:28:38 | -27 | let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 +28 | let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 | ----------------------- ^^^ expected struct `Pin`, found `&mut PhantomPinned` | | | expected due to this @@ -10,9 +10,9 @@ error[E0308]: mismatched types found mutable reference `&mut PhantomPinned` error[E0308]: mismatched types - --> $DIR/remove-attr-from-field.rs:31:38 + --> $DIR/remove-attr-from-field.rs:32:38 | -31 | let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 +32 | let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 | ----------------------- ^^^ expected struct `Pin`, found `&mut PhantomPinned` | | | expected due to this diff --git a/tests/ui/pin_project/remove-attr-from-struct.rs b/tests/ui/pin_project/remove-attr-from-struct.rs index 0086cf96..cbe5aba2 100644 --- a/tests/ui/pin_project/remove-attr-from-struct.rs +++ b/tests/ui/pin_project/remove-attr-from-struct.rs @@ -1,6 +1,7 @@ +use std::{marker::PhantomPinned, pin::Pin}; + use auxiliary_macro::remove_attr; use pin_project::pin_project; -use std::{marker::PhantomPinned, pin::Pin}; fn is_unpin() {} diff --git a/tests/ui/pin_project/remove-attr-from-struct.stderr b/tests/ui/pin_project/remove-attr-from-struct.stderr index 4652b663..2b387ec2 100644 --- a/tests/ui/pin_project/remove-attr-from-struct.stderr +++ b/tests/ui/pin_project/remove-attr-from-struct.stderr @@ -1,71 +1,71 @@ error: #[pin_project] attribute has been removed - --> $DIR/remove-attr-from-struct.rs:21:1 + --> $DIR/remove-attr-from-struct.rs:22:1 | -21 | #[pin_project] //~ ERROR has been removed +22 | #[pin_project] //~ ERROR has been removed | ^^^^^^^^^^^^^^ | = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot find attribute `pin` in this scope - --> $DIR/remove-attr-from-struct.rs:17:7 + --> $DIR/remove-attr-from-struct.rs:18:7 | -17 | #[pin] //~ ERROR cannot find attribute `pin` in this scope +18 | #[pin] //~ ERROR cannot find attribute `pin` in this scope | ^^^ error: cannot find attribute `pin` in this scope - --> $DIR/remove-attr-from-struct.rs:10:7 + --> $DIR/remove-attr-from-struct.rs:11:7 | -10 | #[pin] //~ ERROR cannot find attribute `pin` in this scope +11 | #[pin] //~ ERROR cannot find attribute `pin` in this scope | ^^^ error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/remove-attr-from-struct.rs:34:5 + --> $DIR/remove-attr-from-struct.rs:35:5 | -5 | fn is_unpin() {} +6 | fn is_unpin() {} | ----- required by this bound in `is_unpin` ... -34 | is_unpin::(); //~ ERROR E0277 +35 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^ within `A`, the trait `Unpin` is not implemented for `PhantomPinned` | = note: required because it appears within the type `A` error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/remove-attr-from-struct.rs:35:5 + --> $DIR/remove-attr-from-struct.rs:36:5 | -5 | fn is_unpin() {} +6 | fn is_unpin() {} | ----- required by this bound in `is_unpin` ... -35 | is_unpin::(); //~ ERROR E0277 +36 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^ within `B`, the trait `Unpin` is not implemented for `PhantomPinned` | = note: required because it appears within the type `B` error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/remove-attr-from-struct.rs:39:13 + --> $DIR/remove-attr-from-struct.rs:40:13 | -39 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 +40 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^^ within `A`, the trait `Unpin` is not implemented for `PhantomPinned` | = note: required because it appears within the type `A` = note: required by `Pin::

::new` error[E0599]: no method named `project` found for struct `Pin<&mut A>` in the current scope - --> $DIR/remove-attr-from-struct.rs:39:30 + --> $DIR/remove-attr-from-struct.rs:40:30 | -39 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 +40 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^ method not found in `Pin<&mut A>` error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/remove-attr-from-struct.rs:42:13 + --> $DIR/remove-attr-from-struct.rs:43:13 | -42 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 +43 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^^ within `B`, the trait `Unpin` is not implemented for `PhantomPinned` | = note: required because it appears within the type `B` = note: required by `Pin::

::new` error[E0599]: no method named `project` found for struct `Pin<&mut B>` in the current scope - --> $DIR/remove-attr-from-struct.rs:42:30 + --> $DIR/remove-attr-from-struct.rs:43:30 | -42 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 +43 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^ method not found in `Pin<&mut B>` diff --git a/tests/ui/pinned_drop/call-drop-inner.rs b/tests/ui/pinned_drop/call-drop-inner.rs index 4171ed59..9f89942b 100644 --- a/tests/ui/pinned_drop/call-drop-inner.rs +++ b/tests/ui/pinned_drop/call-drop-inner.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] struct Struct { f: bool, diff --git a/tests/ui/pinned_drop/call-drop-inner.stderr b/tests/ui/pinned_drop/call-drop-inner.stderr index 53194b00..463e8375 100644 --- a/tests/ui/pinned_drop/call-drop-inner.stderr +++ b/tests/ui/pinned_drop/call-drop-inner.stderr @@ -1,14 +1,14 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/call-drop-inner.rs:12:9 + --> $DIR/call-drop-inner.rs:13:9 | -12 | __drop_inner(__self); +13 | __drop_inner(__self); | ^^^^^^^^^^^^ ------ supplied 1 argument | | | expected 0 arguments | note: function defined here - --> $DIR/call-drop-inner.rs:9:1 + --> $DIR/call-drop-inner.rs:10:1 | -9 | #[pinned_drop] +10 | #[pinned_drop] | ^^^^^^^^^^^^^^ = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pinned_drop/conditional-drop-impl.rs b/tests/ui/pinned_drop/conditional-drop-impl.rs index fecfd50d..23d756d4 100644 --- a/tests/ui/pinned_drop/conditional-drop-impl.rs +++ b/tests/ui/pinned_drop/conditional-drop-impl.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + // In `Drop` impl, the implementor must specify the same requirement as type definition. struct DropImpl { diff --git a/tests/ui/pinned_drop/conditional-drop-impl.stderr b/tests/ui/pinned_drop/conditional-drop-impl.stderr index 6381a296..31203f03 100644 --- a/tests/ui/pinned_drop/conditional-drop-impl.stderr +++ b/tests/ui/pinned_drop/conditional-drop-impl.stderr @@ -1,26 +1,26 @@ error[E0367]: `Drop` impl requires `T: Unpin` but the struct it is implemented for does not - --> $DIR/conditional-drop-impl.rs:10:9 + --> $DIR/conditional-drop-impl.rs:11:9 | -10 | impl Drop for DropImpl { +11 | impl Drop for DropImpl { | ^^^^^ | note: the implementor must specify the same requirement - --> $DIR/conditional-drop-impl.rs:6:1 + --> $DIR/conditional-drop-impl.rs:7:1 | -6 | / struct DropImpl { -7 | | f: T, -8 | | } +7 | / struct DropImpl { +8 | | f: T, +9 | | } | |_^ error[E0277]: `T` cannot be unpinned - --> $DIR/conditional-drop-impl.rs:15:15 + --> $DIR/conditional-drop-impl.rs:16:15 | -15 | #[pin_project(PinnedDrop)] //~ ERROR E0277 +16 | #[pin_project(PinnedDrop)] //~ ERROR E0277 | ^^^^^^^^^^ the trait `Unpin` is not implemented for `T` | = note: required because of the requirements on the impl of `PinnedDrop` for `PinnedDropImpl` = note: required by `pin_project::__private::PinnedDrop::drop` help: consider restricting type parameter `T` | -16 | struct PinnedDropImpl { +17 | struct PinnedDropImpl { | ^^^^^^^ diff --git a/tests/ui/pinned_drop/invalid.rs b/tests/ui/pinned_drop/invalid.rs index 7e36750c..fdadf8a5 100644 --- a/tests/ui/pinned_drop/invalid.rs +++ b/tests/ui/pinned_drop/invalid.rs @@ -1,7 +1,8 @@ mod argument { - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; + use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] struct UnexpectedArg1(()); @@ -128,9 +129,10 @@ mod assoc_item { } mod method { - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; + use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] struct RetUnit(()); diff --git a/tests/ui/pinned_drop/invalid.stderr b/tests/ui/pinned_drop/invalid.stderr index 277a2fa1..499b0d91 100644 --- a/tests/ui/pinned_drop/invalid.stderr +++ b/tests/ui/pinned_drop/invalid.stderr @@ -1,143 +1,143 @@ error: unexpected token: foo - --> $DIR/invalid.rs:8:19 + --> $DIR/invalid.rs:9:19 | -8 | #[pinned_drop(foo)] //~ ERROR unexpected token +9 | #[pinned_drop(foo)] //~ ERROR unexpected token | ^^^ error: duplicate #[pinned_drop] attribute - --> $DIR/invalid.rs:29:5 + --> $DIR/invalid.rs:30:5 | -29 | #[pinned_drop] //~ ERROR duplicate #[pinned_drop] attribute +30 | #[pinned_drop] //~ ERROR duplicate #[pinned_drop] attribute | ^^^^^^^^^^^^^^ error: #[pinned_drop] may only be used on implementation for the `PinnedDrop` trait - --> $DIR/invalid.rs:42:10 + --> $DIR/invalid.rs:43:10 | -42 | impl Drop for TraitImpl {} //~ ERROR may only be used on implementation for the `PinnedDrop` trait +43 | impl Drop for TraitImpl {} //~ ERROR may only be used on implementation for the `PinnedDrop` trait | ^^^^ error: #[pinned_drop] may only be used on implementation for the `PinnedDrop` trait - --> $DIR/invalid.rs:48:10 + --> $DIR/invalid.rs:49:10 | -48 | impl InherentImpl {} //~ ERROR may only be used on implementation for the `PinnedDrop` trait +49 | impl InherentImpl {} //~ ERROR may only be used on implementation for the `PinnedDrop` trait | ^^^^^^^^^^^^ error: expected `impl` - --> $DIR/invalid.rs:51:5 + --> $DIR/invalid.rs:52:5 | -51 | fn func(_: Pin<&mut ()>) {} //~ ERROR expected `impl` +52 | fn func(_: Pin<&mut ()>) {} //~ ERROR expected `impl` | ^^ error: implementing the trait `PinnedDrop` is not unsafe - --> $DIR/invalid.rs:61:5 + --> $DIR/invalid.rs:62:5 | -61 | unsafe impl PinnedDrop for Impl { +62 | unsafe impl PinnedDrop for Impl { | ^^^^^^ error: implementing the method `drop` is not unsafe - --> $DIR/invalid.rs:71:9 + --> $DIR/invalid.rs:72:9 | -71 | unsafe fn drop(self: Pin<&mut Self>) {} //~ ERROR implementing the method `drop` is not unsafe +72 | unsafe fn drop(self: Pin<&mut Self>) {} //~ ERROR implementing the method `drop` is not unsafe | ^^^^^^ error: not all trait items implemented, missing: `drop` - --> $DIR/invalid.rs:82:5 + --> $DIR/invalid.rs:83:5 | -82 | impl PinnedDrop for Empty {} //~ ERROR not all trait items implemented, missing: `drop` +83 | impl PinnedDrop for Empty {} //~ ERROR not all trait items implemented, missing: `drop` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: const `A` is not a member of trait `PinnedDrop` - --> $DIR/invalid.rs:89:9 + --> $DIR/invalid.rs:90:9 | -89 | const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` +90 | const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` | ^^^^^^^^^^^^^^^^ error: const `A` is not a member of trait `PinnedDrop` - --> $DIR/invalid.rs:99:9 - | -99 | const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` - | ^^^^^^^^^^^^^^^^ + --> $DIR/invalid.rs:100:9 + | +100 | const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` + | ^^^^^^^^^^^^^^^^ error: type `A` is not a member of trait `PinnedDrop` - --> $DIR/invalid.rs:107:9 + --> $DIR/invalid.rs:108:9 | -107 | type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` +108 | type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` | ^^^^^^^^^^^^ error: type `A` is not a member of trait `PinnedDrop` - --> $DIR/invalid.rs:117:9 + --> $DIR/invalid.rs:118:9 | -117 | type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` +118 | type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` | ^^^^^^^^^^^^ error: duplicate definitions with name `drop` - --> $DIR/invalid.rs:126:9 + --> $DIR/invalid.rs:127:9 | -126 | fn drop(self: Pin<&mut Self>) {} //~ ERROR duplicate definitions with name `drop` +127 | fn drop(self: Pin<&mut Self>) {} //~ ERROR duplicate definitions with name `drop` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: method `drop` must return the unit type - --> $DIR/invalid.rs:147:42 + --> $DIR/invalid.rs:149:42 | -147 | fn drop(self: Pin<&mut Self>) -> Self {} //~ ERROR method `drop` must return the unit type +149 | fn drop(self: Pin<&mut Self>) -> Self {} //~ ERROR method `drop` must return the unit type | ^^^^ error: method `drop` must take an argument `self: Pin<&mut Self>` - --> $DIR/invalid.rs:155:16 + --> $DIR/invalid.rs:157:16 | -155 | fn drop() {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` +157 | fn drop() {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` | ^^ error: method `drop` must take an argument `self: Pin<&mut Self>` - --> $DIR/invalid.rs:163:17 + --> $DIR/invalid.rs:165:17 | -163 | fn drop(self: Pin<&mut Self>, _: ()) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` +165 | fn drop(self: Pin<&mut Self>, _: ()) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: method `drop` must take an argument `self: Pin<&mut Self>` - --> $DIR/invalid.rs:171:17 + --> $DIR/invalid.rs:173:17 | -171 | fn drop(&mut self) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` +173 | fn drop(&mut self) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` | ^^^^^^^^^ error: method `drop` must take an argument `self: Pin<&mut Self>` - --> $DIR/invalid.rs:179:17 + --> $DIR/invalid.rs:181:17 | -179 | fn drop(_: Pin<&mut Self>) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` +181 | fn drop(_: Pin<&mut Self>) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` | ^^^^^^^^^^^^^^^^^ error: method `drop` must take an argument `self: Pin<&mut Self>` - --> $DIR/invalid.rs:187:17 + --> $DIR/invalid.rs:189:17 | -187 | fn drop(self: Pin<&Self>) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` +189 | fn drop(self: Pin<&Self>) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` | ^^^^^^^^^^^^^^^^ error: method `drop` must take an argument `self: Pin<&mut Self>` - --> $DIR/invalid.rs:195:17 + --> $DIR/invalid.rs:197:17 | -195 | fn drop(self: Pin<&mut ()>) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` +197 | fn drop(self: Pin<&mut ()>) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` | ^^^^^^^^^^^^^^^^^^ error: method `pinned_drop` is not a member of trait `PinnedDrop - --> $DIR/invalid.rs:203:12 + --> $DIR/invalid.rs:205:12 | -203 | fn pinned_drop(self: Pin<&mut Self>) {} //~ ERROR method `pinned_drop` is not a member of trait `PinnedDrop +205 | fn pinned_drop(self: Pin<&mut Self>) {} //~ ERROR method `pinned_drop` is not a member of trait `PinnedDrop | ^^^^^^^^^^^ error: implementing the trait `PinnedDrop` on this type is unsupported - --> $DIR/invalid.rs:211:25 + --> $DIR/invalid.rs:213:25 | -211 | impl PinnedDrop for () { +213 | impl PinnedDrop for () { | ^^ error: implementing the trait `PinnedDrop` on this type is unsupported - --> $DIR/invalid.rs:217:25 + --> $DIR/invalid.rs:219:25 | -217 | impl PinnedDrop for &mut A { +219 | impl PinnedDrop for &mut A { | ^^^^^^ error: implementing the trait `PinnedDrop` on this type is unsupported - --> $DIR/invalid.rs:223:25 + --> $DIR/invalid.rs:225:25 | -223 | impl PinnedDrop for [A] { +225 | impl PinnedDrop for [A] { | ^^^ diff --git a/tests/ui/pinned_drop/pinned-drop-no-attr-arg.rs b/tests/ui/pinned_drop/pinned-drop-no-attr-arg.rs index f9db79c0..391f2901 100644 --- a/tests/ui/pinned_drop/pinned-drop-no-attr-arg.rs +++ b/tests/ui/pinned_drop/pinned-drop-no-attr-arg.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[pin_project] struct S { #[pin] diff --git a/tests/ui/pinned_drop/pinned-drop-no-attr-arg.stderr b/tests/ui/pinned_drop/pinned-drop-no-attr-arg.stderr index 6f868bfe..304ed983 100644 --- a/tests/ui/pinned_drop/pinned-drop-no-attr-arg.stderr +++ b/tests/ui/pinned_drop/pinned-drop-no-attr-arg.stderr @@ -1,8 +1,8 @@ error[E0119]: conflicting implementations of trait `pin_project::__private::PinnedDrop` for type `S`: - --> $DIR/pinned-drop-no-attr-arg.rs:11:1 + --> $DIR/pinned-drop-no-attr-arg.rs:12:1 | -4 | #[pin_project] +5 | #[pin_project] | -------------- first implementation here ... -11 | impl PinnedDrop for S { +12 | impl PinnedDrop for S { | ^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S` diff --git a/tests/ui/pinned_drop/self.rs b/tests/ui/pinned_drop/self.rs index 03825ca0..ff634022 100644 --- a/tests/ui/pinned_drop/self.rs +++ b/tests/ui/pinned_drop/self.rs @@ -1,7 +1,8 @@ pub mod self_in_macro_def { - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; + use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] pub struct S { f: (), @@ -23,9 +24,10 @@ pub mod self_in_macro_def { } pub mod self_span { - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; + use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] pub struct S { f: (), diff --git a/tests/ui/pinned_drop/self.stderr b/tests/ui/pinned_drop/self.stderr index edab117b..4ccbc413 100644 --- a/tests/ui/pinned_drop/self.stderr +++ b/tests/ui/pinned_drop/self.stderr @@ -1,42 +1,42 @@ error: `self` parameter is only allowed in associated functions - --> $DIR/self.rs:17:26 + --> $DIR/self.rs:18:26 | -17 | fn f(self: ()) {} //~ ERROR `self` parameter is only allowed in associated functions +18 | fn f(self: ()) {} //~ ERROR `self` parameter is only allowed in associated functions | ^^^^ not semantically valid as function parameter ... -20 | t!(); +21 | t!(); | ----- in this macro invocation | = note: associated functions are those in `impl` or `trait` definitions = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0434]: can't capture dynamic environment in a fn item - --> $DIR/self.rs:15:29 + --> $DIR/self.rs:16:29 | -15 | let _ = self; //~ ERROR E0434 +16 | let _ = self; //~ ERROR E0434 | ^^^^ ... -20 | t!(); +21 | t!(); | ----- in this macro invocation | = help: use the `|| { ... }` closure form instead = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0423]: expected value, found struct `S` - --> $DIR/self.rs:38:27 + --> $DIR/self.rs:40:27 | -30 | / pub struct S { -31 | | f: (), -32 | | } +32 | / pub struct S { +33 | | f: (), +34 | | } | |_____- `S` defined here ... -38 | let _: Self = Self; //~ ERROR E0423 +40 | let _: Self = Self; //~ ERROR E0423 | ^^^^ help: use struct literal syntax instead: `S { f: val }` error[E0308]: mismatched types - --> $DIR/self.rs:37:25 + --> $DIR/self.rs:39:25 | -37 | let _: () = self; //~ ERROR E0308 +39 | let _: () = self; //~ ERROR E0308 | -- ^^^^ expected `()`, found struct `Pin` | | | expected due to this @@ -45,9 +45,9 @@ error[E0308]: mismatched types found struct `Pin<&mut self_span::S>` error[E0308]: mismatched types - --> $DIR/self.rs:50:25 + --> $DIR/self.rs:52:25 | -50 | let _: () = self; //~ ERROR E0308 +52 | let _: () = self; //~ ERROR E0308 | -- ^^^^ expected `()`, found struct `Pin` | | | expected due to this @@ -56,7 +56,7 @@ error[E0308]: mismatched types found struct `Pin<&mut E>` error[E0533]: expected unit struct, unit variant or constant, found struct variant `Self::V` - --> $DIR/self.rs:51:27 + --> $DIR/self.rs:53:27 | -51 | let _: Self = Self::V; //~ ERROR E0533 +53 | let _: Self = Self::V; //~ ERROR E0533 | ^^^^^^^ diff --git a/tests/ui/pinned_drop/unsafe-call.rs b/tests/ui/pinned_drop/unsafe-call.rs index 7faf0fa2..3ee2b56c 100644 --- a/tests/ui/pinned_drop/unsafe-call.rs +++ b/tests/ui/pinned_drop/unsafe-call.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] struct S { #[pin] diff --git a/tests/ui/pinned_drop/unsafe-call.stderr b/tests/ui/pinned_drop/unsafe-call.stderr index cd5e572a..6216200f 100644 --- a/tests/ui/pinned_drop/unsafe-call.stderr +++ b/tests/ui/pinned_drop/unsafe-call.stderr @@ -1,7 +1,7 @@ error[E0133]: call to unsafe function is unsafe and requires unsafe function or block - --> $DIR/unsafe-call.rs:13:9 + --> $DIR/unsafe-call.rs:14:9 | -13 | self.project().f.get_unchecked_mut(); //~ ERROR call to unsafe function is unsafe and requires unsafe function or block [E0133] +14 | self.project().f.get_unchecked_mut(); //~ ERROR call to unsafe function is unsafe and requires unsafe function or block [E0133] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | = note: consult the function's documentation for information on how to avoid undefined behavior diff --git a/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs b/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs index 127cd1a7..542250bd 100644 --- a/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs +++ b/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs @@ -1,8 +1,9 @@ // Note: If you change this test, change 'marker_trait_attr.rs' at the same time. -use pin_project::pin_project; use std::marker::PhantomPinned; +use pin_project::pin_project; + #[pin_project] //~ ERROR E0119 struct Struct { #[pin] diff --git a/tests/ui/unstable-features/marker_trait_attr-feature-gate.stderr b/tests/ui/unstable-features/marker_trait_attr-feature-gate.stderr index bab534b9..44ee694b 100644 --- a/tests/ui/unstable-features/marker_trait_attr-feature-gate.stderr +++ b/tests/ui/unstable-features/marker_trait_attr-feature-gate.stderr @@ -1,10 +1,10 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Struct<_>`: - --> $DIR/marker_trait_attr-feature-gate.rs:6:1 + --> $DIR/marker_trait_attr-feature-gate.rs:7:1 | -6 | #[pin_project] //~ ERROR E0119 +7 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Struct<_>` ... -13 | impl Unpin for Struct {} +14 | impl Unpin for Struct {} | --------------------------- first implementation here | = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unstable-features/marker_trait_attr.rs b/tests/ui/unstable-features/marker_trait_attr.rs index d6eab212..9c8e6643 100644 --- a/tests/ui/unstable-features/marker_trait_attr.rs +++ b/tests/ui/unstable-features/marker_trait_attr.rs @@ -6,9 +6,10 @@ // See https://github.com/taiki-e/pin-project/issues/105#issuecomment-535355974 -use pin_project::pin_project; use std::marker::PhantomPinned; +use pin_project::pin_project; + #[pin_project] //~ ERROR E0119 struct Struct { #[pin] diff --git a/tests/ui/unstable-features/marker_trait_attr.stderr b/tests/ui/unstable-features/marker_trait_attr.stderr index 9b3ec57e..8b053490 100644 --- a/tests/ui/unstable-features/marker_trait_attr.stderr +++ b/tests/ui/unstable-features/marker_trait_attr.stderr @@ -1,10 +1,10 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Struct<_>`: - --> $DIR/marker_trait_attr.rs:12:1 + --> $DIR/marker_trait_attr.rs:13:1 | -12 | #[pin_project] //~ ERROR E0119 +13 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Struct<_>` ... -19 | impl Unpin for Struct {} +20 | impl Unpin for Struct {} | --------------------------- first implementation here | = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs b/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs index 9d1b8b86..012c8709 100644 --- a/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs +++ b/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs @@ -1,8 +1,9 @@ // Note: If you change this test, change 'overlapping_marker_traits.rs' at the same time. -use pin_project::pin_project; use std::marker::PhantomPinned; +use pin_project::pin_project; + #[pin_project] //~ ERROR E0119 struct Struct { #[pin] diff --git a/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.stderr b/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.stderr index 4a8e2384..cc7d0878 100644 --- a/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.stderr +++ b/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.stderr @@ -1,10 +1,10 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Struct<_>`: - --> $DIR/overlapping_marker_traits-feature-gate.rs:6:1 + --> $DIR/overlapping_marker_traits-feature-gate.rs:7:1 | -6 | #[pin_project] //~ ERROR E0119 +7 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Struct<_>` ... -13 | impl Unpin for Struct {} +14 | impl Unpin for Struct {} | --------------------------- first implementation here | = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unstable-features/overlapping_marker_traits.rs b/tests/ui/unstable-features/overlapping_marker_traits.rs index 0e0cddd9..8dc27c1d 100644 --- a/tests/ui/unstable-features/overlapping_marker_traits.rs +++ b/tests/ui/unstable-features/overlapping_marker_traits.rs @@ -3,16 +3,17 @@ // This feature could break the guarantee for Unpin provided by pin-project, // but was removed in https://github.com/rust-lang/rust/pull/68544 (nightly-2020-02-06). // Refs: -// * https://github.com/rust-lang/rust/issues/29864#issuecomment-515780867. -// * https://github.com/taiki-e/pin-project/issues/105 +// - https://github.com/rust-lang/rust/issues/29864#issuecomment-515780867 +// - https://github.com/taiki-e/pin-project/issues/105 // overlapping_marker_traits // Tracking issue: https://github.com/rust-lang/rust/issues/29864 #![feature(overlapping_marker_traits)] -use pin_project::pin_project; use std::marker::PhantomPinned; +use pin_project::pin_project; + #[pin_project] struct Struct { #[pin] diff --git a/tests/ui/unstable-features/overlapping_marker_traits.stderr b/tests/ui/unstable-features/overlapping_marker_traits.stderr index 91aaf6ca..f877f4dd 100644 --- a/tests/ui/unstable-features/overlapping_marker_traits.stderr +++ b/tests/ui/unstable-features/overlapping_marker_traits.stderr @@ -7,12 +7,12 @@ error[E0557]: feature has been removed = note: removed in favor of `#![feature(marker_trait_attr)]` error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Struct<_>`: - --> $DIR/overlapping_marker_traits.rs:16:1 + --> $DIR/overlapping_marker_traits.rs:17:1 | -16 | #[pin_project] +17 | #[pin_project] | ^^^^^^^^^^^^^^ conflicting implementation for `Struct<_>` ... -23 | impl Unpin for Struct {} +24 | impl Unpin for Struct {} | --------------------------- first implementation here | = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) From c9be8c97876b8cfe6b3d4d945e37cf2de2c5c226 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 28 Mar 2021 08:07:50 +0900 Subject: [PATCH 2/2] Prepare for removal of safe_packed_borrows lint --- examples/not_unpin-expanded.rs | 2 +- examples/pinned_drop-expanded.rs | 2 +- examples/project_replace-expanded.rs | 2 +- examples/struct-default-expanded.rs | 8 ++--- examples/unsafe_unpin-expanded.rs | 2 +- .../src/pin_project/derive.rs | 30 ++++++++++++------- tests/expand/default/struct.expanded.rs | 2 +- tests/expand/default/tuple_struct.expanded.rs | 2 +- tests/expand/multifields/struct.expanded.rs | 2 +- .../multifields/tuple_struct.expanded.rs | 2 +- tests/expand/naming/struct-all.expanded.rs | 2 +- tests/expand/naming/struct-mut.expanded.rs | 2 +- tests/expand/naming/struct-none.expanded.rs | 2 +- tests/expand/naming/struct-own.expanded.rs | 2 +- tests/expand/naming/struct-ref.expanded.rs | 2 +- .../naming/tuple_struct-all.expanded.rs | 2 +- .../naming/tuple_struct-mut.expanded.rs | 2 +- .../naming/tuple_struct-none.expanded.rs | 2 +- .../naming/tuple_struct-own.expanded.rs | 2 +- .../naming/tuple_struct-ref.expanded.rs | 2 +- tests/expand/not_unpin/struct.expanded.rs | 2 +- .../expand/not_unpin/tuple_struct.expanded.rs | 2 +- tests/expand/pinned_drop/enum.expanded.rs | 2 +- tests/expand/pinned_drop/enum.rs | 3 +- tests/expand/pinned_drop/struct.expanded.rs | 4 +-- tests/expand/pinned_drop/struct.rs | 3 +- .../pinned_drop/tuple_struct.expanded.rs | 4 +-- tests/expand/pinned_drop/tuple_struct.rs | 3 +- .../expand/project_replace/struct.expanded.rs | 2 +- .../project_replace/tuple_struct.expanded.rs | 2 +- tests/expand/pub/struct.expanded.rs | 2 +- tests/expand/pub/tuple_struct.expanded.rs | 2 +- tests/expand/unsafe_unpin/struct.expanded.rs | 2 +- .../unsafe_unpin/tuple_struct.expanded.rs | 2 +- tests/repr_packed.rs | 5 +++- tests/ui/pin_project/packed.rs | 14 +++++++-- tests/ui/pin_project/packed.stderr | 6 ++++ tests/ui/pin_project/safe_packed_borrows.rs | 14 +++++---- .../ui/pin_project/safe_packed_borrows.stderr | 8 ++--- tests/ui/pin_project/unaligned_references.rs | 22 ++++++++++++++ .../pin_project/unaligned_references.stderr | 20 +++++++++++++ 41 files changed, 136 insertions(+), 62 deletions(-) create mode 100644 tests/ui/pin_project/unaligned_references.rs create mode 100644 tests/ui/pin_project/unaligned_references.stderr diff --git a/examples/not_unpin-expanded.rs b/examples/not_unpin-expanded.rs index aa5209d5..5700c120 100644 --- a/examples/not_unpin-expanded.rs +++ b/examples/not_unpin-expanded.rs @@ -76,7 +76,7 @@ const _: () = { // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34 // for details. - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/examples/pinned_drop-expanded.rs b/examples/pinned_drop-expanded.rs index 48eb7fc5..7c81825f 100644 --- a/examples/pinned_drop-expanded.rs +++ b/examples/pinned_drop-expanded.rs @@ -82,7 +82,7 @@ const _: () = { // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34 // for details. - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed<'a, T>(this: &Struct<'a, T>) { let _ = &this.was_dropped; let _ = &this.field; diff --git a/examples/project_replace-expanded.rs b/examples/project_replace-expanded.rs index 4f43bdab..ebb8e00e 100644 --- a/examples/project_replace-expanded.rs +++ b/examples/project_replace-expanded.rs @@ -112,7 +112,7 @@ const _: () = { // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34 // for details. - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/examples/struct-default-expanded.rs b/examples/struct-default-expanded.rs index 3d0e4ab1..d6610993 100644 --- a/examples/struct-default-expanded.rs +++ b/examples/struct-default-expanded.rs @@ -71,10 +71,8 @@ const _: () = { // Ensure that it's impossible to use pin projections on a #[repr(packed)] // struct. // - // Taking a reference to a packed field is unsafe, and applying - // #[forbid(safe_packed_borrows)] makes sure that doing this without - // an 'unsafe' block (which we deliberately do not generate) - // is a hard error. + // Taking a reference to a packed field is UB, and applying + // `#[forbid(unaligned_references)]` makes sure that doing this is a hard error. // // If the struct ends up having #[repr(packed)] applied somehow, // this will generate an (unfriendly) error message. Under all reasonable @@ -82,7 +80,7 @@ const _: () = { // a much nicer error above. // // See https://github.com/taiki-e/pin-project/pull/34 for more details. - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/examples/unsafe_unpin-expanded.rs b/examples/unsafe_unpin-expanded.rs index 2ea1f373..e9c7abce 100644 --- a/examples/unsafe_unpin-expanded.rs +++ b/examples/unsafe_unpin-expanded.rs @@ -75,7 +75,7 @@ const _: () = { // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34 // for details. - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/pin-project-internal/src/pin_project/derive.rs b/pin-project-internal/src/pin_project/derive.rs index 82539ca7..44ca3a28 100644 --- a/pin-project-internal/src/pin_project/derive.rs +++ b/pin-project-internal/src/pin_project/derive.rs @@ -996,7 +996,7 @@ fn make_proj_impl( /// This currently does two checks: /// * Checks the attributes of structs to ensure there is no `[repr(packed)]`. /// * Generates a function that borrows fields without an unsafe block and -/// forbidding `safe_packed_borrows` lint. +/// forbidding `unaligned_references` lint. fn ensure_not_packed(orig: &OriginalType<'_>, fields: &Fields) -> Result { for meta in orig.attrs.iter().filter_map(|attr| attr.parse_meta().ok()) { if let Meta::List(list) = meta { @@ -1019,9 +1019,6 @@ fn ensure_not_packed(orig: &OriginalType<'_>, fields: &Fields) -> Result, fields: &Fields) -> Result, fields: &Fields) -> Result, fields: &Fields) -> Result { @@ -1080,7 +1090,7 @@ fn ensure_not_packed(orig: &OriginalType<'_>, fields: &Fields) -> Result(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/default/tuple_struct.expanded.rs b/tests/expand/default/tuple_struct.expanded.rs index 3e8e3065..1322d22b 100644 --- a/tests/expand/default/tuple_struct.expanded.rs +++ b/tests/expand/default/tuple_struct.expanded.rs @@ -65,7 +65,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/multifields/struct.expanded.rs b/tests/expand/multifields/struct.expanded.rs index 17dab6a1..1f7dfdd7 100644 --- a/tests/expand/multifields/struct.expanded.rs +++ b/tests/expand/multifields/struct.expanded.rs @@ -142,7 +142,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned1; let _ = &this.pinned2; diff --git a/tests/expand/multifields/tuple_struct.expanded.rs b/tests/expand/multifields/tuple_struct.expanded.rs index 28e7fd87..aef8f8d5 100644 --- a/tests/expand/multifields/tuple_struct.expanded.rs +++ b/tests/expand/multifields/tuple_struct.expanded.rs @@ -118,7 +118,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/naming/struct-all.expanded.rs b/tests/expand/naming/struct-all.expanded.rs index 6506928e..88e024c5 100644 --- a/tests/expand/naming/struct-all.expanded.rs +++ b/tests/expand/naming/struct-all.expanded.rs @@ -109,7 +109,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/naming/struct-mut.expanded.rs b/tests/expand/naming/struct-mut.expanded.rs index 53c5212b..1365b23b 100644 --- a/tests/expand/naming/struct-mut.expanded.rs +++ b/tests/expand/naming/struct-mut.expanded.rs @@ -75,7 +75,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/naming/struct-none.expanded.rs b/tests/expand/naming/struct-none.expanded.rs index 2528ecec..70f04ef2 100644 --- a/tests/expand/naming/struct-none.expanded.rs +++ b/tests/expand/naming/struct-none.expanded.rs @@ -77,7 +77,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/naming/struct-own.expanded.rs b/tests/expand/naming/struct-own.expanded.rs index 0c1fc76f..899166f8 100644 --- a/tests/expand/naming/struct-own.expanded.rs +++ b/tests/expand/naming/struct-own.expanded.rs @@ -111,7 +111,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/naming/struct-ref.expanded.rs b/tests/expand/naming/struct-ref.expanded.rs index 3f52ac58..f636f108 100644 --- a/tests/expand/naming/struct-ref.expanded.rs +++ b/tests/expand/naming/struct-ref.expanded.rs @@ -77,7 +77,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/naming/tuple_struct-all.expanded.rs b/tests/expand/naming/tuple_struct-all.expanded.rs index 325b9db6..e4032bef 100644 --- a/tests/expand/naming/tuple_struct-all.expanded.rs +++ b/tests/expand/naming/tuple_struct-all.expanded.rs @@ -88,7 +88,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/naming/tuple_struct-mut.expanded.rs b/tests/expand/naming/tuple_struct-mut.expanded.rs index 8cbb11f5..076e4a07 100644 --- a/tests/expand/naming/tuple_struct-mut.expanded.rs +++ b/tests/expand/naming/tuple_struct-mut.expanded.rs @@ -60,7 +60,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/naming/tuple_struct-none.expanded.rs b/tests/expand/naming/tuple_struct-none.expanded.rs index 3e8e3065..1322d22b 100644 --- a/tests/expand/naming/tuple_struct-none.expanded.rs +++ b/tests/expand/naming/tuple_struct-none.expanded.rs @@ -65,7 +65,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/naming/tuple_struct-own.expanded.rs b/tests/expand/naming/tuple_struct-own.expanded.rs index 84bc14b7..eda82676 100644 --- a/tests/expand/naming/tuple_struct-own.expanded.rs +++ b/tests/expand/naming/tuple_struct-own.expanded.rs @@ -96,7 +96,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/naming/tuple_struct-ref.expanded.rs b/tests/expand/naming/tuple_struct-ref.expanded.rs index 587d741d..3c2618f8 100644 --- a/tests/expand/naming/tuple_struct-ref.expanded.rs +++ b/tests/expand/naming/tuple_struct-ref.expanded.rs @@ -62,7 +62,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/not_unpin/struct.expanded.rs b/tests/expand/not_unpin/struct.expanded.rs index efa660f7..680fb03f 100644 --- a/tests/expand/not_unpin/struct.expanded.rs +++ b/tests/expand/not_unpin/struct.expanded.rs @@ -77,7 +77,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/not_unpin/tuple_struct.expanded.rs b/tests/expand/not_unpin/tuple_struct.expanded.rs index 89a257e0..8bc6bbcc 100644 --- a/tests/expand/not_unpin/tuple_struct.expanded.rs +++ b/tests/expand/not_unpin/tuple_struct.expanded.rs @@ -65,7 +65,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/pinned_drop/enum.expanded.rs b/tests/expand/pinned_drop/enum.expanded.rs index c8eb0e4c..a920c791 100644 --- a/tests/expand/pinned_drop/enum.expanded.rs +++ b/tests/expand/pinned_drop/enum.expanded.rs @@ -1,5 +1,5 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; # [pin (__private (PinnedDrop , project = EnumProj , project_ref = EnumProjRef))] enum Enum { Struct { diff --git a/tests/expand/pinned_drop/enum.rs b/tests/expand/pinned_drop/enum.rs index f5b8aa4c..c162ef6b 100644 --- a/tests/expand/pinned_drop/enum.rs +++ b/tests/expand/pinned_drop/enum.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop, project = EnumProj, project_ref = EnumProjRef)] enum Enum { Struct { diff --git a/tests/expand/pinned_drop/struct.expanded.rs b/tests/expand/pinned_drop/struct.expanded.rs index 9d7f4897..9cf50667 100644 --- a/tests/expand/pinned_drop/struct.expanded.rs +++ b/tests/expand/pinned_drop/struct.expanded.rs @@ -1,5 +1,5 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; #[pin(__private(PinnedDrop))] struct Struct { #[pin] @@ -78,7 +78,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/pinned_drop/struct.rs b/tests/expand/pinned_drop/struct.rs index 948e6cc4..691d3cb4 100644 --- a/tests/expand/pinned_drop/struct.rs +++ b/tests/expand/pinned_drop/struct.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] struct Struct { #[pin] diff --git a/tests/expand/pinned_drop/tuple_struct.expanded.rs b/tests/expand/pinned_drop/tuple_struct.expanded.rs index b30ee66b..5019d263 100644 --- a/tests/expand/pinned_drop/tuple_struct.expanded.rs +++ b/tests/expand/pinned_drop/tuple_struct.expanded.rs @@ -1,5 +1,5 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; #[pin(__private(PinnedDrop))] struct TupleStruct(#[pin] T, U); #[allow(box_pointers)] @@ -66,7 +66,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/pinned_drop/tuple_struct.rs b/tests/expand/pinned_drop/tuple_struct.rs index a5360391..1f4917c2 100644 --- a/tests/expand/pinned_drop/tuple_struct.rs +++ b/tests/expand/pinned_drop/tuple_struct.rs @@ -1,6 +1,7 @@ -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[pin_project(PinnedDrop)] struct TupleStruct(#[pin] T, U); diff --git a/tests/expand/project_replace/struct.expanded.rs b/tests/expand/project_replace/struct.expanded.rs index 476c0abd..d3ed9e45 100644 --- a/tests/expand/project_replace/struct.expanded.rs +++ b/tests/expand/project_replace/struct.expanded.rs @@ -111,7 +111,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/project_replace/tuple_struct.expanded.rs b/tests/expand/project_replace/tuple_struct.expanded.rs index 0026a9f5..91077f3b 100644 --- a/tests/expand/project_replace/tuple_struct.expanded.rs +++ b/tests/expand/project_replace/tuple_struct.expanded.rs @@ -96,7 +96,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/pub/struct.expanded.rs b/tests/expand/pub/struct.expanded.rs index 246d9b62..7e6b9755 100644 --- a/tests/expand/pub/struct.expanded.rs +++ b/tests/expand/pub/struct.expanded.rs @@ -77,7 +77,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/pub/tuple_struct.expanded.rs b/tests/expand/pub/tuple_struct.expanded.rs index 033fbafc..48355e3e 100644 --- a/tests/expand/pub/tuple_struct.expanded.rs +++ b/tests/expand/pub/tuple_struct.expanded.rs @@ -65,7 +65,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/expand/unsafe_unpin/struct.expanded.rs b/tests/expand/unsafe_unpin/struct.expanded.rs index 4066d49b..76f4e528 100644 --- a/tests/expand/unsafe_unpin/struct.expanded.rs +++ b/tests/expand/unsafe_unpin/struct.expanded.rs @@ -77,7 +77,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &Struct) { let _ = &this.pinned; let _ = &this.unpinned; diff --git a/tests/expand/unsafe_unpin/tuple_struct.expanded.rs b/tests/expand/unsafe_unpin/tuple_struct.expanded.rs index 59a40da3..a0a52a86 100644 --- a/tests/expand/unsafe_unpin/tuple_struct.expanded.rs +++ b/tests/expand/unsafe_unpin/tuple_struct.expanded.rs @@ -65,7 +65,7 @@ const _: () = { } } } - #[forbid(safe_packed_borrows)] + #[forbid(unaligned_references, safe_packed_borrows)] fn __assert_not_repr_packed(this: &TupleStruct) { let _ = &this.0; let _ = &this.1; diff --git a/tests/repr_packed.rs b/tests/repr_packed.rs index a0d8bdc5..e87aabff 100644 --- a/tests/repr_packed.rs +++ b/tests/repr_packed.rs @@ -1,5 +1,8 @@ #![warn(rust_2018_idioms, single_use_lifetimes)] -#![forbid(safe_packed_borrows)] +// unaligned_references did not exist in older compilers and safe_packed_borrows was removed in the latest compilers. +// https://github.com/rust-lang/rust/pull/82525 +#![allow(unknown_lints, renamed_and_removed_lints)] +#![forbid(unaligned_references, safe_packed_borrows)] use std::cell::Cell; diff --git a/tests/ui/pin_project/packed.rs b/tests/ui/pin_project/packed.rs index f7566053..dd3ebfd6 100644 --- a/tests/ui/pin_project/packed.rs +++ b/tests/ui/pin_project/packed.rs @@ -2,7 +2,7 @@ use pin_project::pin_project; #[pin_project] #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types -struct A { +struct Packed1 { #[pin] f: u8, } @@ -10,14 +10,22 @@ struct A { // Test putting 'repr' before the 'pin_project' attribute #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types #[pin_project] -struct B { +struct Packed2 { #[pin] f: u8, } #[pin_project] #[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types -struct C { +struct PackedN1 { + #[pin] + f: u32, +} + +// Test putting 'repr' before the 'pin_project' attribute +#[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types +#[pin_project] +struct PackedN2 { #[pin] f: u32, } diff --git a/tests/ui/pin_project/packed.stderr b/tests/ui/pin_project/packed.stderr index 969faea2..e5b9e550 100644 --- a/tests/ui/pin_project/packed.stderr +++ b/tests/ui/pin_project/packed.stderr @@ -15,3 +15,9 @@ error: #[pin_project] attribute may not be used on #[repr(packed)] types | 19 | #[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types | ^^^^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> $DIR/packed.rs:26:8 + | +26 | #[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types + | ^^^^^^^^^ diff --git a/tests/ui/pin_project/safe_packed_borrows.rs b/tests/ui/pin_project/safe_packed_borrows.rs index db4ac2d0..f4d1aef3 100644 --- a/tests/ui/pin_project/safe_packed_borrows.rs +++ b/tests/ui/pin_project/safe_packed_borrows.rs @@ -1,21 +1,25 @@ #![forbid(safe_packed_borrows)] +#![allow(unaligned_references)] -// Refs: https://github.com/rust-lang/rust/issues/46043 +// This lint was removed in https://github.com/rust-lang/rust/pull/82525 (nightly-2021-03-28). +// Refs: +// - https://github.com/rust-lang/rust/pull/82525 +// - https://github.com/rust-lang/rust/issues/46043 #[repr(packed)] -struct A { +struct Packed { f: u32, } #[repr(packed(2))] -struct B { +struct PackedN { f: u32, } fn main() { - let a = A { f: 1 }; + let a = Packed { f: 1 }; &a.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block - let b = B { f: 1 }; + let b = PackedN { f: 1 }; &b.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block } diff --git a/tests/ui/pin_project/safe_packed_borrows.stderr b/tests/ui/pin_project/safe_packed_borrows.stderr index c1f734a4..9b77a4e0 100644 --- a/tests/ui/pin_project/safe_packed_borrows.stderr +++ b/tests/ui/pin_project/safe_packed_borrows.stderr @@ -1,7 +1,7 @@ error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) - --> $DIR/safe_packed_borrows.rs:17:5 + --> $DIR/safe_packed_borrows.rs:21:5 | -17 | &a.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block +21 | &a.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ^^^^ | note: the lint level is defined here @@ -14,9 +14,9 @@ note: the lint level is defined here = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) - --> $DIR/safe_packed_borrows.rs:20:5 + --> $DIR/safe_packed_borrows.rs:24:5 | -20 | &b.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block +24 | &b.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/tests/ui/pin_project/unaligned_references.rs b/tests/ui/pin_project/unaligned_references.rs new file mode 100644 index 00000000..d97b4b8e --- /dev/null +++ b/tests/ui/pin_project/unaligned_references.rs @@ -0,0 +1,22 @@ +#![forbid(unaligned_references)] +#![allow(safe_packed_borrows)] + +// Refs: https://github.com/rust-lang/rust/issues/82523 + +#[repr(packed)] +struct Packed { + f: u32, +} + +#[repr(packed(2))] +struct PackedN { + f: u32, +} + +fn main() { + let a = Packed { f: 1 }; + &a.f; //~ ERROR reference to packed field is unaligned + + let b = PackedN { f: 1 }; + &b.f; //~ ERROR reference to packed field is unaligned +} diff --git a/tests/ui/pin_project/unaligned_references.stderr b/tests/ui/pin_project/unaligned_references.stderr new file mode 100644 index 00000000..cc9d9c8a --- /dev/null +++ b/tests/ui/pin_project/unaligned_references.stderr @@ -0,0 +1,20 @@ +error: reference to packed field is unaligned + --> $DIR/unaligned_references.rs:18:5 + | +18 | &a.f; //~ ERROR reference to packed field is unaligned + | ^^^^ + | +note: the lint level is defined here + --> $DIR/unaligned_references.rs:1:11 + | +1 | #![forbid(unaligned_references)] + | ^^^^^^^^^^^^^^^^^^^^ + = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) + +error: reference to packed field is unaligned + --> $DIR/unaligned_references.rs:21:5 + | +21 | &b.f; //~ ERROR reference to packed field is unaligned + | ^^^^ + | + = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)