diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/pin-project-lite/tests | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/pin-project-lite/tests')
22 files changed, 918 insertions, 0 deletions
diff --git a/third_party/rust/pin-project-lite/tests/compiletest.rs b/third_party/rust/pin-project-lite/tests/compiletest.rs new file mode 100644 index 0000000000..ae3df319f0 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/compiletest.rs @@ -0,0 +1,9 @@ +#![warn(unsafe_code)] +#![warn(rust_2018_idioms, single_use_lifetimes)] + +#[rustversion::attr(not(nightly), ignore)] +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} diff --git a/third_party/rust/pin-project-lite/tests/test.rs b/third_party/rust/pin-project-lite/tests/test.rs new file mode 100644 index 0000000000..9077149b6f --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/test.rs @@ -0,0 +1,348 @@ +#![no_std] +#![warn(unsafe_code)] +#![warn(rust_2018_idioms, single_use_lifetimes)] +#![allow(dead_code)] + +use core::{marker::PhantomPinned, pin::Pin}; +use pin_project_lite::pin_project; + +#[test] +fn test_pin_project() { + pin_project! { + struct Foo<T, U> { + #[pin] + field1: T, + field2: U, + } + } + + let mut foo = Foo { field1: 1, field2: 2 }; + + let mut foo_orig = Pin::new(&mut foo); + let foo = foo_orig.as_mut().project(); + + let x: Pin<&mut i32> = foo.field1; + assert_eq!(*x, 1); + + let y: &mut i32 = foo.field2; + assert_eq!(*y, 2); + + assert_eq!(foo_orig.as_ref().field1, 1); + assert_eq!(foo_orig.as_ref().field2, 2); + + let mut foo = Foo { field1: 1, field2: 2 }; + + let foo = Pin::new(&mut foo).project(); + + let field1 = foo.field1; + let field2 = foo.field2; + let _: Pin<&mut i32> = field1; + let _: &mut i32 = field2; +} + +#[test] +fn where_clause_and_associated_type_fields() { + pin_project! { + struct Struct1<I> + where + I: Iterator, + { + #[pin] + field1: I, + field2: I::Item, + } + } + + pin_project! { + struct Struct2<I, J> + where + I: Iterator<Item = J>, + { + #[pin] + field1: I, + field2: J, + } + } + + // TODO(#7): where clause does not support yet. + + // pin_project! { + // pub struct Struct3<T> + // where + // T: 'static, + // { + // field: T, + // } + // } + + // trait Static: 'static {} + + // impl<T> Static for Struct3<T> {} +} + +// #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 +// #[test] +// fn unsized_in_where_clause() { +// pin_project! { +// struct Struct<I> +// where +// I: ?Sized, +// { +// #[pin] +// field: I, +// } +// } +// } + +#[test] +fn derive_copy() { + pin_project! { + #[derive(Clone, Copy)] + struct Struct<T> { + val: T, + } + } + + fn is_copy<T: Copy>() {} + + is_copy::<Struct<u8>>(); +} + +#[test] +fn move_out() { + struct NotCopy; + + pin_project! { + struct Struct { + val: NotCopy, + } + } + + let foo = Struct { val: NotCopy }; + let _val: NotCopy = foo.val; +} + +#[test] +fn trait_bounds_on_type_generics() { + pin_project! { + pub struct Struct1<'a, T: ?Sized> { + field: &'a mut T, + } + } + + pin_project! { + pub struct Struct2<'a, T: ::core::fmt::Debug> { + field: &'a mut T, + } + } + + pin_project! { + pub struct Struct3<'a, T: core::fmt::Debug> { + field: &'a mut T, + } + } + + // pin_project! { + // pub struct Struct4<'a, T: core::fmt::Debug + core::fmt::Display> { + // field: &'a mut T, + // } + // } + + // pin_project! { + // pub struct Struct5<'a, T: core::fmt::Debug + ?Sized> { + // field: &'a mut T, + // } + // } + + pin_project! { + pub struct Struct6<'a, T: core::fmt::Debug = [u8; 16]> { + field: &'a mut T, + } + } + + let _: Struct6<'_> = Struct6 { field: &mut [0u8; 16] }; + + pin_project! { + pub struct Struct7<T: 'static> { + field: T, + } + } + + trait Static: 'static {} + + impl<T> Static for Struct7<T> {} + + pin_project! { + pub struct Struct8<'a, 'b: 'a> { + field1: &'a u8, + field2: &'b u8, + } + } +} + +#[test] +fn private_type_in_public_type() { + pin_project! { + pub struct PublicStruct<T> { + #[pin] + inner: PrivateStruct<T>, + } + } + + struct PrivateStruct<T>(T); +} + +#[test] +fn lifetime_project() { + pin_project! { + struct Struct1<T, U> { + #[pin] + pinned: T, + unpinned: U, + } + } + + pin_project! { + struct Struct2<'a, T, U> { + #[pin] + pinned: &'a mut T, + unpinned: U, + } + } + + impl<T, U> Struct1<T, U> { + fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T> { + self.project_ref().pinned + } + fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { + self.project().pinned + } + } + + impl<'b, T, U> Struct2<'b, T, U> { + fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a &'b mut T> { + self.project_ref().pinned + } + fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut &'b mut T> { + self.project().pinned + } + } +} + +#[test] +fn lifetime_project_elided() { + pin_project! { + struct Struct1<T, U> { + #[pin] + pinned: T, + unpinned: U, + } + } + + pin_project! { + struct Struct2<'a, T, U> { + #[pin] + pinned: &'a mut T, + unpinned: U, + } + } + + impl<T, U> Struct1<T, U> { + fn get_pin_ref(self: Pin<&Self>) -> Pin<&T> { + self.project_ref().pinned + } + fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T> { + self.project().pinned + } + } + + impl<'b, T, U> Struct2<'b, T, U> { + fn get_pin_ref(self: Pin<&Self>) -> Pin<&&'b mut T> { + self.project_ref().pinned + } + fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut &'b mut T> { + self.project().pinned + } + } +} + +mod visibility { + use pin_project_lite::pin_project; + + pin_project! { + pub(crate) struct A { + pub b: u8, + } + } +} + +#[test] +fn visibility() { + let mut x = visibility::A { b: 0 }; + let x = Pin::new(&mut x); + let y = x.as_ref().project_ref(); + let _: &u8 = y.b; + let y = x.project(); + let _: &mut u8 = y.b; +} + +#[test] +fn trivial_bounds() { + pin_project! { + pub struct NoGenerics { + #[pin] + field: PhantomPinned, + } + } +} + +#[test] +fn dst() { + pin_project! { + pub struct A<T: ?Sized> { + x: T, + } + } + + let _: &mut A<dyn core::fmt::Debug> = &mut A { x: 0u8 } as _; + + pin_project! { + pub struct B<T: ?Sized> { + #[pin] + x: T, + } + } +} + +#[test] +fn dyn_type() { + pin_project! { + struct Struct1 { + a: i32, + f: dyn core::fmt::Debug, + } + } + + pin_project! { + struct Struct2 { + a: i32, + #[pin] + f: dyn core::fmt::Debug, + } + } + + pin_project! { + struct Struct3 { + a: i32, + f: dyn core::fmt::Debug + Send, + } + } + + pin_project! { + struct Struct4 { + a: i32, + #[pin] + f: dyn core::fmt::Debug + Send, + } + } +} diff --git a/third_party/rust/pin-project-lite/tests/ui/conflict-drop.rs b/third_party/rust/pin-project-lite/tests/ui/conflict-drop.rs new file mode 100644 index 0000000000..870059d62f --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/conflict-drop.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { //~ ERROR E0119 + struct Foo<T, U> { + #[pin] + future: T, + field: U, + } +} + +impl<T, U> Drop for Foo<T, U> { + fn drop(&mut self) {} +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/conflict-drop.stderr b/third_party/rust/pin-project-lite/tests/ui/conflict-drop.stderr new file mode 100644 index 0000000000..6679d3d244 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/conflict-drop.stderr @@ -0,0 +1,16 @@ +error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>`: + --> $DIR/conflict-drop.rs:3:1 + | +3 | / pin_project! { //~ ERROR E0119 +4 | | struct Foo<T, U> { +5 | | #[pin] +6 | | future: T, +7 | | field: U, +8 | | } +9 | | } + | | ^ + | | | + | |_first implementation here + | conflicting implementation for `Foo<_, _>` + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/conflict-unpin.rs b/third_party/rust/pin-project-lite/tests/ui/conflict-unpin.rs new file mode 100644 index 0000000000..f702f064de --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/conflict-unpin.rs @@ -0,0 +1,40 @@ +use pin_project_lite::pin_project; + +// The same implementation. + +pin_project! { //~ ERROR E0119 + struct Foo<T, U> { + #[pin] + future: T, + field: 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] + future: T, + field: U, + } +} + +// conflicting implementations +impl<T, U> Unpin for Bar<T, U> {} // Non-conditional Unpin impl + +pin_project! { //~ ERROR E0119 + struct Baz<T, U> { + #[pin] + future: T, + field: 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-lite/tests/ui/conflict-unpin.stderr b/third_party/rust/pin-project-lite/tests/ui/conflict-unpin.stderr new file mode 100644 index 0000000000..8065fde58b --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/conflict-unpin.stderr @@ -0,0 +1,50 @@ +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>`: + --> $DIR/conflict-unpin.rs:5:1 + | +5 | / pin_project! { //~ ERROR E0119 +6 | | struct Foo<T, U> { +7 | | #[pin] +8 | | future: T, +9 | | field: U, +10 | | } +11 | | } + | |_^ conflicting implementation for `Foo<_, _>` +... +14 | impl<T, U> Unpin for Foo<T, U> where T: Unpin {} // Conditional Unpin impl + | --------------------------------------------- first implementation here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>`: + --> $DIR/conflict-unpin.rs:18:1 + | +18 | / pin_project! { //~ ERROR E0119 +19 | | struct Bar<T, U> { +20 | | #[pin] +21 | | future: T, +22 | | field: U, +23 | | } +24 | | } + | |_^ conflicting implementation for `Bar<_, _>` +... +27 | impl<T, U> Unpin for Bar<T, U> {} // Non-conditional Unpin impl + | ------------------------------ first implementation here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>`: + --> $DIR/conflict-unpin.rs:29:1 + | +29 | / pin_project! { //~ ERROR E0119 +30 | | struct Baz<T, U> { +31 | | #[pin] +32 | | future: T, +33 | | field: U, +34 | | } +35 | | } + | |_^ conflicting implementation for `Baz<_, _>` +... +38 | impl<T: Unpin, U: Unpin> Unpin for Baz<T, U> {} // Conditional Unpin impl + | -------------------------------------------- first implementation here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/invalid-bounds.rs b/third_party/rust/pin-project-lite/tests/ui/invalid-bounds.rs new file mode 100644 index 0000000000..980bb952ea --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/invalid-bounds.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct A<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:` + field: T, + } +} + +pin_project! { + struct B<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` + field: T, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/invalid-bounds.stderr b/third_party/rust/pin-project-lite/tests/ui/invalid-bounds.stderr new file mode 100644 index 0000000000..ebd1da8179 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/invalid-bounds.stderr @@ -0,0 +1,21 @@ +error: no rules expected the token `:` + --> $DIR/invalid-bounds.rs:4:25 + | +4 | struct A<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:` + | ^ no rules expected this token in macro call + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> $DIR/invalid-bounds.rs:9:1 + | +9 | / pin_project! { +10 | | struct B<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +11 | | field: T, +12 | | } +13 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/invalid.rs b/third_party/rust/pin-project-lite/tests/ui/invalid.rs new file mode 100644 index 0000000000..e0ea61d4f7 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/invalid.rs @@ -0,0 +1,25 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct A<T> { + #[pin()] //~ ERROR no rules expected the token `(` + pinned: T, + } +} + +pin_project! { + #[pin] //~ ERROR cannot find attribute `pin` in this scope + struct B<T> { + pinned: T, + } +} + +pin_project! { + struct C<T> { + #[pin] + #[pin] //~ ERROR no rules expected the token `#` + pinned: T, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/invalid.stderr b/third_party/rust/pin-project-lite/tests/ui/invalid.stderr new file mode 100644 index 0000000000..f780e2e69a --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/invalid.stderr @@ -0,0 +1,17 @@ +error: no rules expected the token `(` + --> $DIR/invalid.rs:5:14 + | +5 | #[pin()] //~ ERROR no rules expected the token `(` + | ^ no rules expected this token in macro call + +error: no rules expected the token `#` + --> $DIR/invalid.rs:20:9 + | +20 | #[pin] //~ ERROR no rules expected the token `#` + | ^ no rules expected this token in macro call + +error: cannot find attribute `pin` in this scope + --> $DIR/invalid.rs:11:7 + | +11 | #[pin] //~ ERROR cannot find attribute `pin` in this scope + | ^^^ diff --git a/third_party/rust/pin-project-lite/tests/ui/overlapping_lifetime_names.rs b/third_party/rust/pin-project-lite/tests/ui/overlapping_lifetime_names.rs new file mode 100644 index 0000000000..87a737e2fa --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/overlapping_lifetime_names.rs @@ -0,0 +1,10 @@ +use pin_project_lite::pin_project; + +pin_project! { //~ ERROR E0496 + pub struct Foo<'__pin, T> { //~ ERROR E0263 + #[pin] + field: &'__pin mut T, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/overlapping_lifetime_names.stderr b/third_party/rust/pin-project-lite/tests/ui/overlapping_lifetime_names.stderr new file mode 100644 index 0000000000..db4f5a8bb0 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/overlapping_lifetime_names.stderr @@ -0,0 +1,83 @@ +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> $DIR/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0496 +4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> $DIR/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0496 +4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope + --> $DIR/overlapping_lifetime_names.rs:3:1 + | +3 | / pin_project! { //~ ERROR E0496 +4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 + | | ------ first declared here +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_^ lifetime '__pin already in scope + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope + --> $DIR/overlapping_lifetime_names.rs:3:1 + | +3 | / pin_project! { //~ ERROR E0496 +4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 + | | ------ first declared here +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_^ lifetime '__pin already in scope + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> $DIR/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0496 +4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> $DIR/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0496 +4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/overlapping_unpin_struct.rs b/third_party/rust/pin-project-lite/tests/ui/overlapping_unpin_struct.rs new file mode 100644 index 0000000000..1338524307 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/overlapping_unpin_struct.rs @@ -0,0 +1,19 @@ +use pin_project_lite::pin_project; +use std::marker::PhantomPinned; + +pin_project! { + struct Foo<T> { + #[pin] + inner: T, + } +} + +struct __Origin {} + +impl Unpin for __Origin {} + +fn is_unpin<T: Unpin>() {} + +fn main() { + is_unpin::<Foo<PhantomPinned>>(); //~ ERROR E0277 +} diff --git a/third_party/rust/pin-project-lite/tests/ui/overlapping_unpin_struct.stderr b/third_party/rust/pin-project-lite/tests/ui/overlapping_unpin_struct.stderr new file mode 100644 index 0000000000..73db6f932b --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/overlapping_unpin_struct.stderr @@ -0,0 +1,13 @@ +error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_, std::marker::PhantomPinned>` + --> $DIR/overlapping_unpin_struct.rs:18:5 + | +15 | fn is_unpin<T: Unpin>() {} + | -------- ----- required by this bound in `is_unpin` +... +18 | is_unpin::<Foo<PhantomPinned>>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` + | + = help: the following implementations were found: + <std::marker::PhantomPinned as std::marker::Unpin> + = note: required because it appears within the type `_::__Origin<'_, std::marker::PhantomPinned>` + = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<std::marker::PhantomPinned>` diff --git a/third_party/rust/pin-project-lite/tests/ui/packed.rs b/third_party/rust/pin-project-lite/tests/ui/packed.rs new file mode 100644 index 0000000000..0bccc1f216 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/packed.rs @@ -0,0 +1,19 @@ +use pin_project_lite::pin_project; + +pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block + #[repr(packed, C)] + struct A { + #[pin] + field: u16, + } +} + +pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block + #[repr(packed(2))] + struct C { + #[pin] + field: u32, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/packed.stderr b/third_party/rust/pin-project-lite/tests/ui/packed.stderr new file mode 100644 index 0000000000..1853377dec --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/packed.stderr @@ -0,0 +1,55 @@ +error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) + --> $DIR/packed.rs:3:1 + | +3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block +4 | | #[repr(packed, C)] +5 | | struct A { +6 | | #[pin] +7 | | field: u16, +8 | | } +9 | | } + | |_^ + | +note: lint level defined here + --> $DIR/packed.rs:3:1 + | +3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block +4 | | #[repr(packed, C)] +5 | | struct A { +6 | | #[pin] +7 | | field: u16, +8 | | } +9 | | } + | |_^ + = 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 + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) + --> $DIR/packed.rs:11:1 + | +11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block +12 | | #[repr(packed(2))] +13 | | struct C { +14 | | #[pin] +15 | | field: u32, +16 | | } +17 | | } + | |_^ + | +note: lint level defined here + --> $DIR/packed.rs:11:1 + | +11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block +12 | | #[repr(packed(2))] +13 | | struct C { +14 | | #[pin] +15 | | field: u32, +16 | | } +17 | | } + | |_^ + = 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 + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/proper_unpin.rs b/third_party/rust/pin-project-lite/tests/ui/proper_unpin.rs new file mode 100644 index 0000000000..3c85f2d77f --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/proper_unpin.rs @@ -0,0 +1,41 @@ +use pin_project_lite::pin_project; +use std::marker::PhantomPinned; + +struct Inner<T> { + val: T, +} + +pin_project! { + struct Foo<T, U> { + #[pin] + inner: Inner<T>, + other: U, + } +} + +pin_project! { + pub struct TrivialBounds { + #[pin] + field1: PhantomPinned, + } +} + +pin_project! { + struct Bar<'a, T, U> { + #[pin] + inner: &'a mut Inner<T>, + other: U, + } +} + +fn is_unpin<T: Unpin>() {} + +fn main() { + is_unpin::<Foo<PhantomPinned, ()>>(); //~ ERROR E0277 + is_unpin::<Foo<(), PhantomPinned>>(); // Ok + is_unpin::<Foo<PhantomPinned, PhantomPinned>>(); //~ ERROR E0277 + + is_unpin::<TrivialBounds>(); //~ ERROR E0277 + + is_unpin::<Bar<'_, PhantomPinned, PhantomPinned>>(); //~ Ok +} diff --git a/third_party/rust/pin-project-lite/tests/ui/proper_unpin.stderr b/third_party/rust/pin-project-lite/tests/ui/proper_unpin.stderr new file mode 100644 index 0000000000..52eb80223e --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/proper_unpin.stderr @@ -0,0 +1,43 @@ +error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_, std::marker::PhantomPinned, ()>` + --> $DIR/proper_unpin.rs:34:5 + | +31 | fn is_unpin<T: Unpin>() {} + | -------- ----- required by this bound in `is_unpin` +... +34 | is_unpin::<Foo<PhantomPinned, ()>>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, std::marker::PhantomPinned, ()>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` + | + = help: the following implementations were found: + <std::marker::PhantomPinned as std::marker::Unpin> + = note: required because it appears within the type `Inner<std::marker::PhantomPinned>` + = note: required because it appears within the type `_::__Origin<'_, std::marker::PhantomPinned, ()>` + = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<std::marker::PhantomPinned, ()>` + +error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>` + --> $DIR/proper_unpin.rs:36:5 + | +31 | fn is_unpin<T: Unpin>() {} + | -------- ----- required by this bound in `is_unpin` +... +36 | is_unpin::<Foo<PhantomPinned, PhantomPinned>>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` + | + = help: the following implementations were found: + <std::marker::PhantomPinned as std::marker::Unpin> + = note: required because it appears within the type `Inner<std::marker::PhantomPinned>` + = note: required because it appears within the type `_::__Origin<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>` + = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<std::marker::PhantomPinned, std::marker::PhantomPinned>` + +error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_>` + --> $DIR/proper_unpin.rs:38:5 + | +31 | fn is_unpin<T: Unpin>() {} + | -------- ----- required by this bound in `is_unpin` +... +38 | is_unpin::<TrivialBounds>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` + | + = help: the following implementations were found: + <std::marker::PhantomPinned as std::marker::Unpin> + = note: required because it appears within the type `_::__Origin<'_>` + = note: required because of the requirements on the impl of `std::marker::Unpin` for `TrivialBounds` diff --git a/third_party/rust/pin-project-lite/tests/ui/unpin_sneaky.rs b/third_party/rust/pin-project-lite/tests/ui/unpin_sneaky.rs new file mode 100644 index 0000000000..984cc2a219 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/unpin_sneaky.rs @@ -0,0 +1,12 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Foo { + #[pin] + inner: u8, + } +} + +impl Unpin for __Origin {} //~ ERROR E0412,E0321 + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/unpin_sneaky.stderr b/third_party/rust/pin-project-lite/tests/ui/unpin_sneaky.stderr new file mode 100644 index 0000000000..77ad2dc315 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/unpin_sneaky.stderr @@ -0,0 +1,11 @@ +error[E0412]: cannot find type `__Origin` in this scope + --> $DIR/unpin_sneaky.rs:10:16 + | +10 | impl Unpin for __Origin {} //~ ERROR E0412,E0321 + | ^^^^^^^^ not found in this scope + +error[E0321]: cross-crate traits with a default impl, like `std::marker::Unpin`, can only be implemented for a struct/enum type, not `[type error]` + --> $DIR/unpin_sneaky.rs:10:1 + | +10 | impl Unpin for __Origin {} //~ ERROR E0412,E0321 + | ^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type diff --git a/third_party/rust/pin-project-lite/tests/ui/unsupported.rs b/third_party/rust/pin-project-lite/tests/ui/unsupported.rs new file mode 100644 index 0000000000..2f80836275 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/unsupported.rs @@ -0,0 +1,27 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Struct1 {} //~ ERROR no rules expected the token `}` +} + +pin_project! { + struct Struct2(); //~ ERROR no rules expected the token `(` +} + +pin_project! { + struct Struct3; //~ ERROR no rules expected the token `;` +} + +pin_project! { + enum Enum { //~ ERROR no rules expected the token `enum` + A(u8) + } +} + +pin_project! { + union Union { //~ ERROR no rules expected the token `union` + x: u8, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/unsupported.stderr b/third_party/rust/pin-project-lite/tests/ui/unsupported.stderr new file mode 100644 index 0000000000..4f7b1aed09 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/unsupported.stderr @@ -0,0 +1,29 @@ +error: no rules expected the token `}` + --> $DIR/unsupported.rs:4:21 + | +4 | struct Struct1 {} //~ ERROR no rules expected the token `}` + | ^ no rules expected this token in macro call + +error: no rules expected the token `(` + --> $DIR/unsupported.rs:8:19 + | +8 | struct Struct2(); //~ ERROR no rules expected the token `(` + | ^ no rules expected this token in macro call + +error: no rules expected the token `;` + --> $DIR/unsupported.rs:12:19 + | +12 | struct Struct3; //~ ERROR no rules expected the token `;` + | ^ no rules expected this token in macro call + +error: no rules expected the token `enum` + --> $DIR/unsupported.rs:16:5 + | +16 | enum Enum { //~ ERROR no rules expected the token `enum` + | ^^^^ no rules expected this token in macro call + +error: no rules expected the token `union` + --> $DIR/unsupported.rs:22:5 + | +22 | union Union { //~ ERROR no rules expected the token `union` + | ^^^^^ no rules expected this token in macro call |