diff options
Diffstat (limited to 'tests/ui/pin_project')
27 files changed, 320 insertions, 155 deletions
diff --git a/tests/ui/pin_project/add-attr-to-struct.rs b/tests/ui/pin_project/add-attr-to-struct.rs index 55f1561..045e796 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 27656d6..f3ee9e4 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/add-pinned-field.stderr b/tests/ui/pin_project/add-pinned-field.stderr index a140694..a391f3b 100644 --- a/tests/ui/pin_project/add-pinned-field.stderr +++ b/tests/ui/pin_project/add-pinned-field.stderr @@ -7,7 +7,12 @@ error[E0277]: `PhantomPinned` cannot be unpinned 21 | is_unpin::<Foo>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^ within `__Foo<'_>`, the trait `Unpin` is not implemented for `PhantomPinned` | - = note: required because it appears within the type `__Foo<'_>` + = note: consider using `Box::pin` +note: required because it appears within the type `__Foo<'_>` + --> $DIR/add-pinned-field.rs:8:8 + | +8 | struct Foo { + | ^^^ = note: required because of the requirements on the impl of `Unpin` for `Foo` error[E0277]: `PhantomPinned` cannot be unpinned @@ -19,5 +24,10 @@ error[E0277]: `PhantomPinned` cannot be unpinned 22 | is_unpin::<Bar>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^ within `__Bar<'_>`, the trait `Unpin` is not implemented for `PhantomPinned` | - = note: required because it appears within the type `__Bar<'_>` + = note: consider using `Box::pin` +note: required because it appears within the type `__Bar<'_>` + --> $DIR/add-pinned-field.rs:15:8 + | +15 | struct Bar { + | ^^^ = note: required because of the requirements on the impl of `Unpin` for `Bar` diff --git a/tests/ui/pin_project/conflict-drop.rs b/tests/ui/pin_project/conflict-drop.rs index 908f5c0..4fdb118 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<T, U> { #[pin] diff --git a/tests/ui/pin_project/conflict-drop.stderr b/tests/ui/pin_project/conflict-drop.stderr index d5ca7b3..ae51456 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 +error[E0119]: conflicting implementations of trait `_::FooMustNotImplDrop` for type `Foo<_, _>` + --> $DIR/conflict-drop.rs:5:1 | -4 | #[pin_project] //~ ERROR E0119 +5 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ | | | first implementation here @@ -9,11 +9,11 @@ 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 +error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `Bar<_, _>` + --> $DIR/conflict-drop.rs:16:15 | -15 | #[pin_project(PinnedDrop)] //~ ERROR E0119 +16 | #[pin_project(PinnedDrop)] //~ ERROR E0119 | ^^^^^^^^^^ conflicting implementation for `Bar<_, _>` ... -27 | impl<T, U> Drop for Bar<T, U> { +28 | impl<T, U> Drop for Bar<T, U> { | ----------------------------- first implementation here diff --git a/tests/ui/pin_project/conflict-unpin.stderr b/tests/ui/pin_project/conflict-unpin.stderr index 0d6f439..0401140 100644 --- a/tests/ui/pin_project/conflict-unpin.stderr +++ b/tests/ui/pin_project/conflict-unpin.stderr @@ -1,4 +1,4 @@ -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>`: +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>` --> $DIR/conflict-unpin.rs:5:1 | 5 | #[pin_project] //~ ERROR E0119 @@ -9,7 +9,7 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type | = 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::marker::Unpin` for type `Bar<_, _>`: +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>` --> $DIR/conflict-unpin.rs:17:1 | 17 | #[pin_project] //~ ERROR E0119 @@ -20,7 +20,7 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type | = 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::marker::Unpin` for type `Baz<_, _>`: +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>` --> $DIR/conflict-unpin.rs:27:1 | 27 | #[pin_project] //~ ERROR E0119 diff --git a/tests/ui/pin_project/impl-unsafe-unpin.stderr b/tests/ui/pin_project/impl-unsafe-unpin.stderr index 78545c2..078baee 100644 --- a/tests/ui/pin_project/impl-unsafe-unpin.stderr +++ b/tests/ui/pin_project/impl-unsafe-unpin.stderr @@ -1,4 +1,4 @@ -error[E0119]: conflicting implementations of trait `pin_project::UnsafeUnpin` for type `Foo<_, _>`: +error[E0119]: conflicting implementations of trait `pin_project::UnsafeUnpin` for type `Foo<_, _>` --> $DIR/impl-unsafe-unpin.rs:3:1 | 3 | #[pin_project] //~ ERROR E0119 @@ -9,7 +9,7 @@ error[E0119]: conflicting implementations of trait `pin_project::UnsafeUnpin` fo | = 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 `pin_project::UnsafeUnpin` for type `Bar<_, _>`: +error[E0119]: conflicting implementations of trait `pin_project::UnsafeUnpin` for type `Bar<_, _>` --> $DIR/impl-unsafe-unpin.rs:12:1 | 12 | #[pin_project] //~ ERROR E0119 @@ -20,7 +20,7 @@ error[E0119]: conflicting implementations of trait `pin_project::UnsafeUnpin` fo | = 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 `pin_project::UnsafeUnpin` for type `Baz<_, _>`: +error[E0119]: conflicting implementations of trait `pin_project::UnsafeUnpin` for type `Baz<_, _>` --> $DIR/impl-unsafe-unpin.rs:21:1 | 21 | #[pin_project] //~ ERROR E0119 diff --git a/tests/ui/pin_project/overlapping_unpin_struct.rs b/tests/ui/pin_project/overlapping_unpin_struct.rs index 8db0855..abfd5d1 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<T> { #[pin] diff --git a/tests/ui/pin_project/overlapping_unpin_struct.stderr b/tests/ui/pin_project/overlapping_unpin_struct.stderr index 296b063..f49c736 100644 --- a/tests/ui/pin_project/overlapping_unpin_struct.stderr +++ b/tests/ui/pin_project/overlapping_unpin_struct.stderr @@ -1,11 +1,16 @@ error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/overlapping_unpin_struct.rs:17:5 + --> $DIR/overlapping_unpin_struct.rs:18:5 | -14 | fn is_unpin<T: Unpin>() {} +15 | fn is_unpin<T: Unpin>() {} | ----- required by this bound in `is_unpin` ... -17 | is_unpin::<S<PhantomPinned>>(); //~ ERROR E0277 +18 | is_unpin::<S<PhantomPinned>>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__S<'_, PhantomPinned>`, the trait `Unpin` is not implemented for `PhantomPinned` | - = note: required because it appears within the type `_::__S<'_, PhantomPinned>` + = note: consider using `Box::pin` +note: required because it appears within the type `_::__S<'_, PhantomPinned>` + --> $DIR/overlapping_unpin_struct.rs:6:8 + | +6 | struct S<T> { + | ^ = note: required because of the requirements on the impl of `Unpin` for `S<PhantomPinned>` diff --git a/tests/ui/pin_project/packed-enum.rs b/tests/ui/pin_project/packed-enum.rs index 9d4a4c3..023c08d 100644 --- a/tests/ui/pin_project/packed-enum.rs +++ b/tests/ui/pin_project/packed-enum.rs @@ -1,5 +1,9 @@ use pin_project::pin_project; +// #[repr(packed)] cannot be apply on enums and will be rejected by rustc. +// However, we should not rely on the behavior of rustc that rejects this. +// https://github.com/taiki-e/pin-project/pull/324#discussion_r612388001 + #[repr(packed)] //~ ERROR E0517 enum E1 { V(()), diff --git a/tests/ui/pin_project/packed-enum.stderr b/tests/ui/pin_project/packed-enum.stderr index afc8b30..0951944 100644 --- a/tests/ui/pin_project/packed-enum.stderr +++ b/tests/ui/pin_project/packed-enum.stderr @@ -1,30 +1,42 @@ +error: #[repr(packed)] attribute should be applied to a struct or union + --> $DIR/packed-enum.rs:13:8 + | +13 | #[repr(packed)] //~ ERROR E0517 + | ^^^^^^ + +error: #[repr(packed)] attribute should be applied to a struct or union + --> $DIR/packed-enum.rs:18:8 + | +18 | #[repr(packed)] //~ ERROR E0517 + | ^^^^^^ + error[E0517]: attribute should be applied to a struct or union - --> $DIR/packed-enum.rs:3:8 - | -3 | #[repr(packed)] //~ ERROR E0517 - | ^^^^^^ -4 | / enum E1 { -5 | | V(()), -6 | | } - | |_- not a struct or union + --> $DIR/packed-enum.rs:7:8 + | +7 | #[repr(packed)] //~ ERROR E0517 + | ^^^^^^ +8 | / enum E1 { +9 | | V(()), +10 | | } + | |_- not a struct or union error[E0517]: attribute should be applied to a struct or union - --> $DIR/packed-enum.rs:9:8 + --> $DIR/packed-enum.rs:13:8 | -9 | #[repr(packed)] //~ ERROR E0517 +13 | #[repr(packed)] //~ ERROR E0517 | ^^^^^^ -10 | / enum E2 { -11 | | V(()), -12 | | } +14 | / enum E2 { +15 | | V(()), +16 | | } | |_- not a struct or union error[E0517]: attribute should be applied to a struct or union - --> $DIR/packed-enum.rs:14:8 + --> $DIR/packed-enum.rs:18:8 | -14 | #[repr(packed)] //~ ERROR E0517 +18 | #[repr(packed)] //~ ERROR E0517 | ^^^^^^ -15 | #[pin_project] -16 | / enum E3 { -17 | | V(()), -18 | | } +19 | #[pin_project] +20 | / enum E3 { +21 | | V(()), +22 | | } | |_- not a struct or union diff --git a/tests/ui/pin_project/packed-name-value.rs b/tests/ui/pin_project/packed-name-value.rs index ed819ca..dedc403 100644 --- a/tests/ui/pin_project/packed-name-value.rs +++ b/tests/ui/pin_project/packed-name-value.rs @@ -1,17 +1,24 @@ use pin_project::pin_project; -#[repr(packed = "")] //~ ERROR E0552 -struct S1 { - f: (), -} +// #[repr(packed = "")] is not valid format of #[repr(packed)] and will be +// rejected by rustc. +// However, we should not rely on the behavior of rustc that rejects this. +// https://github.com/taiki-e/pin-project/pull/324#discussion_r612388001 + +// https://github.com/taiki-e/pin-project/pull/324#discussion_r612388001 +// https://github.com/rust-lang/rust/issues/83921 +// #[repr(packed = "")] //~ ERROR E0552 +// struct S1 { +// f: (), +// } #[pin_project] -#[repr(packed = "")] //~ ERROR E0552 +#[repr(packed = "")] //~ ERROR attribute should not be name-value pair struct S2 { f: (), } -#[repr(packed = "")] //~ ERROR E0552 +#[repr(packed = "")] //~ ERROR attribute should not be name-value pair #[pin_project] struct S3 { f: (), diff --git a/tests/ui/pin_project/packed-name-value.stderr b/tests/ui/pin_project/packed-name-value.stderr index a3e2571..51b82dd 100644 --- a/tests/ui/pin_project/packed-name-value.stderr +++ b/tests/ui/pin_project/packed-name-value.stderr @@ -1,17 +1,11 @@ -error[E0552]: unrecognized representation hint - --> $DIR/packed-name-value.rs:3:8 - | -3 | #[repr(packed = "")] //~ ERROR E0552 - | ^^^^^^^^^^^ - -error[E0552]: unrecognized representation hint - --> $DIR/packed-name-value.rs:9:8 - | -9 | #[repr(packed = "")] //~ ERROR E0552 - | ^^^^^^^^^^^ +error: #[repr(packed)] attribute should not be name-value pair + --> $DIR/packed-name-value.rs:16:8 + | +16 | #[repr(packed = "")] //~ ERROR attribute should not be name-value pair + | ^^^^^^^^^^^ -error[E0552]: unrecognized representation hint - --> $DIR/packed-name-value.rs:14:8 +error: #[repr(packed)] attribute should not be name-value pair + --> $DIR/packed-name-value.rs:21:8 | -14 | #[repr(packed = "")] //~ ERROR E0552 +21 | #[repr(packed = "")] //~ ERROR attribute should not be name-value pair | ^^^^^^^^^^^ diff --git a/tests/ui/pin_project/packed.rs b/tests/ui/pin_project/packed.rs index f756605..dd3ebfd 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 969faea..e5b9e55 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/packed_sneaky-1.rs b/tests/ui/pin_project/packed_sneaky-1.rs index 38f6fe0..72d3d3e 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 510200e..67bcd1b 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/project_replace_unsized.stderr b/tests/ui/pin_project/project_replace_unsized.stderr index 26e416a..75a2666 100644 --- a/tests/ui/pin_project/project_replace_unsized.stderr +++ b/tests/ui/pin_project/project_replace_unsized.stderr @@ -4,9 +4,13 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 3 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 4 | struct Struct<T: ?Sized> { - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` | - = note: required because it appears within the type `Struct<T>` +note: required because it appears within the type `Struct<T>` + --> $DIR/project_replace_unsized.rs:4:8 + | +4 | struct Struct<T: ?Sized> { + | ^^^^^^ = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | @@ -19,9 +23,13 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 3 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 4 | struct Struct<T: ?Sized> { - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` + | +note: required because it appears within the type `Struct<T>` + --> $DIR/project_replace_unsized.rs:4:8 | - = note: required because it appears within the type `Struct<T>` +4 | struct Struct<T: ?Sized> { + | ^^^^^^ = note: required by `UnsafeOverwriteGuard` = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) @@ -29,7 +37,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/project_replace_unsized.rs:5:5 | 4 | struct Struct<T: ?Sized> { - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` 5 | f: T, | ^ doesn't have a size known at compile-time @@ -39,9 +47,13 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 8 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 9 | struct TupleStruct<T: ?Sized>(T); - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` + | +note: required because it appears within the type `TupleStruct<T>` + --> $DIR/project_replace_unsized.rs:9:8 | - = note: required because it appears within the type `TupleStruct<T>` +9 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^ = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | @@ -54,9 +66,13 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 8 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 9 | struct TupleStruct<T: ?Sized>(T); - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` | - = note: required because it appears within the type `TupleStruct<T>` +note: required because it appears within the type `TupleStruct<T>` + --> $DIR/project_replace_unsized.rs:9:8 + | +9 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^ = note: required by `UnsafeOverwriteGuard` = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) @@ -64,7 +80,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/project_replace_unsized.rs:9:8 | 9 | struct TupleStruct<T: ?Sized>(T); - | ^^^^^^^^^^^ - this type parameter needs to be `Sized` + | ^^^^^^^^^^^ - this type parameter needs to be `std::marker::Sized` | | | doesn't have a size known at compile-time | diff --git a/tests/ui/pin_project/project_replace_unsized_fn_params.stderr b/tests/ui/pin_project/project_replace_unsized_fn_params.stderr index f0f9573..f8cee98 100644 --- a/tests/ui/pin_project/project_replace_unsized_fn_params.stderr +++ b/tests/ui/pin_project/project_replace_unsized_fn_params.stderr @@ -4,10 +4,14 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 6 | struct Struct<T: ?Sized> { | ^^^^^^^-^^^^^^^^^ | | | - | | this type parameter needs to be `Sized` + | | this type parameter needs to be `std::marker::Sized` | doesn't have a size known at compile-time | - = note: required because it appears within the type `__StructProjectionOwned<T>` +note: required because it appears within the type `__StructProjectionOwned<T>` + --> $DIR/project_replace_unsized_fn_params.rs:6:8 + | +6 | struct Struct<T: ?Sized> { + | ^^^^^^ = note: the return type of a function must have a statically known size error[E0277]: the size for values of type `T` cannot be known at compilation time @@ -16,9 +20,13 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 5 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 6 | struct Struct<T: ?Sized> { - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` | - = note: required because it appears within the type `Struct<T>` +note: required because it appears within the type `Struct<T>` + --> $DIR/project_replace_unsized_fn_params.rs:6:8 + | +6 | struct Struct<T: ?Sized> { + | ^^^^^^ = note: required by `UnsafeOverwriteGuard` = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) @@ -26,7 +34,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/project_replace_unsized_fn_params.rs:7:5 | 6 | struct Struct<T: ?Sized> { - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` 7 | f: T, | ^ doesn't have a size known at compile-time @@ -36,10 +44,14 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 11 | struct TupleStruct<T: ?Sized>(T); | ^^^^^^^^^^^^-^^^^^^^^^ | | | - | | this type parameter needs to be `Sized` + | | this type parameter needs to be `std::marker::Sized` | doesn't have a size known at compile-time | - = note: required because it appears within the type `__TupleStructProjectionOwned<T>` +note: required because it appears within the type `__TupleStructProjectionOwned<T>` + --> $DIR/project_replace_unsized_fn_params.rs:11:8 + | +11 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^ = note: the return type of a function must have a statically known size error[E0277]: the size for values of type `T` cannot be known at compilation time @@ -48,8 +60,12 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 10 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 11 | struct TupleStruct<T: ?Sized>(T); - | - this type parameter needs to be `Sized` + | - this type parameter needs to be `std::marker::Sized` | - = note: required because it appears within the type `TupleStruct<T>` +note: required because it appears within the type `TupleStruct<T>` + --> $DIR/project_replace_unsized_fn_params.rs:11:8 + | +11 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^ = note: required by `UnsafeOverwriteGuard` = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pin_project/remove-attr-from-field.rs b/tests/ui/pin_project/remove-attr-from-field.rs index bec8302..fd14da3 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<T: Unpin>() {} diff --git a/tests/ui/pin_project/remove-attr-from-field.stderr b/tests/ui/pin_project/remove-attr-from-field.stderr index 5d8caac..486bc00 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 0086cf9..cbe5aba 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<T: Unpin>() {} diff --git a/tests/ui/pin_project/remove-attr-from-struct.stderr b/tests/ui/pin_project/remove-attr-from-struct.stderr index 4652b66..82fada5 100644 --- a/tests/ui/pin_project/remove-attr-from-struct.stderr +++ b/tests/ui/pin_project/remove-attr-from-struct.stderr @@ -1,71 +1,91 @@ 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<T: Unpin>() {} +6 | fn is_unpin<T: Unpin>() {} | ----- required by this bound in `is_unpin` ... -34 | is_unpin::<A>(); //~ ERROR E0277 +35 | is_unpin::<A>(); //~ ERROR E0277 | ^^^^^^^^^^^^^ within `A`, the trait `Unpin` is not implemented for `PhantomPinned` | - = note: required because it appears within the type `A` + = note: consider using `Box::pin` +note: required because it appears within the type `A` + --> $DIR/remove-attr-from-struct.rs:10:8 + | +10 | struct 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<T: Unpin>() {} +6 | fn is_unpin<T: Unpin>() {} | ----- required by this bound in `is_unpin` ... -35 | is_unpin::<B>(); //~ ERROR E0277 +36 | is_unpin::<B>(); //~ ERROR E0277 | ^^^^^^^^^^^^^ within `B`, the trait `Unpin` is not implemented for `PhantomPinned` | - = note: required because it appears within the type `B` + = note: consider using `Box::pin` +note: required because it appears within the type `B` + --> $DIR/remove-attr-from-struct.rs:17:8 + | +17 | struct 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: consider using `Box::pin` +note: required because it appears within the type `A` + --> $DIR/remove-attr-from-struct.rs:10:8 + | +10 | struct A { + | ^ = note: required by `Pin::<P>::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: consider using `Box::pin` +note: required because it appears within the type `B` + --> $DIR/remove-attr-from-struct.rs:17:8 + | +17 | struct B { + | ^ = note: required by `Pin::<P>::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/pin_project/safe_packed_borrows.rs b/tests/ui/pin_project/safe_packed_borrows.rs index db4ac2d..8f4f462 100644 --- a/tests/ui/pin_project/safe_packed_borrows.rs +++ b/tests/ui/pin_project/safe_packed_borrows.rs @@ -1,21 +1,28 @@ -#![forbid(safe_packed_borrows)] +#![deny(renamed_and_removed_lints)] +#![deny(safe_packed_borrows)] //~ ERROR has been renamed to `unaligned_references` +#![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 }; - &a.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block + let a = Packed { f: 1 }; + &a.f; + let _ = &a.f; - let b = B { f: 1 }; - &b.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block + let b = PackedN { f: 1 }; + &b.f; + let _ = &b.f; } diff --git a/tests/ui/pin_project/safe_packed_borrows.stderr b/tests/ui/pin_project/safe_packed_borrows.stderr index c1f734a..4048eaa 100644 --- a/tests/ui/pin_project/safe_packed_borrows.stderr +++ b/tests/ui/pin_project/safe_packed_borrows.stderr @@ -1,24 +1,11 @@ -error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) - --> $DIR/safe_packed_borrows.rs:17:5 - | -17 | &a.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block - | ^^^^ - | +error: lint `safe_packed_borrows` has been renamed to `unaligned_references` + --> $DIR/safe_packed_borrows.rs:2:9 + | +2 | #![deny(safe_packed_borrows)] //~ ERROR has been renamed to `unaligned_references` + | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `unaligned_references` + | note: the lint level is defined here - --> $DIR/safe_packed_borrows.rs:1:11 - | -1 | #![forbid(safe_packed_borrows)] - | ^^^^^^^^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> - = 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 - | -20 | &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! - = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> - = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior + --> $DIR/safe_packed_borrows.rs:1:9 + | +1 | #![deny(renamed_and_removed_lints)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/pin_project/unaligned_references.rs b/tests/ui/pin_project/unaligned_references.rs new file mode 100644 index 0000000..23dd71d --- /dev/null +++ b/tests/ui/pin_project/unaligned_references.rs @@ -0,0 +1,23 @@ +#![forbid(unaligned_references)] + +// 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 _ = &a.f; //~ ERROR reference to packed field is unaligned + + let b = PackedN { f: 1 }; + &b.f; //~ ERROR reference to packed field is unaligned + let _ = &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 0000000..17600de --- /dev/null +++ b/tests/ui/pin_project/unaligned_references.stderr @@ -0,0 +1,44 @@ +error: reference to packed field is unaligned + --> $DIR/unaligned_references.rs:17:5 + | +17 | &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)] + | ^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = 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:18:13 + | +18 | let _ = &a.f; //~ ERROR reference to packed field is unaligned + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = 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 + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = 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:22:13 + | +22 | let _ = &b.f; //~ ERROR reference to packed field is unaligned + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) |