From 0bca927e552b788e4c60d4ce64e8fc0a5e215bd3 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 3 Sep 2019 05:25:02 +0900 Subject: [PATCH] Tweak ui tests and error messages --- pin-project-internal/src/pin_project/enums.rs | 12 ++++-- pin-project-internal/src/pin_project/mod.rs | 11 +++-- .../src/pin_project/structs.rs | 12 +++++- tests/ui/pin_project/drop_conflict.rs | 2 - tests/ui/pin_project/drop_conflict.stderr | 10 ++--- tests/ui/pin_project/forget-unsafe-unpin.rs | 2 - .../ui/pin_project/forget-unsafe-unpin.stderr | 0 tests/ui/pin_project/invalid.rs | 4 +- tests/ui/pin_project/invalid.stderr | 20 ++++----- tests/ui/pin_project/packed.rs | 2 - tests/ui/pin_project/packed.stderr | 12 +++--- tests/ui/pin_project/proper_unpin.rs | 6 +-- tests/ui/pin_project/proper_unpin.stderr | 6 +-- tests/ui/pin_project/unpin_conflict.rs | 2 - tests/ui/pin_project/unpin_conflict.stderr | 18 ++++---- tests/ui/pin_project/unpin_sneaky.rs | 6 ++- tests/ui/pin_project/unpin_sneaky.stderr | 22 +++++----- tests/ui/pin_project/unsupported.rs | 14 +++---- tests/ui/pin_project/unsupported.stderr | 42 +++++++++---------- tests/ui/pinned_drop/forget-pinned-drop.rs | 11 ++--- .../ui/pinned_drop/forget-pinned-drop.stderr | 8 ++-- tests/ui/pinned_drop/invalid.rs | 16 +++---- tests/ui/pinned_drop/invalid.stderr | 10 ++--- tests/ui/pinned_drop/return-type.rs | 30 +++++++------ tests/ui/pinned_drop/return-type.stderr | 14 +++++-- tests/ui/project/ambiguous-let.rs | 3 +- tests/ui/project/ambiguous-let.stderr | 8 ++-- tests/ui/project/invalid.rs | 2 - tests/ui/project/invalid.stderr | 4 +- tests/ui/project/type-mismatch.rs | 1 - tests/ui/project/type-mismatch.stderr | 4 +- 31 files changed, 157 insertions(+), 157 deletions(-) delete mode 100644 tests/ui/pin_project/forget-unsafe-unpin.stderr diff --git a/pin-project-internal/src/pin_project/enums.rs b/pin-project-internal/src/pin_project/enums.rs index 094eb1c8..473ea796 100644 --- a/pin-project-internal/src/pin_project/enums.rs +++ b/pin-project-internal/src/pin_project/enums.rs @@ -8,11 +8,14 @@ use super::{Context, PIN}; pub(super) fn parse(cx: &mut Context, mut item: ItemEnum) -> Result { if item.variants.is_empty() { - return Err(error!(item, "cannot be implemented for enums without variants")); + return Err(error!( + item, + "#[pin_project] attribute may not be used on enums without variants" + )); } let has_field = item.variants.iter().try_fold(false, |has_field, v| { if let Some((_, e)) = &v.discriminant { - Err(error!(e, "cannot be implemented for enums with discriminants")) + Err(error!(e, "#[pin_project] attribute may not be used on enums with discriminants")) } else if let Fields::Unit = v.fields { Ok(has_field) } else { @@ -20,7 +23,10 @@ pub(super) fn parse(cx: &mut Context, mut item: ItemEnum) -> Result } })?; if !has_field { - return Err(error!(item.variants, "cannot be implemented for enums that have no field")); + return Err(error!( + item.variants, + "#[pin_project] attribute may not be used on enums that have no field" + )); } let (proj_variants, proj_arms) = variants(cx, &mut item)?; diff --git a/pin-project-internal/src/pin_project/mod.rs b/pin-project-internal/src/pin_project/mod.rs index 4c543f4d..da1144b8 100644 --- a/pin-project-internal/src/pin_project/mod.rs +++ b/pin-project-internal/src/pin_project/mod.rs @@ -35,7 +35,12 @@ impl Parse for Args { match &*i.to_string() { "PinnedDrop" => pinned_drop = Some(i.span()), "UnsafeUnpin" => unsafe_unpin = Some(i.span()), - _ => return Err(error!(i, "an invalid argument was passed")), + _ => { + return Err(error!( + i, + "an invalid argument was passed to #[pin_project] attribute" + )) + } } if !input.is_empty() { @@ -363,7 +368,7 @@ fn parse(args: TokenStream, input: TokenStream) -> Result { res.extend(cx.make_proj_trait()); Ok(res) } - item => Err(error!(item, "may only be used on structs or enums")), + item => Err(error!(item, "#[pin_project] attribute may only be used on structs or enums")), } } @@ -376,7 +381,7 @@ fn ensure_not_packed(item: &ItemStruct) -> Result { if p.is_ident("packed") { return Err(error!( p, - "pin_project may not be used on #[repr(packed)] types" + "#[pin_project] attribute may not be used on #[repr(packed)] types" )); } } diff --git a/pin-project-internal/src/pin_project/structs.rs b/pin-project-internal/src/pin_project/structs.rs index 2196194a..023cd604 100644 --- a/pin-project-internal/src/pin_project/structs.rs +++ b/pin-project-internal/src/pin_project/structs.rs @@ -12,9 +12,17 @@ pub(super) fn parse(cx: &mut Context, mut item: ItemStruct) -> Result { - return Err(error!(item.fields, "cannot be implemented for structs with zero fields")) + return Err(error!( + item.fields, + "#[pin_project] attribute may not be used on structs with zero fields" + )) + } + Fields::Unit => { + return Err(error!( + item, + "#[pin_project] attribute may not be used on structs with units" + )) } - Fields::Unit => return Err(error!(item, "cannot be implemented for structs with units")), Fields::Named(fields) => named(cx, fields)?, Fields::Unnamed(fields) => unnamed(cx, fields)?, diff --git a/tests/ui/pin_project/drop_conflict.rs b/tests/ui/pin_project/drop_conflict.rs index 1e58a4f7..ffd60dd3 100644 --- a/tests/ui/pin_project/drop_conflict.rs +++ b/tests/ui/pin_project/drop_conflict.rs @@ -1,7 +1,5 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; diff --git a/tests/ui/pin_project/drop_conflict.stderr b/tests/ui/pin_project/drop_conflict.stderr index d95533b9..72f1e91e 100644 --- a/tests/ui/pin_project/drop_conflict.stderr +++ b/tests/ui/pin_project/drop_conflict.stderr @@ -1,19 +1,19 @@ error[E0119]: conflicting implementations of trait `FooMustNotImplDrop` for type `Foo<_, _>`: - --> $DIR/drop_conflict.rs:8:1 + --> $DIR/drop_conflict.rs:6:1 | -8 | #[pin_project] //~ ERROR E0119 +6 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ | | | first implementation here | conflicting implementation for `Foo<_, _>` error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `Bar<_, _>`: - --> $DIR/drop_conflict.rs:19:1 + --> $DIR/drop_conflict.rs:17:1 | -19 | #[pin_project(PinnedDrop)] //~ ERROR E0119 +17 | #[pin_project(PinnedDrop)] //~ ERROR E0119 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Bar<_, _>` ... -29 | impl Drop for Bar { +27 | impl Drop for Bar { | ----------------------------- first implementation here error: aborting due to 2 previous errors diff --git a/tests/ui/pin_project/forget-unsafe-unpin.rs b/tests/ui/pin_project/forget-unsafe-unpin.rs index 2e2d9172..31fa204c 100644 --- a/tests/ui/pin_project/forget-unsafe-unpin.rs +++ b/tests/ui/pin_project/forget-unsafe-unpin.rs @@ -1,7 +1,5 @@ // run-pass -#![deny(warnings, unsafe_code)] - use pin_project::pin_project; // FIXME diff --git a/tests/ui/pin_project/forget-unsafe-unpin.stderr b/tests/ui/pin_project/forget-unsafe-unpin.stderr deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/ui/pin_project/invalid.rs b/tests/ui/pin_project/invalid.rs index 2223d34f..c0a6b36f 100644 --- a/tests/ui/pin_project/invalid.rs +++ b/tests/ui/pin_project/invalid.rs @@ -1,7 +1,5 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::pin_project; #[pin_project] @@ -26,7 +24,7 @@ enum D { }, } -#[pin_project(UnsafeUnpin,,)] //~ ERROR unexpected token +#[pin_project(UnsafeUnpin,,)] //~ ERROR expected identifier struct E { #[pin] future: T, diff --git a/tests/ui/pin_project/invalid.stderr b/tests/ui/pin_project/invalid.stderr index 25c1a708..fb5f0919 100644 --- a/tests/ui/pin_project/invalid.stderr +++ b/tests/ui/pin_project/invalid.stderr @@ -1,31 +1,31 @@ error: unexpected token - --> $DIR/invalid.rs:9:10 + --> $DIR/invalid.rs:7:10 | -9 | #[pin()] //~ ERROR unexpected token +7 | #[pin()] //~ ERROR unexpected token | ^ error: unexpected token - --> $DIR/invalid.rs:14:18 + --> $DIR/invalid.rs:12:18 | -14 | struct B(#[pin(foo)] T); //~ ERROR unexpected token +12 | struct B(#[pin(foo)] T); //~ ERROR unexpected token | ^ error: unexpected token - --> $DIR/invalid.rs:18:12 + --> $DIR/invalid.rs:16:12 | -18 | A(#[pin(foo)] T), //~ ERROR unexpected token +16 | A(#[pin(foo)] T), //~ ERROR unexpected token | ^ error: unexpected token - --> $DIR/invalid.rs:24:14 + --> $DIR/invalid.rs:22:14 | -24 | #[pin(foo)] //~ ERROR unexpected token +22 | #[pin(foo)] //~ ERROR unexpected token | ^ error: expected identifier - --> $DIR/invalid.rs:29:27 + --> $DIR/invalid.rs:27:27 | -29 | #[pin_project(UnsafeUnpin,,)] //~ ERROR unexpected token +27 | #[pin_project(UnsafeUnpin,,)] //~ ERROR expected identifier | ^ error: aborting due to 5 previous errors diff --git a/tests/ui/pin_project/packed.rs b/tests/ui/pin_project/packed.rs index fcddd0f8..5770e877 100644 --- a/tests/ui/pin_project/packed.rs +++ b/tests/ui/pin_project/packed.rs @@ -1,7 +1,5 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::pin_project; #[pin_project] diff --git a/tests/ui/pin_project/packed.stderr b/tests/ui/pin_project/packed.stderr index c6dc2bd9..118c7cb3 100644 --- a/tests/ui/pin_project/packed.stderr +++ b/tests/ui/pin_project/packed.stderr @@ -1,13 +1,13 @@ -error: pin_project may not be used on #[repr(packed)] types - --> $DIR/packed.rs:8:8 +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> $DIR/packed.rs:6:8 | -8 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] type +6 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] type | ^^^^^^ -error: pin_project may not be used on #[repr(packed)] types - --> $DIR/packed.rs:15:8 +error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> $DIR/packed.rs:13:8 | -15 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] type +13 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] type | ^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/pin_project/proper_unpin.rs b/tests/ui/pin_project/proper_unpin.rs index 1eac4780..8a1ace14 100644 --- a/tests/ui/pin_project/proper_unpin.rs +++ b/tests/ui/pin_project/proper_unpin.rs @@ -1,19 +1,17 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; struct Inner { - val: T + val: T, } #[pin_project] struct Foo { #[pin] inner: Inner, - other: U + other: U, } fn is_unpin() {} diff --git a/tests/ui/pin_project/proper_unpin.stderr b/tests/ui/pin_project/proper_unpin.stderr index dccb5acc..06caaacd 100644 --- a/tests/ui/pin_project/proper_unpin.stderr +++ b/tests/ui/pin_project/proper_unpin.stderr @@ -1,10 +1,10 @@ error[E0277]: the trait bound `T: std::marker::Unpin` is not satisfied in `__UnpinStructFoo` - --> $DIR/proper_unpin.rs:22:5 + --> $DIR/proper_unpin.rs:20:5 | -19 | fn is_unpin() {} +17 | fn is_unpin() {} | ----------------------- required by `is_unpin` ... -22 | is_unpin::>(); //~ ERROR E0277 +20 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^ within `__UnpinStructFoo`, the trait `std::marker::Unpin` is not implemented for `T` | = help: consider adding a `where T: std::marker::Unpin` bound diff --git a/tests/ui/pin_project/unpin_conflict.rs b/tests/ui/pin_project/unpin_conflict.rs index 4f21f35a..6d0a8ff0 100644 --- a/tests/ui/pin_project/unpin_conflict.rs +++ b/tests/ui/pin_project/unpin_conflict.rs @@ -1,7 +1,5 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::pin_project; use std::pin::Pin; diff --git a/tests/ui/pin_project/unpin_conflict.stderr b/tests/ui/pin_project/unpin_conflict.stderr index 8a6df905..78848ad6 100644 --- a/tests/ui/pin_project/unpin_conflict.stderr +++ b/tests/ui/pin_project/unpin_conflict.stderr @@ -1,28 +1,28 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>`: - --> $DIR/unpin_conflict.rs:10:1 + --> $DIR/unpin_conflict.rs:8:1 | -10 | #[pin_project] //~ ERROR E0119 +8 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Foo<_, _>` ... -18 | impl Unpin for Foo where T: Unpin {} // Conditional Unpin impl +16 | impl Unpin for Foo where T: Unpin {} // Conditional Unpin impl | --------------------------------------------- first implementation here error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>`: - --> $DIR/unpin_conflict.rs:22:1 + --> $DIR/unpin_conflict.rs:20:1 | -22 | #[pin_project] //~ ERROR E0119 +20 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Bar<_, _>` ... -30 | impl Unpin for Bar {} // Non-conditional Unpin impl +28 | impl Unpin for Bar {} // Non-conditional Unpin impl | ------------------------------ first implementation here error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>`: - --> $DIR/unpin_conflict.rs:32:1 + --> $DIR/unpin_conflict.rs:30:1 | -32 | #[pin_project] //~ ERROR E0119 +30 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Baz<_, _>` ... -40 | impl Unpin for Baz {} // Conditional Unpin impl +38 | impl Unpin for Baz {} // Conditional Unpin impl | -------------------------------------------- first implementation here error: aborting due to 3 previous errors diff --git a/tests/ui/pin_project/unpin_sneaky.rs b/tests/ui/pin_project/unpin_sneaky.rs index 732e6fb3..ba06fc61 100644 --- a/tests/ui/pin_project/unpin_sneaky.rs +++ b/tests/ui/pin_project/unpin_sneaky.rs @@ -1,11 +1,13 @@ +// compile-fail + use pin_project::pin_project; #[pin_project] struct Foo { #[pin] - inner: u8 + inner: u8, } -impl Unpin for __UnpinStructFoo {} +impl Unpin for __UnpinStructFoo {} //~ ERROR E0412,E0321 fn main() {} diff --git a/tests/ui/pin_project/unpin_sneaky.stderr b/tests/ui/pin_project/unpin_sneaky.stderr index 3507ada8..292c9133 100644 --- a/tests/ui/pin_project/unpin_sneaky.stderr +++ b/tests/ui/pin_project/unpin_sneaky.stderr @@ -1,18 +1,18 @@ error[E0412]: cannot find type `__UnpinStructFoo` in this scope - --> $DIR/unpin_sneaky.rs:9:16 - | -9 | impl Unpin for __UnpinStructFoo {} - | ^^^^^^^^^^^^^^^^ not found in this scope + --> $DIR/unpin_sneaky.rs:11:16 + | +11 | impl Unpin for __UnpinStructFoo {} //~ ERROR E0412,E0321 + | ^^^^^^^^^^^^^^^^ not found in this scope help: possible candidate is found in another module, you can import it into scope - | -1 | use crate::__UnpinStructFoo; - | + | +3 | use crate::__UnpinStructFoo; + | 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:9:1 - | -9 | impl Unpin for __UnpinStructFoo {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type + --> $DIR/unpin_sneaky.rs:11:1 + | +11 | impl Unpin for __UnpinStructFoo {} //~ ERROR E0412,E0321 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type error: aborting due to 2 previous errors diff --git a/tests/ui/pin_project/unsupported.rs b/tests/ui/pin_project/unsupported.rs index b5b4a17e..f73342d4 100644 --- a/tests/ui/pin_project/unsupported.rs +++ b/tests/ui/pin_project/unsupported.rs @@ -1,29 +1,27 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::pin_project; #[pin_project] -struct Struct1 {} //~ ERROR cannot be implemented for structs with zero fields +struct Struct1 {} //~ ERROR may not be used on structs with zero fields #[pin_project] -struct Struct2(); //~ ERROR cannot be implemented for structs with zero fields +struct Struct2(); //~ ERROR may not be used on structs with zero fields #[pin_project] -struct Struct3; //~ ERROR cannot be implemented for structs with units +struct Struct3; //~ ERROR may not be used on structs with units #[pin_project] -enum Enum1 {} //~ ERROR cannot be implemented for enums without variants +enum Enum1 {} //~ ERROR may not be used on enums without variants #[pin_project] enum Enum2 { - A = 2, //~ ERROR cannot be implemented for enums with discriminants + A = 2, //~ ERROR may not be used on enums with discriminants } #[pin_project] enum Enum1 { - A, //~ ERROR cannot be implemented for enums that have no field + A, //~ ERROR may not be used on enums that have no field B, } diff --git a/tests/ui/pin_project/unsupported.stderr b/tests/ui/pin_project/unsupported.stderr index cd2d8428..02442b4e 100644 --- a/tests/ui/pin_project/unsupported.stderr +++ b/tests/ui/pin_project/unsupported.stderr @@ -1,38 +1,38 @@ -error: cannot be implemented for structs with zero fields - --> $DIR/unsupported.rs:8:16 +error: #[pin_project] attribute may not be used on structs with zero fields + --> $DIR/unsupported.rs:6:16 | -8 | struct Struct1 {} //~ ERROR cannot be implemented for structs with zero fields +6 | struct Struct1 {} //~ ERROR may not be used on structs with zero fields | ^^ -error: cannot be implemented for structs with zero fields - --> $DIR/unsupported.rs:11:15 - | -11 | struct Struct2(); //~ ERROR cannot be implemented for structs with zero fields - | ^^ +error: #[pin_project] attribute may not be used on structs with zero fields + --> $DIR/unsupported.rs:9:15 + | +9 | struct Struct2(); //~ ERROR may not be used on structs with zero fields + | ^^ -error: cannot be implemented for structs with units - --> $DIR/unsupported.rs:14:1 +error: #[pin_project] attribute may not be used on structs with units + --> $DIR/unsupported.rs:12:1 | -14 | struct Struct3; //~ ERROR cannot be implemented for structs with units +12 | struct Struct3; //~ ERROR may not be used on structs with units | ^^^^^^^^^^^^^^^ -error: cannot be implemented for enums without variants - --> $DIR/unsupported.rs:17:1 +error: #[pin_project] attribute may not be used on enums without variants + --> $DIR/unsupported.rs:15:1 | -17 | enum Enum1 {} //~ ERROR cannot be implemented for enums without variants +15 | enum Enum1 {} //~ ERROR may not be used on enums without variants | ^^^^^^^^^^^^^ -error: cannot be implemented for enums with discriminants - --> $DIR/unsupported.rs:21:9 +error: #[pin_project] attribute may not be used on enums with discriminants + --> $DIR/unsupported.rs:19:9 | -21 | A = 2, //~ ERROR cannot be implemented for enums with discriminants +19 | A = 2, //~ ERROR may not be used on enums with discriminants | ^ -error: cannot be implemented for enums that have no field - --> $DIR/unsupported.rs:26:5 +error: #[pin_project] attribute may not be used on enums that have no field + --> $DIR/unsupported.rs:24:5 | -26 | / A, //~ ERROR cannot be implemented for enums that have no field -27 | | B, +24 | / A, //~ ERROR may not be used on enums that have no field +25 | | B, | |______^ error: aborting due to 6 previous errors diff --git a/tests/ui/pinned_drop/forget-pinned-drop.rs b/tests/ui/pinned_drop/forget-pinned-drop.rs index d6a86cb7..75990a89 100644 --- a/tests/ui/pinned_drop/forget-pinned-drop.rs +++ b/tests/ui/pinned_drop/forget-pinned-drop.rs @@ -1,15 +1,12 @@ // compile-fail -#![deny(warnings, unsafe_code)] - -use core::pin::Pin; use pin_project::{pin_project, pinned_drop}; +use std::pin::Pin; -#[pin_project(PinnedDrop)] -pub struct Foo<'a> { - was_dropped: &'a mut bool, +#[pin_project(PinnedDrop)] //~ ERROR E0277 +pub struct Foo { #[pin] - field_2: u8, + field: u8, } fn main() {} diff --git a/tests/ui/pinned_drop/forget-pinned-drop.stderr b/tests/ui/pinned_drop/forget-pinned-drop.stderr index 8c894a46..e010f63f 100644 --- a/tests/ui/pinned_drop/forget-pinned-drop.stderr +++ b/tests/ui/pinned_drop/forget-pinned-drop.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `Foo<'a>: pin_project::__private::UnsafePinnedDrop` is not satisfied - --> $DIR/forget-pinned-drop.rs:8:15 +error[E0277]: the trait bound `Foo: pin_project::__private::UnsafePinnedDrop` is not satisfied + --> $DIR/forget-pinned-drop.rs:6:15 | -8 | #[pin_project(PinnedDrop)] - | ^^^^^^^^^^ the trait `pin_project::__private::UnsafePinnedDrop` is not implemented for `Foo<'a>` +6 | #[pin_project(PinnedDrop)] //~ ERROR E0277 + | ^^^^^^^^^^ the trait `pin_project::__private::UnsafePinnedDrop` is not implemented for `Foo` | = note: required by `pin_project::__private::UnsafePinnedDrop::pinned_drop` diff --git a/tests/ui/pinned_drop/invalid.rs b/tests/ui/pinned_drop/invalid.rs index d7ec7a92..9e04c390 100644 --- a/tests/ui/pinned_drop/invalid.rs +++ b/tests/ui/pinned_drop/invalid.rs @@ -1,28 +1,24 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[pin_project] -pub struct Foo<'a> { - was_dropped: &'a mut bool, +pub struct Foo { #[pin] - field_2: u8, + field: u8, } #[pinned_drop(foo)] //~ ERROR unexpected token -fn do_drop(_foo: Pin<&mut Foo<'_>>) {} +fn do_drop(_x: Pin<&mut Foo>) {} #[pin_project] -pub struct Bar<'a> { - was_dropped: &'a mut bool, +pub struct Bar { #[pin] - field_2: u8, + field: u8, } #[pinned_drop] -fn do_drop(_bar: &mut Bar<'_>) {} //~ ERROR #[pinned_drop] function must take a argument `Pin<&mut Type>` +fn do_drop(_x: &mut Bar) {} //~ ERROR #[pinned_drop] function must take a argument `Pin<&mut Type>` fn main() {} diff --git a/tests/ui/pinned_drop/invalid.stderr b/tests/ui/pinned_drop/invalid.stderr index 212c044d..b823ea3e 100644 --- a/tests/ui/pinned_drop/invalid.stderr +++ b/tests/ui/pinned_drop/invalid.stderr @@ -1,14 +1,14 @@ error: unexpected token - --> $DIR/invalid.rs:15:15 + --> $DIR/invalid.rs:12:15 | -15 | #[pinned_drop(foo)] //~ ERROR unexpected token +12 | #[pinned_drop(foo)] //~ ERROR unexpected token | ^^^ error: #[pinned_drop] function must take a argument `Pin<&mut Type>` - --> $DIR/invalid.rs:26:12 + --> $DIR/invalid.rs:22:12 | -26 | fn do_drop(_bar: &mut Bar<'_>) {} //~ ERROR #[pinned_drop] function must take a argument `Pin<&mut Type>` - | ^^^^^^^^^^^^^^^^^^ +22 | fn do_drop(_x: &mut Bar) {} //~ ERROR #[pinned_drop] function must take a argument `Pin<&mut Type>` + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/pinned_drop/return-type.rs b/tests/ui/pinned_drop/return-type.rs index 0bb41acc..94490585 100644 --- a/tests/ui/pinned_drop/return-type.rs +++ b/tests/ui/pinned_drop/return-type.rs @@ -1,35 +1,33 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[pin_project] -pub struct Foo<'a> { - was_dropped: &'a mut bool, +pub struct A { #[pin] - field_2: u8, + field: u8, } #[pinned_drop] -fn do_drop(foo: Pin<&mut Foo<'_>>) -> bool { - //~ ERROR #[pinned_drop] function must return the unit type - **foo.project().was_dropped = true; - true -} +fn do_drop(_x: Pin<&mut A>) -> bool {} //~ ERROR #[pinned_drop] function must return the unit type #[pin_project] -pub struct Bar<'a> { - was_dropped: &'a mut bool, +pub struct B { #[pin] - field_2: u8, + field: u8, } -// OK #[pinned_drop] -fn do_drop(foo: Pin<&mut Bar<'_>>) -> () { - **foo.project().was_dropped = true; +fn do_drop(_x: Pin<&mut B>) -> ((),) {} //~ ERROR #[pinned_drop] function must return the unit type + +#[pin_project] +pub struct C { + #[pin] + field: u8, } +#[pinned_drop] +fn do_drop(_x: Pin<&mut C>) -> () {} // OK + fn main() {} diff --git a/tests/ui/pinned_drop/return-type.stderr b/tests/ui/pinned_drop/return-type.stderr index 8a44eb5b..f5e425da 100644 --- a/tests/ui/pinned_drop/return-type.stderr +++ b/tests/ui/pinned_drop/return-type.stderr @@ -1,8 +1,14 @@ error: #[pinned_drop] function must return the unit type - --> $DIR/return-type.rs:16:39 + --> $DIR/return-type.rs:13:32 | -16 | fn do_drop(foo: Pin<&mut Foo<'_>>) -> bool { - | ^^^^ +13 | fn do_drop(_x: Pin<&mut A>) -> bool {} //~ ERROR #[pinned_drop] function must return the unit type + | ^^^^ -error: aborting due to previous error +error: #[pinned_drop] function must return the unit type + --> $DIR/return-type.rs:22:32 + | +22 | fn do_drop(_x: Pin<&mut B>) -> ((),) {} //~ ERROR #[pinned_drop] function must return the unit type + | ^^^^^ + +error: aborting due to 2 previous errors diff --git a/tests/ui/project/ambiguous-let.rs b/tests/ui/project/ambiguous-let.rs index b35c1ec7..1f83ac47 100644 --- a/tests/ui/project/ambiguous-let.rs +++ b/tests/ui/project/ambiguous-let.rs @@ -1,7 +1,5 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::{pin_project, project}; use std::pin::Pin; @@ -20,6 +18,7 @@ fn foo() { #[project] let Struct(x) = match 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!(), }; diff --git a/tests/ui/project/ambiguous-let.stderr b/tests/ui/project/ambiguous-let.stderr index a7d5427d..3c493b0e 100644 --- a/tests/ui/project/ambiguous-let.stderr +++ b/tests/ui/project/ambiguous-let.stderr @@ -1,13 +1,13 @@ 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:22:9 + --> $DIR/ambiguous-let.rs:20:9 | -22 | let Struct(x) = match foo.project() { +20 | let Struct(x) = match foo.project() { | ^^^^^^^^^ error[E0425]: cannot find value `x` in this scope - --> $DIR/ambiguous-let.rs:26:13 + --> $DIR/ambiguous-let.rs:25:13 | -26 | assert!(x); +25 | assert!(x); | ^ not found in this scope error: aborting due to 2 previous errors diff --git a/tests/ui/project/invalid.rs b/tests/ui/project/invalid.rs index ea20a55d..d10f27dc 100644 --- a/tests/ui/project/invalid.rs +++ b/tests/ui/project/invalid.rs @@ -1,7 +1,5 @@ // compile-fail -#![deny(warnings, unsafe_code)] - use pin_project::{pin_project, project}; #[pin_project] diff --git a/tests/ui/project/invalid.stderr b/tests/ui/project/invalid.stderr index 059c884a..b84068b2 100644 --- a/tests/ui/project/invalid.stderr +++ b/tests/ui/project/invalid.stderr @@ -1,7 +1,7 @@ error: unexpected token - --> $DIR/invalid.rs:16:14 + --> $DIR/invalid.rs:14:14 | -16 | #[project(foo)] //~ ERROR unexpected token +14 | #[project(foo)] //~ ERROR unexpected token | ^ error: aborting due to previous error diff --git a/tests/ui/project/type-mismatch.rs b/tests/ui/project/type-mismatch.rs index 8680cf5f..a0951fd9 100644 --- a/tests/ui/project/type-mismatch.rs +++ b/tests/ui/project/type-mismatch.rs @@ -1,6 +1,5 @@ // compile-fail -#![deny(warnings, unsafe_code)] #![feature(proc_macro_hygiene, stmt_expr_attributes)] use pin_project::{pin_project, project}; diff --git a/tests/ui/project/type-mismatch.stderr b/tests/ui/project/type-mismatch.stderr index 4558d91b..04efebff 100644 --- a/tests/ui/project/type-mismatch.stderr +++ b/tests/ui/project/type-mismatch.stderr @@ -1,7 +1,7 @@ error[E0308]: mismatched types - --> $DIR/type-mismatch.rs:41:9 + --> $DIR/type-mismatch.rs:40:9 | -41 | None => {} //~ ERROR mismatched types +40 | None => {} //~ ERROR mismatched types | ^^^^ expected enum `span::__BazProjection`, found enum `std::option::Option` | = note: expected type `span::__BazProjection<'_, {integer}, {integer}, _, _>`