diff options
Diffstat (limited to 'third_party/rust/pin-project/tests/ui/pin_project')
50 files changed, 2129 insertions, 0 deletions
diff --git a/third_party/rust/pin-project/tests/ui/pin_project/add-attr-to-struct.rs b/third_party/rust/pin-project/tests/ui/pin_project/add-attr-to-struct.rs new file mode 100644 index 0000000000..045e79664d --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/add-attr-to-struct.rs @@ -0,0 +1,20 @@ +use std::marker::PhantomPinned; + +use auxiliary_macro::add_pin_attr; +use pin_project::pin_project; + +#[pin_project] +#[add_pin_attr(struct)] //~ ERROR duplicate #[pin] attribute +struct Foo { + #[pin] + f: PhantomPinned, +} + +#[add_pin_attr(struct)] //~ ERROR #[pin] attribute may only be used on fields of structs or variants +#[pin_project] +struct Bar { + #[pin] + f: PhantomPinned, +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/add-attr-to-struct.stderr b/third_party/rust/pin-project/tests/ui/pin_project/add-attr-to-struct.stderr new file mode 100644 index 0000000000..6fb88e8059 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/add-attr-to-struct.stderr @@ -0,0 +1,15 @@ +error: duplicate #[pin] attribute + --> tests/ui/pin_project/add-attr-to-struct.rs:7:1 + | +7 | #[add_pin_attr(struct)] //~ ERROR duplicate #[pin] attribute + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `add_pin_attr` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: #[pin] attribute may only be used on fields of structs or variants + --> tests/ui/pin_project/add-attr-to-struct.rs:13:1 + | +13 | #[add_pin_attr(struct)] //~ ERROR #[pin] attribute may only be used on fields of structs or variants + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `add_pin_attr` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/add-pinned-field.rs b/third_party/rust/pin-project/tests/ui/pin_project/add-pinned-field.rs new file mode 100644 index 0000000000..c415f9c904 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/add-pinned-field.rs @@ -0,0 +1,23 @@ +use auxiliary_macro::add_pinned_field; +use pin_project::pin_project; + +fn is_unpin<T: Unpin>() {} + +#[pin_project] +#[add_pinned_field] +struct Foo { + #[pin] + f: u32, +} + +#[add_pinned_field] +#[pin_project] +struct Bar { + #[pin] + f: u32, +} + +fn main() { + is_unpin::<Foo>(); //~ ERROR E0277 + is_unpin::<Bar>(); //~ ERROR E0277 +} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/add-pinned-field.stderr b/third_party/rust/pin-project/tests/ui/pin_project/add-pinned-field.stderr new file mode 100644 index 0000000000..d0832cced8 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/add-pinned-field.stderr @@ -0,0 +1,52 @@ +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/add-pinned-field.rs:21:5 + | +21 | is_unpin::<Foo>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^ within `__Foo<'_>`, the trait `Unpin` is not implemented for `PhantomPinned` + | + = note: consider using `Box::pin` +note: required because it appears within the type `__Foo<'_>` + --> tests/ui/pin_project/add-pinned-field.rs:8:8 + | +8 | struct Foo { + | ^^^ +note: required because of the requirements on the impl of `Unpin` for `Foo` + --> tests/ui/pin_project/add-pinned-field.rs:6:1 + | +6 | #[pin_project] + | ^^^^^^^^^^^^^^ +7 | #[add_pinned_field] +8 | struct Foo { + | ^^^ +note: required by a bound in `is_unpin` + --> tests/ui/pin_project/add-pinned-field.rs:4:16 + | +4 | fn is_unpin<T: Unpin>() {} + | ^^^^^ required by this bound in `is_unpin` + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/add-pinned-field.rs:22:5 + | +22 | is_unpin::<Bar>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^ within `__Bar<'_>`, the trait `Unpin` is not implemented for `PhantomPinned` + | + = note: consider using `Box::pin` +note: required because it appears within the type `__Bar<'_>` + --> tests/ui/pin_project/add-pinned-field.rs:15:8 + | +15 | struct Bar { + | ^^^ +note: required because of the requirements on the impl of `Unpin` for `Bar` + --> tests/ui/pin_project/add-pinned-field.rs:14:1 + | +14 | #[pin_project] + | ^^^^^^^^^^^^^^ +15 | struct Bar { + | ^^^ +note: required by a bound in `is_unpin` + --> tests/ui/pin_project/add-pinned-field.rs:4:16 + | +4 | fn is_unpin<T: Unpin>() {} + | ^^^^^ required by this bound in `is_unpin` + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/conflict-drop.rs b/third_party/rust/pin-project/tests/ui/pin_project/conflict-drop.rs new file mode 100644 index 0000000000..4fdb118d06 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/conflict-drop.rs @@ -0,0 +1,32 @@ +use std::pin::Pin; + +use pin_project::{pin_project, pinned_drop}; + +#[pin_project] //~ ERROR E0119 +struct Foo<T, U> { + #[pin] + f1: T, + f2: U, +} + +impl<T, U> Drop for Foo<T, U> { + fn drop(&mut self) {} +} + +#[pin_project(PinnedDrop)] //~ ERROR E0119 +struct Bar<T, U> { + #[pin] + f1: T, + f2: U, +} + +#[pinned_drop] +impl<T, U> PinnedDrop for Bar<T, U> { + fn drop(self: Pin<&mut Self>) {} +} + +impl<T, U> Drop for Bar<T, U> { + fn drop(&mut self) {} +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/conflict-drop.stderr b/third_party/rust/pin-project/tests/ui/pin_project/conflict-drop.stderr new file mode 100644 index 0000000000..4ae628da75 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/conflict-drop.stderr @@ -0,0 +1,19 @@ +error[E0119]: conflicting implementations of trait `_::FooMustNotImplDrop` for type `Foo<_, _>` + --> tests/ui/pin_project/conflict-drop.rs:5:1 + | +5 | #[pin_project] //~ ERROR E0119 + | ^^^^^^^^^^^^^^ + | | + | first implementation here + | conflicting implementation for `Foo<_, _>` + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `Bar<_, _>` + --> tests/ui/pin_project/conflict-drop.rs:16:15 + | +16 | #[pin_project(PinnedDrop)] //~ ERROR E0119 + | ^^^^^^^^^^ conflicting implementation for `Bar<_, _>` +... +28 | impl<T, U> Drop for Bar<T, U> { + | ----------------------------- first implementation here diff --git a/third_party/rust/pin-project/tests/ui/pin_project/conflict-unpin.rs b/third_party/rust/pin-project/tests/ui/pin_project/conflict-unpin.rs new file mode 100644 index 0000000000..f58c45e09f --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/conflict-unpin.rs @@ -0,0 +1,37 @@ +use pin_project::pin_project; + +// The same implementation. + +#[pin_project] //~ ERROR E0119 +struct Foo<T, U> { + #[pin] + f1: T, + f2: U, +} + +// conflicting implementations +impl<T, U> Unpin for Foo<T, U> where T: Unpin {} // Conditional Unpin impl + +// The implementation that under different conditions. + +#[pin_project] //~ ERROR E0119 +struct Bar<T, U> { + #[pin] + f1: T, + f2: U, +} + +// conflicting implementations +impl<T, U> Unpin for Bar<T, U> {} // Non-conditional Unpin impl + +#[pin_project] //~ ERROR E0119 +struct Baz<T, U> { + #[pin] + f1: T, + f2: U, +} + +// conflicting implementations +impl<T: Unpin, U: Unpin> Unpin for Baz<T, U> {} // Conditional Unpin impl + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/conflict-unpin.stderr b/third_party/rust/pin-project/tests/ui/pin_project/conflict-unpin.stderr new file mode 100644 index 0000000000..7df5db272f --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/conflict-unpin.stderr @@ -0,0 +1,32 @@ +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:5:1 + | +5 | #[pin_project] //~ ERROR E0119 + | ^^^^^^^^^^^^^^ conflicting implementation for `Foo<_, _>` +... +13 | impl<T, U> Unpin for Foo<T, U> where T: Unpin {} // Conditional Unpin impl + | ------------------------------ first implementation here + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:17:1 + | +17 | #[pin_project] //~ ERROR E0119 + | ^^^^^^^^^^^^^^ conflicting implementation for `Bar<_, _>` +... +25 | impl<T, U> Unpin for Bar<T, U> {} // Non-conditional Unpin impl + | ------------------------------ first implementation here + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:27:1 + | +27 | #[pin_project] //~ ERROR E0119 + | ^^^^^^^^^^^^^^ conflicting implementation for `Baz<_, _>` +... +35 | impl<T: Unpin, U: Unpin> Unpin for Baz<T, U> {} // Conditional Unpin impl + | -------------------------------------------- first implementation here + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/impl-unsafe-unpin.rs b/third_party/rust/pin-project/tests/ui/pin_project/impl-unsafe-unpin.rs new file mode 100644 index 0000000000..562c9b64f6 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/impl-unsafe-unpin.rs @@ -0,0 +1,30 @@ +use pin_project::{pin_project, UnsafeUnpin}; + +#[pin_project] //~ ERROR E0119 +struct Foo<T, U> { + #[pin] + f1: T, + f2: U, +} + +unsafe impl<T, U> UnsafeUnpin for Foo<T, U> where T: Unpin {} + +#[pin_project] //~ ERROR E0119 +struct Bar<T, U> { + #[pin] + f1: T, + f2: U, +} + +unsafe impl<T, U> UnsafeUnpin for Bar<T, U> {} + +#[pin_project] //~ ERROR E0119 +struct Baz<T, U> { + #[pin] + f1: T, + f2: U, +} + +unsafe impl<T: Unpin, U: Unpin> UnsafeUnpin for Baz<T, U> {} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/impl-unsafe-unpin.stderr b/third_party/rust/pin-project/tests/ui/pin_project/impl-unsafe-unpin.stderr new file mode 100644 index 0000000000..9554b9b5df --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/impl-unsafe-unpin.stderr @@ -0,0 +1,32 @@ +error[E0119]: conflicting implementations of trait `_::_pin_project::UnsafeUnpin` for type `Foo<_, _>` + --> tests/ui/pin_project/impl-unsafe-unpin.rs:3:1 + | +3 | #[pin_project] //~ ERROR E0119 + | ^^^^^^^^^^^^^^ conflicting implementation for `Foo<_, _>` +... +10 | unsafe impl<T, U> UnsafeUnpin for Foo<T, U> where T: Unpin {} + | ------------------------------------------- first implementation here + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `_::_pin_project::UnsafeUnpin` for type `Bar<_, _>` + --> tests/ui/pin_project/impl-unsafe-unpin.rs:12:1 + | +12 | #[pin_project] //~ ERROR E0119 + | ^^^^^^^^^^^^^^ conflicting implementation for `Bar<_, _>` +... +19 | unsafe impl<T, U> UnsafeUnpin for Bar<T, U> {} + | ------------------------------------------- first implementation here + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `_::_pin_project::UnsafeUnpin` for type `Baz<_, _>` + --> tests/ui/pin_project/impl-unsafe-unpin.rs:21:1 + | +21 | #[pin_project] //~ ERROR E0119 + | ^^^^^^^^^^^^^^ conflicting implementation for `Baz<_, _>` +... +28 | unsafe impl<T: Unpin, U: Unpin> UnsafeUnpin for Baz<T, U> {} + | --------------------------------------------------------- first implementation here + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/import_unnamed.rs b/third_party/rust/pin-project/tests/ui/pin_project/import_unnamed.rs new file mode 100644 index 0000000000..7926e61a63 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/import_unnamed.rs @@ -0,0 +1,30 @@ +/// Only named projected types can be imported. +/// See visibility.rs for named projected types. + +mod pub_ { + use pin_project::pin_project; + + #[pin_project] + pub struct Default(()); + + #[pin_project(project_replace)] + pub struct Replace(()); +} +#[allow(unused_imports)] +pub mod use_ { + #[rustfmt::skip] + use crate::pub_::__DefaultProjection; //~ ERROR E0432 + #[rustfmt::skip] + use crate::pub_::__DefaultProjectionRef; //~ ERROR E0432 + #[rustfmt::skip] + use crate::pub_::__ReplaceProjection; //~ ERROR E0432 + #[rustfmt::skip] + use crate::pub_::__ReplaceProjectionOwned; //~ ERROR E0432 + #[rustfmt::skip] + use crate::pub_::__ReplaceProjectionRef; //~ ERROR E0432 + + // Confirm that the visibility of the original type is not changed. + pub use crate::pub_::{Default, Replace}; +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/import_unnamed.stderr b/third_party/rust/pin-project/tests/ui/pin_project/import_unnamed.stderr new file mode 100644 index 0000000000..260a35a5c0 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/import_unnamed.stderr @@ -0,0 +1,29 @@ +error[E0432]: unresolved import `crate::pub_::__DefaultProjection` + --> tests/ui/pin_project/import_unnamed.rs:16:9 + | +16 | use crate::pub_::__DefaultProjection; //~ ERROR E0432 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `__DefaultProjection` in `pub_` + +error[E0432]: unresolved import `crate::pub_::__DefaultProjectionRef` + --> tests/ui/pin_project/import_unnamed.rs:18:9 + | +18 | use crate::pub_::__DefaultProjectionRef; //~ ERROR E0432 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `__DefaultProjectionRef` in `pub_` + +error[E0432]: unresolved import `crate::pub_::__ReplaceProjection` + --> tests/ui/pin_project/import_unnamed.rs:20:9 + | +20 | use crate::pub_::__ReplaceProjection; //~ ERROR E0432 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `__ReplaceProjection` in `pub_` + +error[E0432]: unresolved import `crate::pub_::__ReplaceProjectionOwned` + --> tests/ui/pin_project/import_unnamed.rs:22:9 + | +22 | use crate::pub_::__ReplaceProjectionOwned; //~ ERROR E0432 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `__ReplaceProjectionOwned` in `pub_` + +error[E0432]: unresolved import `crate::pub_::__ReplaceProjectionRef` + --> tests/ui/pin_project/import_unnamed.rs:24:9 + | +24 | use crate::pub_::__ReplaceProjectionRef; //~ ERROR E0432 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `__ReplaceProjectionRef` in `pub_` diff --git a/third_party/rust/pin-project/tests/ui/pin_project/invalid.rs b/third_party/rust/pin-project/tests/ui/pin_project/invalid.rs new file mode 100644 index 0000000000..d39a1fd4c9 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/invalid.rs @@ -0,0 +1,280 @@ +mod pin_argument { + use pin_project::pin_project; + + #[pin_project] + struct Struct { + #[pin()] //~ ERROR unexpected token + f: (), + } + + #[pin_project] + struct TupleStruct(#[pin(foo)] ()); //~ ERROR unexpected token + + #[pin_project] + enum EnumTuple { + V(#[pin(foo)] ()), //~ ERROR unexpected token + } + + #[pin_project] + enum EnumStruct { + V { + #[pin(foo)] //~ ERROR unexpected token + f: (), + }, + } +} + +mod pin_attribute { + use pin_project::pin_project; + + #[pin_project] + struct DuplicateStruct { + #[pin] + #[pin] //~ ERROR duplicate #[pin] attribute + f: (), + } + + #[pin_project] + struct DuplicateTupleStruct( + #[pin] + #[pin] + (), + //~^^ ERROR duplicate #[pin] attribute + ); + + #[pin_project] + enum DuplicateEnumTuple { + V( + #[pin] + #[pin] + (), + //~^^ ERROR duplicate #[pin] attribute + ), + } + + #[pin_project] + enum DuplicateEnumStruct { + V { + #[pin] + #[pin] //~ ERROR duplicate #[pin] attribute + f: (), + }, + } +} + +mod pin_item { + use pin_project::pin_project; + + #[pin_project] + #[pin] //~ ERROR may only be used on fields of structs or variants + struct Struct { + #[pin] + f: (), + } + + #[pin_project] + enum Variant { + #[pin] //~ ERROR may only be used on fields of structs or variants + V(()), + } + + #[pin_project] + #[pin] //~ ERROR may only be used on fields of structs or variants + enum Enum { + V(()), + } +} + +mod pin_project_argument { + use pin_project::pin_project; + + #[pin_project(Replace)] //~ ERROR `Replace` argument was removed, use `project_replace` argument instead + struct RemovedReplace(#[pin] ()); + + #[pin_project(UnsafeUnpin,,)] //~ ERROR expected identifier + struct Unexpected1(#[pin] ()); + + #[pin_project(Foo)] //~ ERROR unexpected argument + struct Unexpected2(#[pin] ()); + + #[pin_project(,UnsafeUnpin)] //~ ERROR expected identifier + struct Unexpected3(#[pin] ()); + + #[pin_project()] // Ok + struct Unexpected4(#[pin] ()); + + #[pin_project(PinnedDrop PinnedDrop)] //~ ERROR expected `,` + struct Unexpected5(#[pin] ()); + + #[pin_project(PinnedDrop, PinnedDrop)] //~ ERROR duplicate `PinnedDrop` argument + struct DuplicatePinnedDrop(#[pin] ()); + + #[pin_project(UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument + struct DuplicateUnsafeUnpin(#[pin] ()); + + #[pin_project(!Unpin, !Unpin)] //~ ERROR duplicate `!Unpin` argument + struct DuplicateNotUnpin(#[pin] ()); + + #[pin_project(PinnedDrop, UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument + struct Duplicate3(#[pin] ()); + + #[pin_project(PinnedDrop, UnsafeUnpin, PinnedDrop, UnsafeUnpin)] //~ ERROR duplicate `PinnedDrop` argument + struct Duplicate4(#[pin] ()); + + #[pin_project(project = A, project = B)] //~ ERROR duplicate `project` argument + struct DuplicateProject(#[pin] ()); + + #[pin_project(project = A, project_ref = A, project = B)] //~ ERROR duplicate `project` argument + struct DuplicateProject2(#[pin] ()); + + #[pin_project(project_ref = A, project_ref = B)] //~ ERROR duplicate `project_ref` argument + struct DuplicateProjectRef(#[pin] ()); + + #[pin_project(project_replace = A, project_replace = B)] //~ ERROR duplicate `project_replace` argument + struct DuplicateProjectReplace1(#[pin] ()); + + #[pin_project(project_replace, project_replace = B)] //~ ERROR duplicate `project_replace` argument + struct DuplicateProjectReplace2(#[pin] ()); + + #[pin_project(project_replace = A, project_replace)] //~ ERROR duplicate `project_replace` argument + struct DuplicateProjectReplace3(#[pin] ()); + + #[pin_project(project_replace = A)] // Ok + struct ProjectReplaceWithoutReplace(#[pin] ()); + + #[pin_project(PinnedDrop, project_replace)] //~ ERROR arguments `PinnedDrop` and `project_replace` are mutually exclusive + struct PinnedDropWithProjectReplace1(#[pin] ()); + + #[pin_project(project_replace, UnsafeUnpin, PinnedDrop)] //~ ERROR arguments `PinnedDrop` and `project_replace` are mutually exclusive + struct PinnedDropWithProjectReplace2(#[pin] ()); + + #[pin_project(UnsafeUnpin, !Unpin)] //~ ERROR arguments `UnsafeUnpin` and `!Unpin` are mutually exclusive + struct UnsafeUnpinWithNotUnpin1(#[pin] ()); + + #[pin_project(!Unpin, PinnedDrop, UnsafeUnpin)] //~ ERROR arguments `UnsafeUnpin` and `!Unpin` are mutually exclusive + struct UnsafeUnpinWithNotUnpin2(#[pin] ()); + + #[pin_project(!)] //~ ERROR expected `!Unpin`, found `!` + struct NotUnpin1(#[pin] ()); + + #[pin_project(Unpin)] //~ ERROR unexpected argument + struct NotUnpin2(#[pin] ()); + + #[pin_project(project)] //~ ERROR expected `project = <identifier>`, found `project` + struct Project1(#[pin] ()); + + #[pin_project(project = )] //~ ERROR expected `project = <identifier>`, found `project =` + struct Project2(#[pin] ()); + + #[pin_project(project = !)] //~ ERROR expected identifier + struct Project3(#[pin] ()); + + #[pin_project(project_ref)] //~ ERROR expected `project_ref = <identifier>`, found `project_ref` + struct ProjectRef1(#[pin] ()); + + #[pin_project(project_ref = )] //~ ERROR expected `project_ref = <identifier>`, found `project_ref =` + struct ProjectRef2(#[pin] ()); + + #[pin_project(project_ref = !)] //~ ERROR expected identifier + struct ProjectRef3(#[pin] ()); + + #[pin_project(project_replace)] // Ok + struct ProjectReplace1(#[pin] ()); + + #[pin_project(project_replace = )] //~ ERROR expected `project_replace = <identifier>`, found `project_replace =` + struct ProjectReplace2(#[pin] ()); + + #[pin_project(project_replace = !)] //~ ERROR expected identifier + struct ProjectReplace3(#[pin] ()); + + #[pin_project(project_replace)] //~ ERROR `project_replace` argument requires a value when used on enums + enum ProjectReplaceEnum { + V(#[pin] ()), + } +} + +mod pin_project_conflict_naming { + use pin_project::pin_project; + + #[pin_project(project = OrigAndProj)] //~ ERROR name `OrigAndProj` is the same as the original type name + struct OrigAndProj(#[pin] ()); + + #[pin_project(project_ref = OrigAndProjRef)] //~ ERROR name `OrigAndProjRef` is the same as the original type name + struct OrigAndProjRef(#[pin] ()); + + #[pin_project(project_replace = OrigAndProjOwn)] //~ ERROR name `OrigAndProjOwn` is the same as the original type name + struct OrigAndProjOwn(#[pin] ()); + + #[pin_project(project = A, project_ref = A)] //~ ERROR name `A` is already specified by `project` argument + struct ProjAndProjRef(#[pin] ()); + + #[pin_project(project = A, project_replace = A)] //~ ERROR name `A` is already specified by `project` argument + struct ProjAndProjOwn(#[pin] ()); + + #[pin_project(project_ref = A, project_replace = A)] //~ ERROR name `A` is already specified by `project_ref` argument + struct ProjRefAndProjOwn(#[pin] ()); +} + +mod pin_project_attribute { + use pin_project::pin_project; + + #[pin_project] + #[pin_project] //~ ERROR duplicate #[pin_project] attribute + struct Duplicate(#[pin] ()); +} + +mod pin_project_item { + use pin_project::pin_project; + + #[pin_project] + struct Struct {} //~ ERROR may not be used on structs with zero fields + + #[pin_project] + struct TupleStruct(); //~ ERROR may not be used on structs with zero fields + + #[pin_project] + struct UnitStruct; //~ ERROR may not be used on structs with zero fields + + #[pin_project] + enum EnumEmpty {} //~ ERROR may not be used on enums without variants + + #[pin_project] + enum EnumDiscriminant { + V = 2, //~ ERROR may not be used on enums with discriminants + } + + #[pin_project] + enum EnumZeroFields { + Unit, //~ ERROR may not be used on enums with zero fields + Tuple(), + Struct {}, + } + + #[pin_project] + union Union { + //~^ ERROR may only be used on structs or enums + f: (), + } + + #[pin_project] + impl Impl {} //~ ERROR may only be used on structs or enums +} + +// #[repr(packed)] is always detected first, even on unsupported structs. +mod pin_project_item_packed { + use pin_project::pin_project; + + #[pin_project] + #[repr(packed)] + struct Struct {} //~ ERROR may not be used on #[repr(packed)] types + + #[pin_project] + #[repr(packed)] + struct TupleStruct(); //~ ERROR may not be used on #[repr(packed)] types + + #[pin_project] + #[repr(packed)] + struct UnitStruct; //~ ERROR may not be used on #[repr(packed)] types +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/invalid.stderr b/third_party/rust/pin-project/tests/ui/pin_project/invalid.stderr new file mode 100644 index 0000000000..c43d363de8 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/invalid.stderr @@ -0,0 +1,364 @@ +error: unexpected token: `()` + --> tests/ui/pin_project/invalid.rs:6:14 + | +6 | #[pin()] //~ ERROR unexpected token + | ^^ + +error: unexpected token: `(foo)` + --> tests/ui/pin_project/invalid.rs:11:29 + | +11 | struct TupleStruct(#[pin(foo)] ()); //~ ERROR unexpected token + | ^^^^^ + +error: unexpected token: `(foo)` + --> tests/ui/pin_project/invalid.rs:15:16 + | +15 | V(#[pin(foo)] ()), //~ ERROR unexpected token + | ^^^^^ + +error: unexpected token: `(foo)` + --> tests/ui/pin_project/invalid.rs:21:18 + | +21 | #[pin(foo)] //~ ERROR unexpected token + | ^^^^^ + +error: duplicate #[pin] attribute + --> tests/ui/pin_project/invalid.rs:33:9 + | +33 | #[pin] //~ ERROR duplicate #[pin] attribute + | ^^^^^^ + +error: duplicate #[pin] attribute + --> tests/ui/pin_project/invalid.rs:40:9 + | +40 | #[pin] + | ^^^^^^ + +error: duplicate #[pin] attribute + --> tests/ui/pin_project/invalid.rs:49:13 + | +49 | #[pin] + | ^^^^^^ + +error: duplicate #[pin] attribute + --> tests/ui/pin_project/invalid.rs:59:13 + | +59 | #[pin] //~ ERROR duplicate #[pin] attribute + | ^^^^^^ + +error: #[pin] attribute may only be used on fields of structs or variants + --> tests/ui/pin_project/invalid.rs:69:5 + | +69 | #[pin] //~ ERROR may only be used on fields of structs or variants + | ^^^^^^ + +error: #[pin] attribute may only be used on fields of structs or variants + --> tests/ui/pin_project/invalid.rs:77:9 + | +77 | #[pin] //~ ERROR may only be used on fields of structs or variants + | ^^^^^^ + +error: #[pin] attribute may only be used on fields of structs or variants + --> tests/ui/pin_project/invalid.rs:82:5 + | +82 | #[pin] //~ ERROR may only be used on fields of structs or variants + | ^^^^^^ + +error: `Replace` argument was removed, use `project_replace` argument instead + --> tests/ui/pin_project/invalid.rs:91:19 + | +91 | #[pin_project(Replace)] //~ ERROR `Replace` argument was removed, use `project_replace` argument instead + | ^^^^^^^ + +error: expected identifier + --> tests/ui/pin_project/invalid.rs:94:31 + | +94 | #[pin_project(UnsafeUnpin,,)] //~ ERROR expected identifier + | ^ + +error: unexpected argument: Foo + --> tests/ui/pin_project/invalid.rs:97:19 + | +97 | #[pin_project(Foo)] //~ ERROR unexpected argument + | ^^^ + +error: expected identifier + --> tests/ui/pin_project/invalid.rs:100:19 + | +100 | #[pin_project(,UnsafeUnpin)] //~ ERROR expected identifier + | ^ + +error: expected `,` + --> tests/ui/pin_project/invalid.rs:106:30 + | +106 | #[pin_project(PinnedDrop PinnedDrop)] //~ ERROR expected `,` + | ^^^^^^^^^^ + +error: duplicate `PinnedDrop` argument + --> tests/ui/pin_project/invalid.rs:109:31 + | +109 | #[pin_project(PinnedDrop, PinnedDrop)] //~ ERROR duplicate `PinnedDrop` argument + | ^^^^^^^^^^ + +error: duplicate `UnsafeUnpin` argument + --> tests/ui/pin_project/invalid.rs:112:32 + | +112 | #[pin_project(UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument + | ^^^^^^^^^^^ + +error: duplicate `!Unpin` argument + --> tests/ui/pin_project/invalid.rs:115:27 + | +115 | #[pin_project(!Unpin, !Unpin)] //~ ERROR duplicate `!Unpin` argument + | ^^^^^^ + +error: duplicate `UnsafeUnpin` argument + --> tests/ui/pin_project/invalid.rs:118:44 + | +118 | #[pin_project(PinnedDrop, UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument + | ^^^^^^^^^^^ + +error: duplicate `PinnedDrop` argument + --> tests/ui/pin_project/invalid.rs:121:44 + | +121 | #[pin_project(PinnedDrop, UnsafeUnpin, PinnedDrop, UnsafeUnpin)] //~ ERROR duplicate `PinnedDrop` argument + | ^^^^^^^^^^ + +error: duplicate `project` argument + --> tests/ui/pin_project/invalid.rs:124:32 + | +124 | #[pin_project(project = A, project = B)] //~ ERROR duplicate `project` argument + | ^^^^^^^^^^^ + +error: duplicate `project` argument + --> tests/ui/pin_project/invalid.rs:127:49 + | +127 | #[pin_project(project = A, project_ref = A, project = B)] //~ ERROR duplicate `project` argument + | ^^^^^^^^^^^ + +error: duplicate `project_ref` argument + --> tests/ui/pin_project/invalid.rs:130:36 + | +130 | #[pin_project(project_ref = A, project_ref = B)] //~ ERROR duplicate `project_ref` argument + | ^^^^^^^^^^^^^^^ + +error: duplicate `project_replace` argument + --> tests/ui/pin_project/invalid.rs:133:40 + | +133 | #[pin_project(project_replace = A, project_replace = B)] //~ ERROR duplicate `project_replace` argument + | ^^^^^^^^^^^^^^^^^^^ + +error: duplicate `project_replace` argument + --> tests/ui/pin_project/invalid.rs:136:36 + | +136 | #[pin_project(project_replace, project_replace = B)] //~ ERROR duplicate `project_replace` argument + | ^^^^^^^^^^^^^^^^^^^ + +error: duplicate `project_replace` argument + --> tests/ui/pin_project/invalid.rs:139:40 + | +139 | #[pin_project(project_replace = A, project_replace)] //~ ERROR duplicate `project_replace` argument + | ^^^^^^^^^^^^^^^ + +error: arguments `PinnedDrop` and `project_replace` are mutually exclusive + --> tests/ui/pin_project/invalid.rs:145:19 + | +145 | #[pin_project(PinnedDrop, project_replace)] //~ ERROR arguments `PinnedDrop` and `project_replace` are mutually exclusive + | ^^^^^^^^^^ + +error: arguments `PinnedDrop` and `project_replace` are mutually exclusive + --> tests/ui/pin_project/invalid.rs:148:49 + | +148 | #[pin_project(project_replace, UnsafeUnpin, PinnedDrop)] //~ ERROR arguments `PinnedDrop` and `project_replace` are mutually exclusive + | ^^^^^^^^^^ + +error: arguments `UnsafeUnpin` and `!Unpin` are mutually exclusive + --> tests/ui/pin_project/invalid.rs:151:19 + | +151 | #[pin_project(UnsafeUnpin, !Unpin)] //~ ERROR arguments `UnsafeUnpin` and `!Unpin` are mutually exclusive + | ^^^^^^^^^^^ + +error: arguments `UnsafeUnpin` and `!Unpin` are mutually exclusive + --> tests/ui/pin_project/invalid.rs:154:39 + | +154 | #[pin_project(!Unpin, PinnedDrop, UnsafeUnpin)] //~ ERROR arguments `UnsafeUnpin` and `!Unpin` are mutually exclusive + | ^^^^^^^^^^^ + +error: expected `!Unpin`, found `!` + --> tests/ui/pin_project/invalid.rs:157:19 + | +157 | #[pin_project(!)] //~ ERROR expected `!Unpin`, found `!` + | ^ + +error: unexpected argument: Unpin + --> tests/ui/pin_project/invalid.rs:160:19 + | +160 | #[pin_project(Unpin)] //~ ERROR unexpected argument + | ^^^^^ + +error: expected `project = <identifier>`, found `project` + --> tests/ui/pin_project/invalid.rs:163:19 + | +163 | #[pin_project(project)] //~ ERROR expected `project = <identifier>`, found `project` + | ^^^^^^^ + +error: expected `project = <identifier>`, found `project =` + --> tests/ui/pin_project/invalid.rs:166:19 + | +166 | #[pin_project(project = )] //~ ERROR expected `project = <identifier>`, found `project =` + | ^^^^^^^^^ + +error: expected identifier + --> tests/ui/pin_project/invalid.rs:169:29 + | +169 | #[pin_project(project = !)] //~ ERROR expected identifier + | ^ + +error: expected `project_ref = <identifier>`, found `project_ref` + --> tests/ui/pin_project/invalid.rs:172:19 + | +172 | #[pin_project(project_ref)] //~ ERROR expected `project_ref = <identifier>`, found `project_ref` + | ^^^^^^^^^^^ + +error: expected `project_ref = <identifier>`, found `project_ref =` + --> tests/ui/pin_project/invalid.rs:175:19 + | +175 | #[pin_project(project_ref = )] //~ ERROR expected `project_ref = <identifier>`, found `project_ref =` + | ^^^^^^^^^^^^^ + +error: expected identifier + --> tests/ui/pin_project/invalid.rs:178:33 + | +178 | #[pin_project(project_ref = !)] //~ ERROR expected identifier + | ^ + +error: expected `project_replace = <identifier>`, found `project_replace =` + --> tests/ui/pin_project/invalid.rs:184:19 + | +184 | #[pin_project(project_replace = )] //~ ERROR expected `project_replace = <identifier>`, found `project_replace =` + | ^^^^^^^^^^^^^^^^^ + +error: expected identifier + --> tests/ui/pin_project/invalid.rs:187:37 + | +187 | #[pin_project(project_replace = !)] //~ ERROR expected identifier + | ^ + +error: `project_replace` argument requires a value when used on enums + --> tests/ui/pin_project/invalid.rs:190:19 + | +190 | #[pin_project(project_replace)] //~ ERROR `project_replace` argument requires a value when used on enums + | ^^^^^^^^^^^^^^^ + +error: name `OrigAndProj` is the same as the original type name + --> tests/ui/pin_project/invalid.rs:199:29 + | +199 | #[pin_project(project = OrigAndProj)] //~ ERROR name `OrigAndProj` is the same as the original type name + | ^^^^^^^^^^^ + +error: name `OrigAndProjRef` is the same as the original type name + --> tests/ui/pin_project/invalid.rs:202:33 + | +202 | #[pin_project(project_ref = OrigAndProjRef)] //~ ERROR name `OrigAndProjRef` is the same as the original type name + | ^^^^^^^^^^^^^^ + +error: name `OrigAndProjOwn` is the same as the original type name + --> tests/ui/pin_project/invalid.rs:205:37 + | +205 | #[pin_project(project_replace = OrigAndProjOwn)] //~ ERROR name `OrigAndProjOwn` is the same as the original type name + | ^^^^^^^^^^^^^^ + +error: name `A` is already specified by `project` argument + --> tests/ui/pin_project/invalid.rs:208:46 + | +208 | #[pin_project(project = A, project_ref = A)] //~ ERROR name `A` is already specified by `project` argument + | ^ + +error: name `A` is already specified by `project` argument + --> tests/ui/pin_project/invalid.rs:211:50 + | +211 | #[pin_project(project = A, project_replace = A)] //~ ERROR name `A` is already specified by `project` argument + | ^ + +error: name `A` is already specified by `project_ref` argument + --> tests/ui/pin_project/invalid.rs:214:54 + | +214 | #[pin_project(project_ref = A, project_replace = A)] //~ ERROR name `A` is already specified by `project_ref` argument + | ^ + +error: duplicate #[pin_project] attribute + --> tests/ui/pin_project/invalid.rs:222:5 + | +222 | #[pin_project] //~ ERROR duplicate #[pin_project] attribute + | ^^^^^^^^^^^^^^ + +error: #[pin_project] attribute may not be used on structs with zero fields + --> tests/ui/pin_project/invalid.rs:230:19 + | +230 | struct Struct {} //~ ERROR may not be used on structs with zero fields + | ^^ + +error: #[pin_project] attribute may not be used on structs with zero fields + --> tests/ui/pin_project/invalid.rs:233:23 + | +233 | struct TupleStruct(); //~ ERROR may not be used on structs with zero fields + | ^^ + +error: #[pin_project] attribute may not be used on structs with zero fields + --> tests/ui/pin_project/invalid.rs:236:12 + | +236 | struct UnitStruct; //~ ERROR may not be used on structs with zero fields + | ^^^^^^^^^^ + +error: #[pin_project] attribute may not be used on enums without variants + --> tests/ui/pin_project/invalid.rs:239:20 + | +239 | enum EnumEmpty {} //~ ERROR may not be used on enums without variants + | ^^ + +error: #[pin_project] attribute may not be used on enums with discriminants + --> tests/ui/pin_project/invalid.rs:243:13 + | +243 | V = 2, //~ ERROR may not be used on enums with discriminants + | ^ + +error: #[pin_project] attribute may not be used on enums with zero fields + --> tests/ui/pin_project/invalid.rs:248:9 + | +248 | / Unit, //~ ERROR may not be used on enums with zero fields +249 | | Tuple(), +250 | | Struct {}, + | |__________________^ + +error: #[pin_project] attribute may only be used on structs or enums + --> tests/ui/pin_project/invalid.rs:254:5 + | +254 | / union Union { +255 | | //~^ ERROR may only be used on structs or enums +256 | | f: (), +257 | | } + | |_____^ + +error: #[pin_project] attribute may only be used on structs or enums + --> tests/ui/pin_project/invalid.rs:260:5 + | +260 | impl Impl {} //~ ERROR may only be used on structs or enums + | ^^^^^^^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/invalid.rs:268:12 + | +268 | #[repr(packed)] + | ^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/invalid.rs:272:12 + | +272 | #[repr(packed)] + | ^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/invalid.rs:276:12 + | +276 | #[repr(packed)] + | ^^^^^^ diff --git a/third_party/rust/pin-project/tests/ui/pin_project/overlapping_unpin_struct.rs b/third_party/rust/pin-project/tests/ui/pin_project/overlapping_unpin_struct.rs new file mode 100644 index 0000000000..abfd5d1344 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/overlapping_unpin_struct.rs @@ -0,0 +1,19 @@ +use std::marker::PhantomPinned; + +use pin_project::pin_project; + +#[pin_project] +struct S<T> { + #[pin] + f: T, +} + +struct __S {} + +impl Unpin for __S {} + +fn is_unpin<T: Unpin>() {} + +fn main() { + is_unpin::<S<PhantomPinned>>(); //~ ERROR E0277 +} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/overlapping_unpin_struct.stderr b/third_party/rust/pin-project/tests/ui/pin_project/overlapping_unpin_struct.stderr new file mode 100644 index 0000000000..1bd200d9c8 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/overlapping_unpin_struct.stderr @@ -0,0 +1,25 @@ +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/overlapping_unpin_struct.rs:18:5 + | +18 | is_unpin::<S<PhantomPinned>>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__S<'_, PhantomPinned>`, the trait `Unpin` is not implemented for `PhantomPinned` + | + = note: consider using `Box::pin` +note: required because it appears within the type `_::__S<'_, PhantomPinned>` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:6:8 + | +6 | struct S<T> { + | ^ +note: required because of the requirements on the impl of `Unpin` for `S<PhantomPinned>` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:5:1 + | +5 | #[pin_project] + | ^^^^^^^^^^^^^^ +6 | struct S<T> { + | ^^^^ +note: required by a bound in `is_unpin` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:15:16 + | +15 | fn is_unpin<T: Unpin>() {} + | ^^^^^ required by this bound in `is_unpin` + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/override-priv-mod.rs b/third_party/rust/pin-project/tests/ui/pin_project/override-priv-mod.rs new file mode 100644 index 0000000000..890fd5b8de --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/override-priv-mod.rs @@ -0,0 +1,32 @@ +// https://discord.com/channels/273534239310479360/512792629516173323/870075511009857617 + +extern crate pin_project as pin_project_orig; +extern crate self as pin_project; + +pub use ::pin_project_orig::*; +mod __private { + pub use ::pin_project_orig::__private::*; + pub trait Drop {} +} + +use std::{marker::PhantomPinned, mem}; + +#[pin_project] //~ ERROR conflicting implementations of trait `_::FooMustNotImplDrop` +struct S { + #[pin] + f: (u8, PhantomPinned), +} + +impl Drop for S { + fn drop(&mut self) { + let prev = &self.f.0 as *const _ as usize; + let moved = mem::take(&mut self.f); // move pinned field + let moved = &moved.0 as *const _ as usize; + assert_eq!(prev, moved); // panic + } +} + +fn main() { + let mut x = Box::pin(S { f: (1, PhantomPinned) }); + let _f = x.as_mut().project().f; // first mutable access +} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/override-priv-mod.stderr b/third_party/rust/pin-project/tests/ui/pin_project/override-priv-mod.stderr new file mode 100644 index 0000000000..8a3fb9b61a --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/override-priv-mod.stderr @@ -0,0 +1,10 @@ +error[E0119]: conflicting implementations of trait `_::SMustNotImplDrop` for type `S` + --> tests/ui/pin_project/override-priv-mod.rs:14:1 + | +14 | #[pin_project] //~ ERROR conflicting implementations of trait `_::FooMustNotImplDrop` + | ^^^^^^^^^^^^^^ + | | + | first implementation here + | conflicting implementation for `S` + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed-enum.rs b/third_party/rust/pin-project/tests/ui/pin_project/packed-enum.rs new file mode 100644 index 0000000000..023c08d14f --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed-enum.rs @@ -0,0 +1,24 @@ +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(()), +} + +#[pin_project] +#[repr(packed)] //~ ERROR E0517 +enum E2 { + V(()), +} + +#[repr(packed)] //~ ERROR E0517 +#[pin_project] +enum E3 { + V(()), +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed-enum.stderr b/third_party/rust/pin-project/tests/ui/pin_project/packed-enum.stderr new file mode 100644 index 0000000000..1872211206 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed-enum.stderr @@ -0,0 +1,42 @@ +error: #[repr(packed)] attribute should be applied to a struct or union + --> tests/ui/pin_project/packed-enum.rs:13:8 + | +13 | #[repr(packed)] //~ ERROR E0517 + | ^^^^^^ + +error: #[repr(packed)] attribute should be applied to a struct or union + --> tests/ui/pin_project/packed-enum.rs:18:8 + | +18 | #[repr(packed)] //~ ERROR E0517 + | ^^^^^^ + +error[E0517]: attribute should be applied to a struct or union + --> tests/ui/pin_project/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 + --> tests/ui/pin_project/packed-enum.rs:13:8 + | +13 | #[repr(packed)] //~ ERROR E0517 + | ^^^^^^ +14 | / enum E2 { +15 | | V(()), +16 | | } + | |_- not a struct or union + +error[E0517]: attribute should be applied to a struct or union + --> tests/ui/pin_project/packed-enum.rs:18:8 + | +18 | #[repr(packed)] //~ ERROR E0517 + | ^^^^^^ +19 | #[pin_project] +20 | / enum E3 { +21 | | V(()), +22 | | } + | |_- not a struct or union diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed-name-value.rs b/third_party/rust/pin-project/tests/ui/pin_project/packed-name-value.rs new file mode 100644 index 0000000000..dedc4030fa --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed-name-value.rs @@ -0,0 +1,27 @@ +use pin_project::pin_project; + +// #[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 attribute should not be name-value pair +struct S2 { + f: (), +} + +#[repr(packed = "")] //~ ERROR attribute should not be name-value pair +#[pin_project] +struct S3 { + f: (), +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed-name-value.stderr b/third_party/rust/pin-project/tests/ui/pin_project/packed-name-value.stderr new file mode 100644 index 0000000000..d8b2194713 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed-name-value.stderr @@ -0,0 +1,23 @@ +error: #[repr(packed)] attribute should not be name-value pair + --> tests/ui/pin_project/packed-name-value.rs:16:8 + | +16 | #[repr(packed = "")] //~ ERROR attribute should not be name-value pair + | ^^^^^^^^^^^ + +error: #[repr(packed)] attribute should not be name-value pair + --> tests/ui/pin_project/packed-name-value.rs:21:8 + | +21 | #[repr(packed = "")] //~ ERROR attribute should not be name-value pair + | ^^^^^^^^^^^ + +error[E0693]: incorrect `repr(packed)` attribute format + --> tests/ui/pin_project/packed-name-value.rs:16:8 + | +16 | #[repr(packed = "")] //~ ERROR attribute should not be name-value pair + | ^^^^^^^^^^^ help: use parentheses instead: `packed()` + +error[E0693]: incorrect `repr(packed)` attribute format + --> tests/ui/pin_project/packed-name-value.rs:21:8 + | +21 | #[repr(packed = "")] //~ ERROR attribute should not be name-value pair + | ^^^^^^^^^^^ help: use parentheses instead: `packed()` diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed.rs b/third_party/rust/pin-project/tests/ui/pin_project/packed.rs new file mode 100644 index 0000000000..dd3ebfd638 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed.rs @@ -0,0 +1,33 @@ +use pin_project::pin_project; + +#[pin_project] +#[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types +struct Packed1 { + #[pin] + f: u8, +} + +// Test putting 'repr' before the 'pin_project' attribute +#[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types +#[pin_project] +struct Packed2 { + #[pin] + f: u8, +} + +#[pin_project] +#[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types +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, +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed.stderr b/third_party/rust/pin-project/tests/ui/pin_project/packed.stderr new file mode 100644 index 0000000000..25ea5f43e4 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed.stderr @@ -0,0 +1,23 @@ +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed.rs:4:8 + | +4 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types + | ^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed.rs:11:8 + | +11 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types + | ^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed.rs:19:8 + | +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 + --> tests/ui/pin_project/packed.rs:26:8 + | +26 | #[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types + | ^^^^^^^^^ diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-1.rs b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-1.rs new file mode 100644 index 0000000000..83a46122cc --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-1.rs @@ -0,0 +1,41 @@ +use std::pin::Pin; + +use auxiliary_macro::{hidden_repr, hidden_repr2}; +use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; + +#[pin_project] //~ ERROR may not be used on #[repr(packed)] types +#[hidden_repr(packed)] +struct A { + #[pin] + f: u32, +} + +#[hidden_repr2] +#[pin_project] //~ ERROR may not be used on #[repr(packed)] types +struct B { + #[pin] + f: u32, +} + +#[pin_project(UnsafeUnpin)] //~ ERROR may not be used on #[repr(packed)] types +#[hidden_repr(packed)] +struct C { + #[pin] + f: u32, +} + +unsafe impl UnsafeUnpin for C {} + +#[pin_project(PinnedDrop)] //~ ERROR may not be used on #[repr(packed)] types +#[hidden_repr(packed)] +struct D { + #[pin] + f: u32, +} + +#[pinned_drop] +impl PinnedDrop for D { + fn drop(self: Pin<&mut Self>) {} +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-1.stderr b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-1.stderr new file mode 100644 index 0000000000..0746e1a21c --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-1.stderr @@ -0,0 +1,25 @@ +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed_sneaky-1.rs:7:15 + | +7 | #[hidden_repr(packed)] + | ^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed_sneaky-1.rs:13:1 + | +13 | #[hidden_repr2] + | ^^^^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `hidden_repr2` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed_sneaky-1.rs:21:15 + | +21 | #[hidden_repr(packed)] + | ^^^^^^ + +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed_sneaky-1.rs:30:15 + | +30 | #[hidden_repr(packed)] + | ^^^^^^ diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-2.rs b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-2.rs new file mode 100644 index 0000000000..b098358e6f --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-2.rs @@ -0,0 +1,12 @@ +use auxiliary_macro::hidden_repr_macro; +use pin_project::pin_project; + +hidden_repr_macro! { //~ ERROR may not be used on #[repr(packed)] types + #[pin_project] + struct B { + #[pin] + f: u32, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-2.stderr b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-2.stderr new file mode 100644 index 0000000000..d643052fda --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-2.stderr @@ -0,0 +1,13 @@ +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> tests/ui/pin_project/packed_sneaky-2.rs:4:1 + | +4 | / hidden_repr_macro! { //~ ERROR may not be used on #[repr(packed)] types +5 | | #[pin_project] +6 | | struct B { +7 | | #[pin] +8 | | f: u32, +9 | | } +10 | | } + | |_^ + | + = note: this error originates in the macro `hidden_repr_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-3.rs b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-3.rs new file mode 100644 index 0000000000..d3f00f3d23 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-3.rs @@ -0,0 +1,32 @@ +use auxiliary_macro::{hidden_repr_macro, HiddenRepr}; +use pin_project::pin_project; + +hidden_repr_macro! {} //~ ERROR expected item after attributes +#[pin_project] +struct S1 { + #[pin] + f: u32, +} + +macro_rules! hidden_repr_macro2 { + () => { + #[repr(packed)] //~ ERROR expected item after attributes + }; +} + +hidden_repr_macro2! {} +#[pin_project] +struct S2 { + #[pin] + f: u32, +} + +#[derive(HiddenRepr)] //~ ERROR expected item after attributes +struct S3 {} +#[pin_project] +struct S4 { + #[pin] + f: u32, +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-3.stderr b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-3.stderr new file mode 100644 index 0000000000..c97f18b75a --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-3.stderr @@ -0,0 +1,32 @@ +error: expected item after attributes + --> tests/ui/pin_project/packed_sneaky-3.rs:4:1 + | +4 | hidden_repr_macro! {} //~ ERROR expected item after attributes + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `hidden_repr_macro` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected item after attributes + --> tests/ui/pin_project/packed_sneaky-3.rs:13:9 + | +13 | #[repr(packed)] //~ ERROR expected item after attributes + | ^^^^^^^^^^^^^^^ +... +17 | hidden_repr_macro2! {} + | ---------------------- in this macro invocation + | + = note: this error originates in the macro `hidden_repr_macro2` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected item after attributes + --> tests/ui/pin_project/packed_sneaky-3.rs:24:10 + | +24 | #[derive(HiddenRepr)] //~ ERROR expected item after attributes + | ^^^^^^^^^^ + | + = note: this error originates in the derive macro `HiddenRepr` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: proc-macro derive produced unparseable tokens + --> tests/ui/pin_project/packed_sneaky-3.rs:24:10 + | +24 | #[derive(HiddenRepr)] //~ ERROR expected item after attributes + | ^^^^^^^^^^ diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-4.rs b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-4.rs new file mode 100644 index 0000000000..fb954baf15 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-4.rs @@ -0,0 +1,15 @@ +// https://github.com/taiki-e/pin-project/issues/342 + +#![allow(unaligned_references)] + +use auxiliary_macro::hidden_repr2; +use pin_project::pin_project; + +#[pin_project] //~ ERROR reference to packed field is unaligned +#[hidden_repr2] +struct A { + #[pin] + f: u32, +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-4.stderr b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-4.stderr new file mode 100644 index 0000000000..8072ce2f5f --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/packed_sneaky-4.stderr @@ -0,0 +1,16 @@ +error: reference to packed field is unaligned + --> tests/ui/pin_project/packed_sneaky-4.rs:8:1 + | +8 | #[pin_project] //~ ERROR reference to packed field is unaligned + | ^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui/pin_project/packed_sneaky-4.rs:8:1 + | +8 | #[pin_project] //~ 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) + = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/private_in_public-enum.rs b/third_party/rust/pin-project/tests/ui/pin_project/private_in_public-enum.rs new file mode 100644 index 0000000000..15a82a9a92 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/private_in_public-enum.rs @@ -0,0 +1,23 @@ +// Even if allows private_in_public, these are errors. + +#![allow(private_in_public)] + +pub enum PublicEnum { + V(PrivateEnum), //~ ERROR E0446 +} + +enum PrivateEnum { + V(u8), +} + +mod foo { + pub(crate) enum CrateEnum { + V(PrivateEnum), //~ ERROR E0446 + } + + enum PrivateEnum { + V(u8), + } +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/private_in_public-enum.stderr b/third_party/rust/pin-project/tests/ui/pin_project/private_in_public-enum.stderr new file mode 100644 index 0000000000..c93b265916 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/private_in_public-enum.stderr @@ -0,0 +1,17 @@ +error[E0446]: private type `PrivateEnum` in public interface + --> tests/ui/pin_project/private_in_public-enum.rs:6:7 + | +6 | V(PrivateEnum), //~ ERROR E0446 + | ^^^^^^^^^^^ can't leak private type +... +9 | enum PrivateEnum { + | ---------------- `PrivateEnum` declared as private + +error[E0446]: private type `foo::PrivateEnum` in public interface + --> tests/ui/pin_project/private_in_public-enum.rs:15:11 + | +15 | V(PrivateEnum), //~ ERROR E0446 + | ^^^^^^^^^^^ can't leak private type +... +18 | enum PrivateEnum { + | ---------------- `foo::PrivateEnum` declared as private diff --git a/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized.rs b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized.rs new file mode 100644 index 0000000000..20dde12bd3 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized.rs @@ -0,0 +1,11 @@ +use pin_project::pin_project; + +#[pin_project(project_replace)] //~ ERROR E0277 +struct Struct<T: ?Sized> { + f: T, +} + +#[pin_project(project_replace)] //~ ERROR E0277 +struct TupleStruct<T: ?Sized>(T); + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized.stderr b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized.stderr new file mode 100644 index 0000000000..042b499434 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized.stderr @@ -0,0 +1,118 @@ +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized.rs:3:15 + | +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 `std::marker::Sized` + | +note: required because it appears within the type `Struct<T>` + --> tests/ui/pin_project/project_replace_unsized.rs:4:8 + | +4 | struct Struct<T: ?Sized> { + | ^^^^^^ + = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +4 - struct Struct<T: ?Sized> { +4 + struct Struct<T> { + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +3 | #[pin_project(&project_replace)] //~ ERROR E0277 + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized.rs:3:1 + | +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 `std::marker::Sized` + | +note: required because it appears within the type `Struct<T>` + --> tests/ui/pin_project/project_replace_unsized.rs:4:8 + | +4 | struct Struct<T: ?Sized> { + | ^^^^^^ +note: required by a bound in `UnsafeOverwriteGuard::<T>::new` + --> src/lib.rs + | + | impl<T> UnsafeOverwriteGuard<T> { + | ^ required by this bound in `UnsafeOverwriteGuard::<T>::new` + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +4 - struct Struct<T: ?Sized> { +4 + struct Struct<T> { + | + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized.rs:5:5 + | +3 | #[pin_project(project_replace)] //~ ERROR E0277 + | ------------------------------- required by a bound introduced by this call +4 | struct Struct<T: ?Sized> { + | - this type parameter needs to be `std::marker::Sized` +5 | f: T, + | ^ doesn't have a size known at compile-time + | +note: required by a bound in `std::ptr::read` + --> $RUST/core/src/ptr/mod.rs + | + | pub const unsafe fn read<T>(src: *const T) -> T { + | ^ required by this bound in `std::ptr::read` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +4 - struct Struct<T: ?Sized> { +4 + struct Struct<T> { + | + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized.rs:8:15 + | +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 `std::marker::Sized` + | +note: required because it appears within the type `TupleStruct<T>` + --> tests/ui/pin_project/project_replace_unsized.rs:9:8 + | +9 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^ + = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +9 - struct TupleStruct<T: ?Sized>(T); +9 + struct TupleStruct<T>(T); + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +8 | #[pin_project(&project_replace)] //~ ERROR E0277 + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized.rs:8:1 + | +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 `std::marker::Sized` + | +note: required because it appears within the type `TupleStruct<T>` + --> tests/ui/pin_project/project_replace_unsized.rs:9:8 + | +9 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^ +note: required by a bound in `UnsafeOverwriteGuard::<T>::new` + --> src/lib.rs + | + | impl<T> UnsafeOverwriteGuard<T> { + | ^ required by this bound in `UnsafeOverwriteGuard::<T>::new` + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +9 - struct TupleStruct<T: ?Sized>(T); +9 + struct TupleStruct<T>(T); + | diff --git a/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized_fn_params.rs b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized_fn_params.rs new file mode 100644 index 0000000000..e0fa25bf7d --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized_fn_params.rs @@ -0,0 +1,13 @@ +#![feature(unsized_fn_params)] + +use pin_project::pin_project; + +#[pin_project(project_replace)] //~ ERROR E0277 +struct Struct<T: ?Sized> { + f: T, +} + +#[pin_project(project_replace)] //~ ERROR E0277 +struct TupleStruct<T: ?Sized>(T); + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized_fn_params.stderr b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized_fn_params.stderr new file mode 100644 index 0000000000..10fad081aa --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/project_replace_unsized_fn_params.stderr @@ -0,0 +1,112 @@ +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized_fn_params.rs:6:8 + | +6 | struct Struct<T: ?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>` + --> tests/ui/pin_project/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 +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +6 - struct Struct<T: ?Sized> { +6 + struct Struct<T> { + | + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized_fn_params.rs:5:1 + | +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 `std::marker::Sized` + | +note: required because it appears within the type `Struct<T>` + --> tests/ui/pin_project/project_replace_unsized_fn_params.rs:6:8 + | +6 | struct Struct<T: ?Sized> { + | ^^^^^^ +note: required by a bound in `UnsafeOverwriteGuard::<T>::new` + --> src/lib.rs + | + | impl<T> UnsafeOverwriteGuard<T> { + | ^ required by this bound in `UnsafeOverwriteGuard::<T>::new` + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +6 - struct Struct<T: ?Sized> { +6 + struct Struct<T> { + | + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized_fn_params.rs:7:5 + | +5 | #[pin_project(project_replace)] //~ ERROR E0277 + | ------------------------------- required by a bound introduced by this call +6 | struct Struct<T: ?Sized> { + | - this type parameter needs to be `std::marker::Sized` +7 | f: T, + | ^ doesn't have a size known at compile-time + | +note: required by a bound in `std::ptr::read` + --> $RUST/core/src/ptr/mod.rs + | + | pub const unsafe fn read<T>(src: *const T) -> T { + | ^ required by this bound in `std::ptr::read` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +6 - struct Struct<T: ?Sized> { +6 + struct Struct<T> { + | + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized_fn_params.rs:11:8 + | +11 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^^-^^^^^^^^^ + | | | + | | 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>` + --> tests/ui/pin_project/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 +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +11 - struct TupleStruct<T: ?Sized>(T); +11 + struct TupleStruct<T>(T); + | + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> tests/ui/pin_project/project_replace_unsized_fn_params.rs:10:1 + | +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 `std::marker::Sized` + | +note: required because it appears within the type `TupleStruct<T>` + --> tests/ui/pin_project/project_replace_unsized_fn_params.rs:11:8 + | +11 | struct TupleStruct<T: ?Sized>(T); + | ^^^^^^^^^^^ +note: required by a bound in `UnsafeOverwriteGuard::<T>::new` + --> src/lib.rs + | + | impl<T> UnsafeOverwriteGuard<T> { + | ^ required by this bound in `UnsafeOverwriteGuard::<T>::new` + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +11 - struct TupleStruct<T: ?Sized>(T); +11 + struct TupleStruct<T>(T); + | diff --git a/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-field.rs b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-field.rs new file mode 100644 index 0000000000..fd14da37c1 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-field.rs @@ -0,0 +1,33 @@ +use std::{marker::PhantomPinned, pin::Pin}; + +use auxiliary_macro::remove_attr; +use pin_project::pin_project; + +fn is_unpin<T: Unpin>() {} + +#[pin_project] +#[remove_attr(field_all)] +struct A { + #[pin] + f: PhantomPinned, +} + +#[remove_attr(field_all)] +#[pin_project] +struct B { + #[pin] + f: PhantomPinned, +} + +fn main() { + is_unpin::<A>(); + is_unpin::<B>(); + + let mut x = A { f: PhantomPinned }; + let x = Pin::new(&mut x).project(); + let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 + + let mut x = B { f: PhantomPinned }; + let x = Pin::new(&mut x).project(); + let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 +} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-field.stderr b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-field.stderr new file mode 100644 index 0000000000..697cd63549 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-field.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> tests/ui/pin_project/remove-attr-from-field.rs:28:38 + | +28 | let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 + | ----------------------- ^^^ expected struct `Pin`, found `&mut PhantomPinned` + | | + | expected due to this + | + = note: expected struct `Pin<&mut PhantomPinned>` + found mutable reference `&mut PhantomPinned` + +error[E0308]: mismatched types + --> tests/ui/pin_project/remove-attr-from-field.rs:32:38 + | +32 | let _: Pin<&mut PhantomPinned> = x.f; //~ ERROR E0308 + | ----------------------- ^^^ expected struct `Pin`, found `&mut PhantomPinned` + | | + | expected due to this + | + = note: expected struct `Pin<&mut PhantomPinned>` + found mutable reference `&mut PhantomPinned` diff --git a/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-struct.rs b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-struct.rs new file mode 100644 index 0000000000..cbe5aba234 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-struct.rs @@ -0,0 +1,47 @@ +use std::{marker::PhantomPinned, pin::Pin}; + +use auxiliary_macro::remove_attr; +use pin_project::pin_project; + +fn is_unpin<T: Unpin>() {} + +#[pin_project] +#[remove_attr(struct_all)] +struct A { + #[pin] //~ ERROR cannot find attribute `pin` in this scope + f: PhantomPinned, +} + +#[remove_attr(struct_all)] +#[pin_project] +struct B { + #[pin] //~ ERROR cannot find attribute `pin` in this scope + f: PhantomPinned, +} + +#[pin_project] //~ ERROR has been removed +#[remove_attr(struct_pin)] +struct C { + f: PhantomPinned, +} + +#[remove_attr(struct_pin)] +#[pin_project] // Ok +struct D { + f: PhantomPinned, +} + +fn main() { + is_unpin::<A>(); //~ ERROR E0277 + is_unpin::<B>(); //~ ERROR E0277 + is_unpin::<D>(); // Ok + + let mut x = A { f: PhantomPinned }; + let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 + + let mut x = B { f: PhantomPinned }; + let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 + + let mut x = D { f: PhantomPinned }; + let _ = Pin::new(&mut x).project(); //~ Ok +} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-struct.stderr b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-struct.stderr new file mode 100644 index 0000000000..1a9cd42ce2 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/remove-attr-from-struct.stderr @@ -0,0 +1,107 @@ +error: #[pin_project] attribute has been removed + --> tests/ui/pin_project/remove-attr-from-struct.rs:22:1 + | +22 | #[pin_project] //~ ERROR has been removed + | ^^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: cannot find attribute `pin` in this scope + --> tests/ui/pin_project/remove-attr-from-struct.rs:18:7 + | +18 | #[pin] //~ ERROR cannot find attribute `pin` in this scope + | ^^^ + +error: cannot find attribute `pin` in this scope + --> tests/ui/pin_project/remove-attr-from-struct.rs:11:7 + | +11 | #[pin] //~ ERROR cannot find attribute `pin` in this scope + | ^^^ + +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/remove-attr-from-struct.rs:35:5 + | +35 | is_unpin::<A>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^ within `A`, the trait `Unpin` is not implemented for `PhantomPinned` + | + = note: consider using `Box::pin` +note: required because it appears within the type `A` + --> tests/ui/pin_project/remove-attr-from-struct.rs:10:8 + | +10 | struct A { + | ^ +note: required by a bound in `is_unpin` + --> tests/ui/pin_project/remove-attr-from-struct.rs:6:16 + | +6 | fn is_unpin<T: Unpin>() {} + | ^^^^^ required by this bound in `is_unpin` + +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/remove-attr-from-struct.rs:36:5 + | +36 | is_unpin::<B>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^ within `B`, the trait `Unpin` is not implemented for `PhantomPinned` + | + = note: consider using `Box::pin` +note: required because it appears within the type `B` + --> tests/ui/pin_project/remove-attr-from-struct.rs:17:8 + | +17 | struct B { + | ^ +note: required by a bound in `is_unpin` + --> tests/ui/pin_project/remove-attr-from-struct.rs:6:16 + | +6 | fn is_unpin<T: Unpin>() {} + | ^^^^^ required by this bound in `is_unpin` + +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/remove-attr-from-struct.rs:40:22 + | +40 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 + | -------- ^^^^^^ within `A`, the trait `Unpin` is not implemented for `PhantomPinned` + | | + | required by a bound introduced by this call + | + = note: consider using `Box::pin` +note: required because it appears within the type `A` + --> tests/ui/pin_project/remove-attr-from-struct.rs:10:8 + | +10 | struct A { + | ^ +note: required by a bound in `Pin::<P>::new` + --> $RUST/core/src/pin.rs + | + | impl<P: Deref<Target: Unpin>> Pin<P> { + | ^^^^^ required by this bound in `Pin::<P>::new` + +error[E0599]: no method named `project` found for struct `Pin<&mut A>` in the current scope + --> tests/ui/pin_project/remove-attr-from-struct.rs:40:30 + | +40 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 + | ^^^^^^^ method not found in `Pin<&mut A>` + +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/remove-attr-from-struct.rs:43:22 + | +43 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 + | -------- ^^^^^^ within `B`, the trait `Unpin` is not implemented for `PhantomPinned` + | | + | required by a bound introduced by this call + | + = note: consider using `Box::pin` +note: required because it appears within the type `B` + --> tests/ui/pin_project/remove-attr-from-struct.rs:17:8 + | +17 | struct B { + | ^ +note: required by a bound in `Pin::<P>::new` + --> $RUST/core/src/pin.rs + | + | impl<P: Deref<Target: Unpin>> Pin<P> { + | ^^^^^ required by this bound in `Pin::<P>::new` + +error[E0599]: no method named `project` found for struct `Pin<&mut B>` in the current scope + --> tests/ui/pin_project/remove-attr-from-struct.rs:43:30 + | +43 | let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 + | ^^^^^^^ method not found in `Pin<&mut B>` diff --git a/third_party/rust/pin-project/tests/ui/pin_project/safe_packed_borrows.rs b/third_party/rust/pin-project/tests/ui/pin_project/safe_packed_borrows.rs new file mode 100644 index 0000000000..de8181cb9d --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/safe_packed_borrows.rs @@ -0,0 +1,26 @@ +#![deny(renamed_and_removed_lints)] +#![deny(safe_packed_borrows)] //~ ERROR has been renamed to `unaligned_references` +#![allow(unaligned_references)] + +// 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 Packed { + f: u32, +} + +#[repr(packed(2))] +struct PackedN { + f: u32, +} + +fn main() { + let a = Packed { f: 1 }; + let _ = &a.f; + + let b = PackedN { f: 1 }; + let _ = &b.f; +} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/safe_packed_borrows.stderr b/third_party/rust/pin-project/tests/ui/pin_project/safe_packed_borrows.stderr new file mode 100644 index 0000000000..f483b6d3ce --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/safe_packed_borrows.stderr @@ -0,0 +1,11 @@ +error: lint `safe_packed_borrows` has been renamed to `unaligned_references` + --> tests/ui/pin_project/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 + --> tests/ui/pin_project/safe_packed_borrows.rs:1:9 + | +1 | #![deny(renamed_and_removed_lints)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/third_party/rust/pin-project/tests/ui/pin_project/unaligned_references.rs b/third_party/rust/pin-project/tests/ui/pin_project/unaligned_references.rs new file mode 100644 index 0000000000..eaf185d2a3 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/unaligned_references.rs @@ -0,0 +1,21 @@ +#![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 }; + let _ = &a.f; //~ ERROR reference to packed field is unaligned + + let b = PackedN { f: 1 }; + let _ = &b.f; //~ ERROR reference to packed field is unaligned +} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/unaligned_references.stderr b/third_party/rust/pin-project/tests/ui/pin_project/unaligned_references.stderr new file mode 100644 index 0000000000..8d5ddfc591 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/unaligned_references.stderr @@ -0,0 +1,26 @@ +error: reference to packed field is unaligned + --> tests/ui/pin_project/unaligned_references.rs:17:13 + | +17 | let _ = &a.f; //~ ERROR reference to packed field is unaligned + | ^^^^ + | +note: the lint level is defined here + --> tests/ui/pin_project/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) + = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) + +error: reference to packed field is unaligned + --> tests/ui/pin_project/unaligned_references.rs:20:13 + | +20 | 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) + = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) diff --git a/third_party/rust/pin-project/tests/ui/pin_project/unpin_sneaky.rs b/third_party/rust/pin-project/tests/ui/pin_project/unpin_sneaky.rs new file mode 100644 index 0000000000..3f5f32be69 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/unpin_sneaky.rs @@ -0,0 +1,11 @@ +use pin_project::pin_project; + +#[pin_project] +struct S { + #[pin] + f: u8, +} + +impl Unpin for __S {} //~ ERROR E0412,E0321 + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/unpin_sneaky.stderr b/third_party/rust/pin-project/tests/ui/pin_project/unpin_sneaky.stderr new file mode 100644 index 0000000000..82c2aa5b91 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/unpin_sneaky.stderr @@ -0,0 +1,5 @@ +error[E0412]: cannot find type `__S` in this scope + --> tests/ui/pin_project/unpin_sneaky.rs:9:16 + | +9 | impl Unpin for __S {} //~ ERROR E0412,E0321 + | ^^^ not found in this scope diff --git a/third_party/rust/pin-project/tests/ui/pin_project/visibility.rs b/third_party/rust/pin-project/tests/ui/pin_project/visibility.rs new file mode 100644 index 0000000000..fdff5a6783 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/visibility.rs @@ -0,0 +1,49 @@ +/// Only named projected types can be imported. +/// See import_unnamed.rs for unnamed projected types. + +mod pub_ { + use pin_project::pin_project; + + #[pin_project(project = DProj, project_ref = DProjRef)] + pub struct Default(()); + + #[pin_project(project = RProj, project_ref = RProjRef, project_replace = RProjOwn)] + pub struct Replace(()); +} +pub mod pub_use { + #[rustfmt::skip] + pub use crate::pub_::DProj; //~ ERROR E0365 + #[rustfmt::skip] + pub use crate::pub_::DProjRef; //~ ERROR E0365 + #[rustfmt::skip] + pub use crate::pub_::RProj; //~ ERROR E0365 + #[rustfmt::skip] + pub use crate::pub_::RProjOwn; //~ ERROR E0365 + #[rustfmt::skip] + pub use crate::pub_::RProjRef; //~ ERROR E0365 + + // Confirm that the visibility of the original type is not changed. + pub use crate::pub_::{Default, Replace}; +} +pub mod pub_use2 { + // Ok + #[allow(unused_imports)] + pub(crate) use crate::pub_::{DProj, DProjRef, RProj, RProjOwn, RProjRef}; +} + +mod pub_crate { + use pin_project::pin_project; + + #[pin_project(project = DProj, project_ref = DProjRef)] + pub(crate) struct Default(()); + + #[pin_project(project = RProj, project_ref = RProjRef, project_replace = RProjOwn)] + pub(crate) struct Replace(()); +} +pub mod pub_crate_use { + // Ok + #[allow(unused_imports)] + pub(crate) use crate::pub_crate::{DProj, DProjRef, RProj, RProjOwn, RProjRef}; +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/pin_project/visibility.stderr b/third_party/rust/pin-project/tests/ui/pin_project/visibility.stderr new file mode 100644 index 0000000000..4d1b7229a6 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/pin_project/visibility.stderr @@ -0,0 +1,39 @@ +error[E0365]: `DProj` is only public within the crate, and cannot be re-exported outside + --> tests/ui/pin_project/visibility.rs:15:13 + | +15 | pub use crate::pub_::DProj; //~ ERROR E0365 + | ^^^^^^^^^^^^^^^^^^ re-export of crate public `DProj` + | + = note: consider declaring type or module `DProj` with `pub` + +error[E0365]: `DProjRef` is only public within the crate, and cannot be re-exported outside + --> tests/ui/pin_project/visibility.rs:17:13 + | +17 | pub use crate::pub_::DProjRef; //~ ERROR E0365 + | ^^^^^^^^^^^^^^^^^^^^^ re-export of crate public `DProjRef` + | + = note: consider declaring type or module `DProjRef` with `pub` + +error[E0365]: `RProj` is only public within the crate, and cannot be re-exported outside + --> tests/ui/pin_project/visibility.rs:19:13 + | +19 | pub use crate::pub_::RProj; //~ ERROR E0365 + | ^^^^^^^^^^^^^^^^^^ re-export of crate public `RProj` + | + = note: consider declaring type or module `RProj` with `pub` + +error[E0365]: `RProjOwn` is only public within the crate, and cannot be re-exported outside + --> tests/ui/pin_project/visibility.rs:21:13 + | +21 | pub use crate::pub_::RProjOwn; //~ ERROR E0365 + | ^^^^^^^^^^^^^^^^^^^^^ re-export of crate public `RProjOwn` + | + = note: consider declaring type or module `RProjOwn` with `pub` + +error[E0365]: `RProjRef` is only public within the crate, and cannot be re-exported outside + --> tests/ui/pin_project/visibility.rs:23:13 + | +23 | pub use crate::pub_::RProjRef; //~ ERROR E0365 + | ^^^^^^^^^^^^^^^^^^^^^ re-export of crate public `RProjRef` + | + = note: consider declaring type or module `RProjRef` with `pub` |