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/tests/ui/project | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.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/tests/ui/project')
10 files changed, 204 insertions, 0 deletions
diff --git a/third_party/rust/pin-project/tests/ui/project/ambiguous-let.rs b/third_party/rust/pin-project/tests/ui/project/ambiguous-let.rs new file mode 100644 index 0000000000..a7067494ec --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/ambiguous-let.rs @@ -0,0 +1,24 @@ +use pin_project::{pin_project, project}; + +#[pin_project] +enum Enum<A, B> { + A(#[pin] A), + B(B), +} + +struct Struct<T>(T); + +#[project] +fn foo() { + let mut foo: Enum<bool, bool> = Enum::A(true); + + #[project] + let Struct(x) = match Pin::new(&mut foo).project() { + //~^ ERROR Both initializer expression and pattern are replaceable, you need to split the initializer expression into separate let bindings to avoid ambiguity + Enum::A(_) => Struct(true), + Enum::B(_) => unreachable!(), + }; + assert!(x); +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/project/ambiguous-let.stderr b/third_party/rust/pin-project/tests/ui/project/ambiguous-let.stderr new file mode 100644 index 0000000000..e6552c83ec --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/ambiguous-let.stderr @@ -0,0 +1,5 @@ +error: Both initializer expression and pattern are replaceable, you need to split the initializer expression into separate let bindings to avoid ambiguity + --> $DIR/ambiguous-let.rs:16:9 + | +16 | let Struct(x) = match Pin::new(&mut foo).project() { + | ^^^^^^^^^ diff --git a/third_party/rust/pin-project/tests/ui/project/invalid.rs b/third_party/rust/pin-project/tests/ui/project/invalid.rs new file mode 100644 index 0000000000..bc7226deb2 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/invalid.rs @@ -0,0 +1,24 @@ +use pin_project::{pin_project, project}; + +#[pin_project] +struct A<T> { + #[pin] + future: T, +} + +#[project] +fn foo() { + let mut x = A { future: 0 }; + #[project(foo)] //~ ERROR unexpected token + let A { future } = Pin::new(&mut x).project(); +} + +#[project] +fn bar() { + let mut x = A { future: 0 }; + #[project] + #[project] //~ ERROR duplicate #[project] attribute + let A { future } = Pin::new(&mut x).project(); +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/project/invalid.stderr b/third_party/rust/pin-project/tests/ui/project/invalid.stderr new file mode 100644 index 0000000000..a361b72aa3 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/invalid.stderr @@ -0,0 +1,11 @@ +error: unexpected token: (foo) + --> $DIR/invalid.rs:12:14 + | +12 | #[project(foo)] //~ ERROR unexpected token + | ^^^^^ + +error: duplicate #[project] attribute + --> $DIR/invalid.rs:20:5 + | +20 | #[project] //~ ERROR duplicate #[project] attribute + | ^^^^^^^^^^ diff --git a/third_party/rust/pin-project/tests/ui/project/type-mismatch.rs b/third_party/rust/pin-project/tests/ui/project/type-mismatch.rs new file mode 100644 index 0000000000..41a70eb87b --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/type-mismatch.rs @@ -0,0 +1,74 @@ +#![feature(proc_macro_hygiene, stmt_expr_attributes)] + +use pin_project::{pin_project, project}; +use std::pin::Pin; + +#[project] +fn type_mismatch() { + #[pin_project] + enum Enum<A, B, C, D> { + Variant1(#[pin] A, B), + Variant2 { + #[pin] + field1: C, + field2: D, + }, + None, + } + + let mut foo = Enum::Variant1(1, 2); + let mut foo = Pin::new(&mut foo).project(); + + #[project] + match &mut foo { + Enum::Variant1(x, y) => { + let x: &mut Pin<&mut i32> = x; + assert_eq!(**x, 1); + + let y: &mut &mut i32 = y; + assert_eq!(**y, 2); + } + Enum::Variant2 { field1, field2 } => { + let _x: &mut Pin<&mut i32> = field1; + let _y: &mut &mut i32 = field2; + } + None => {} //~ ERROR mismatched types + } +} + +//~ ERROR mismatched types +// span is lost. +// Refs: https://github.com/rust-lang/rust/issues/43081 +fn type_mismatch_span_issue() { + #[pin_project] + enum Enum<A, B, C, D> { + Variant1(#[pin] A, B), + Variant2 { + #[pin] + field1: C, + field2: D, + }, + None, + } + + let mut foo = Enum::Variant1(1, 2); + let mut foo = Pin::new(&mut foo).project(); + + #[project] + match &mut foo { + Enum::Variant1(x, y) => { + let x: &mut Pin<&mut i32> = x; + assert_eq!(**x, 1); + + let y: &mut &mut i32 = y; + assert_eq!(**y, 2); + } + Enum::Variant2 { field1, field2 } => { + let _x: &mut Pin<&mut i32> = field1; + let _y: &mut &mut i32 = field2; + } + None => {} + } +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/project/type-mismatch.stderr b/third_party/rust/pin-project/tests/ui/project/type-mismatch.stderr new file mode 100644 index 0000000000..b4c97d5a99 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/type-mismatch.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/type-mismatch.rs:35:9 + | +23 | match &mut foo { + | -------- this expression has type `&mut type_mismatch::__EnumProjection<'_, {integer}, {integer}, _, _>` +... +35 | None => {} //~ ERROR mismatched types + | ^^^^ expected enum `type_mismatch::__EnumProjection`, found enum `std::option::Option` + | + = note: expected enum `type_mismatch::__EnumProjection<'_, {integer}, {integer}, _, _>` + found enum `std::option::Option<_>` + +error[E0308]: mismatched types + | + = note: expected enum `type_mismatch_span_issue::__EnumProjection<'_, {integer}, {integer}, _, _>` + found enum `std::option::Option<_>` diff --git a/third_party/rust/pin-project/tests/ui/project/use-public.rs b/third_party/rust/pin-project/tests/ui/project/use-public.rs new file mode 100644 index 0000000000..23c9b89d00 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/use-public.rs @@ -0,0 +1,15 @@ +use pin_project::pin_project; + +#[pin_project] +struct A { + field: u8, +} + +pub mod b { + use pin_project::project; + + #[project] + pub use crate::A; //~ ERROR E0365 +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/project/use-public.stderr b/third_party/rust/pin-project/tests/ui/project/use-public.stderr new file mode 100644 index 0000000000..7919d65cbe --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/use-public.stderr @@ -0,0 +1,7 @@ +error[E0365]: `__AProjection` is private, and cannot be re-exported + --> $DIR/use-public.rs:12:13 + | +12 | pub use crate::A; //~ ERROR E0365 + | ^^^^^^^^ re-export of private `__AProjection` + | + = note: consider declaring type or module `__AProjection` with `pub` diff --git a/third_party/rust/pin-project/tests/ui/project/use.rs b/third_party/rust/pin-project/tests/ui/project/use.rs new file mode 100644 index 0000000000..d4b02c1d60 --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/use.rs @@ -0,0 +1,17 @@ +use pin_project::pin_project; + +#[pin_project] +struct A { + field: u8, +} + +mod b { + use pin_project::project; + + #[project] + use crate::A as B; //~ ERROR #[project] attribute may not be used on renamed imports + #[project] + use crate::*; //~ ERROR #[project] attribute may not be used on glob imports +} + +fn main() {} diff --git a/third_party/rust/pin-project/tests/ui/project/use.stderr b/third_party/rust/pin-project/tests/ui/project/use.stderr new file mode 100644 index 0000000000..07d024160b --- /dev/null +++ b/third_party/rust/pin-project/tests/ui/project/use.stderr @@ -0,0 +1,11 @@ +error: #[project] attribute may not be used on renamed imports + --> $DIR/use.rs:12:16 + | +12 | use crate::A as B; //~ ERROR #[project] attribute may not be used on renamed imports + | ^^^^^^ + +error: #[project] attribute may not be used on glob imports + --> $DIR/use.rs:14:16 + | +14 | use crate::*; //~ ERROR #[project] attribute may not be used on glob imports + | ^ |