From cbfaae45270de20906567aaeaf1edea7b49788fc Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 3 Jun 2020 13:22:04 +0900 Subject: [PATCH] Cleanup tests * Reduced duplicate code. * Fixed warnings in generated code. * Added tests/no-std to main workspace members. --- .github/workflows/ci.yml | 1 + Cargo.toml | 3 +- ci.sh | 6 +- compiletest.sh | 1 - examples/enum-default-expanded.rs | 9 +- examples/not_unpin-expanded.rs | 9 +- examples/pinned_drop-expanded.rs | 9 +- examples/project_replace-expanded.rs | 11 +- examples/struct-default-expanded.rs | 9 +- examples/unsafe_unpin-expanded.rs | 9 +- .../src/pin_project/derive.rs | 9 +- .../tests/expand/default-enum.expanded.rs | 5 +- .../tests/expand/default-struct.expanded.rs | 5 +- .../expand/default-tuple_struct.expanded.rs | 5 +- .../tests/expand/naming-enum.expanded.rs | 5 +- .../tests/expand/naming-struct.expanded.rs | 5 +- .../expand/naming-tuple_struct.expanded.rs | 5 +- .../tests/expand/not_unpin-enum.expanded.rs | 5 +- .../tests/expand/not_unpin-struct.expanded.rs | 5 +- .../expand/not_unpin-tuple_struct.expanded.rs | 5 +- .../tests/expand/pinned_drop-enum.expanded.rs | 5 +- .../expand/pinned_drop-struct.expanded.rs | 5 +- .../pinned_drop-tuple_struct.expanded.rs | 5 +- .../expand/project_replace-enum.expanded.rs | 5 +- .../expand/project_replace-struct.expanded.rs | 5 +- .../project_replace-tuple_struct.expanded.rs | 5 +- .../expand/tests/expand/pub-enum.expanded.rs | 5 +- .../tests/expand/pub-struct.expanded.rs | 5 +- .../tests/expand/pub-tuple_struct.expanded.rs | 5 +- .../expand/unsafe_unpin-enum.expanded.rs | 5 +- .../expand/unsafe_unpin-struct.expanded.rs | 5 +- .../unsafe_unpin-tuple_struct.expanded.rs | 5 +- tests/forbid_unsafe.rs | 108 --------------- .../{lints.rs => include/basic-safe-part.rs} | 127 +++++++++--------- tests/include/basic.rs | 5 + tests/lint.rs | 89 ++++++++++++ tests/no-std/Cargo.toml | 2 - tests/no-std/lib.rs | 99 +------------- tests/overwriting_core_crate.rs | 106 +-------------- tests/project_if_attr.rs.in | 5 +- tests/rust-2015/Cargo.toml | 3 + tests/rust-2015/lib.rs | 12 ++ tests/rust-2015/tests/no-std.rs | 105 --------------- tests/rust-2015/tests/std.rs | 103 +------------- tests/ui/auxiliary/Cargo.toml | 1 - 45 files changed, 318 insertions(+), 628 deletions(-) delete mode 100644 tests/forbid_unsafe.rs rename tests/{lints.rs => include/basic-safe-part.rs} (50%) create mode 100644 tests/include/basic.rs create mode 100644 tests/lint.rs create mode 100644 tests/rust-2015/lib.rs delete mode 100644 tests/rust-2015/tests/no-std.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94d14b36..086ef611 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,7 @@ jobs: if: matrix.rust == 'nightly' run: | cargo check --target thumbv7m-none-eabi --manifest-path tests/no-std/Cargo.toml + cargo check --target thumbv7m-none-eabi --manifest-path tests/rust-2015/Cargo.toml - name: cargo check (minimal versions) if: matrix.rust == 'nightly' run: | diff --git a/Cargo.toml b/Cargo.toml index a7bb174b..92a530cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,8 @@ members = [ "tests/ui/auxiliary", "tests/doc", "tests/expand", - "tests/rust-2015" + "tests/no-std", + "tests/rust-2015", ] [dependencies] diff --git a/ci.sh b/ci.sh index df0131ef..179e2967 100644 --- a/ci.sh +++ b/ci.sh @@ -8,14 +8,14 @@ # . ./ci.sh # ``` -echo "Running 'cargo fmt -- --check'" -cargo +nightly fmt --all -- --check +echo "Running 'cargo fmt'" +cargo +nightly fmt --all echo "Running 'cargo clippy'" cargo +nightly clippy --all --all-features --all-targets echo "Running 'cargo test'" -cargo +nightly test --all --all-features +cargo +nightly test --all --all-features --exclude expandtest echo "Running 'cargo doc'" cargo +nightly doc --no-deps --all --all-features diff --git a/compiletest.sh b/compiletest.sh index 9af5a5fc..2ff92c38 100644 --- a/compiletest.sh +++ b/compiletest.sh @@ -9,4 +9,3 @@ # ``` TRYBUILD=overwrite cargo +nightly test -p pin-project --all-features --test compiletest -- --ignored -# cargo +nightly test -p pin-project --all-features --test compiletest -- --ignored diff --git a/examples/enum-default-expanded.rs b/examples/enum-default-expanded.rs index bc33ecb5..cc158dc4 100644 --- a/examples/enum-default-expanded.rs +++ b/examples/enum-default-expanded.rs @@ -24,9 +24,10 @@ enum Enum { Unpinned(U), } -#[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] enum EnumProj<'pin, T, U> where Enum: 'pin, @@ -35,8 +36,9 @@ where Unpinned(&'pin mut (U)), } #[doc(hidden)] -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjectionRef<'pin, T, U> where Enum: 'pin, @@ -48,6 +50,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { fn project<'pin>( diff --git a/examples/not_unpin-expanded.rs b/examples/not_unpin-expanded.rs index a8bdd558..e7a1c648 100644 --- a/examples/not_unpin-expanded.rs +++ b/examples/not_unpin-expanded.rs @@ -30,9 +30,10 @@ pub struct Struct { } #[doc(hidden)] -#[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -41,8 +42,9 @@ where unpinned: &'pin mut (U), } #[doc(hidden)] -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -54,6 +56,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { pub(crate) fn project<'pin>( diff --git a/examples/pinned_drop-expanded.rs b/examples/pinned_drop-expanded.rs index 974eab76..0700f828 100644 --- a/examples/pinned_drop-expanded.rs +++ b/examples/pinned_drop-expanded.rs @@ -34,9 +34,10 @@ pub struct Struct<'a, T> { } #[doc(hidden)] -#[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjection<'pin, 'a, T> where Struct<'a, T>: 'pin, @@ -45,8 +46,9 @@ where field: ::pin_project::__private::Pin<&'pin mut (T)>, } #[doc(hidden)] -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjectionRef<'pin, 'a, T> where Struct<'a, T>: 'pin, @@ -58,6 +60,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl<'a, T> Struct<'a, T> { pub(crate) fn project<'pin>( diff --git a/examples/project_replace-expanded.rs b/examples/project_replace-expanded.rs index 18f85878..a482a11c 100644 --- a/examples/project_replace-expanded.rs +++ b/examples/project_replace-expanded.rs @@ -27,9 +27,10 @@ struct Struct { } #[doc(hidden)] -#[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -38,8 +39,9 @@ where unpinned: &'pin mut (U), } #[doc(hidden)] -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -49,7 +51,7 @@ where } #[doc(hidden)] -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] struct __StructProjectionOwned { pinned: ::pin_project::__private::PhantomData, @@ -59,6 +61,7 @@ struct __StructProjectionOwned { #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>( diff --git a/examples/struct-default-expanded.rs b/examples/struct-default-expanded.rs index 26331eec..5832ab63 100644 --- a/examples/struct-default-expanded.rs +++ b/examples/struct-default-expanded.rs @@ -27,9 +27,10 @@ struct Struct { } #[doc(hidden)] -#[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -38,8 +39,9 @@ where unpinned: &'pin mut (U), } #[doc(hidden)] -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -51,6 +53,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>( diff --git a/examples/unsafe_unpin-expanded.rs b/examples/unsafe_unpin-expanded.rs index e2841f6b..16e38b30 100644 --- a/examples/unsafe_unpin-expanded.rs +++ b/examples/unsafe_unpin-expanded.rs @@ -29,9 +29,10 @@ pub struct Struct { } #[doc(hidden)] -#[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -40,8 +41,9 @@ where unpinned: &'pin mut (U), } #[doc(hidden)] -#[allow(dead_code)] // This lint warns unused fields/variants. +#[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -53,6 +55,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { pub(crate) fn project<'pin>( diff --git a/pin-project-internal/src/pin_project/derive.rs b/pin-project-internal/src/pin_project/derive.rs index 08065031..2fa2131a 100644 --- a/pin-project-internal/src/pin_project/derive.rs +++ b/pin-project-internal/src/pin_project/derive.rs @@ -59,6 +59,7 @@ pub(super) fn parse_derive(input: TokenStream) -> Result { #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::used_underscore_binding)] const #dummy_const: () = { #scoped_items #unpin_impl @@ -451,13 +452,15 @@ impl<'a> Context<'a> { let doc_proj_own = if self.project_replace { None } else { Some(&doc_attr) }; let mut proj_items = quote! { #doc_proj - #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. #[allow(dead_code)] // This lint warns unused fields/variants. #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 #vis struct #proj_ident #proj_generics #where_clause_fields #doc_proj_ref #[allow(dead_code)] // This lint warns unused fields/variants. #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 #vis struct #proj_ref_ident #proj_generics #where_clause_ref_fields }; if self.replace.is_some() { @@ -540,15 +543,17 @@ impl<'a> Context<'a> { let doc_proj_own = if self.project_replace { None } else { Some(&doc_attr) }; let mut proj_items = quote! { #doc_proj - #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. #[allow(dead_code)] // This lint warns unused fields/variants. #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 #vis enum #proj_ident #proj_generics #where_clause { #proj_variants } #doc_proj_ref #[allow(dead_code)] // This lint warns unused fields/variants. #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 #vis enum #proj_ref_ident #proj_generics #where_clause { #proj_ref_variants } diff --git a/tests/expand/tests/expand/default-enum.expanded.rs b/tests/expand/tests/expand/default-enum.expanded.rs index 9dee2479..315ed29e 100644 --- a/tests/expand/tests/expand/default-enum.expanded.rs +++ b/tests/expand/tests/expand/default-enum.expanded.rs @@ -10,9 +10,10 @@ enum Enum { Unit, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjection<'pin, T, U> where Enum: 'pin, @@ -27,6 +28,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjectionRef<'pin, T, U> where Enum: 'pin, @@ -41,6 +43,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { fn project<'pin>( diff --git a/tests/expand/tests/expand/default-struct.expanded.rs b/tests/expand/tests/expand/default-struct.expanded.rs index b5ddf91d..233dd23c 100644 --- a/tests/expand/tests/expand/default-struct.expanded.rs +++ b/tests/expand/tests/expand/default-struct.expanded.rs @@ -6,9 +6,10 @@ struct Struct { unpinned: U, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -19,6 +20,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -29,6 +31,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>( diff --git a/tests/expand/tests/expand/default-tuple_struct.expanded.rs b/tests/expand/tests/expand/default-tuple_struct.expanded.rs index 545f6e4c..228566f0 100644 --- a/tests/expand/tests/expand/default-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/default-tuple_struct.expanded.rs @@ -2,9 +2,10 @@ use pin_project::pin_project; #[pin(__private())] struct TupleStruct(#[pin] T, U); #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -14,12 +15,14 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjectionRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) where TupleStruct: 'pin; #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_TupleStruct: () = { impl TupleStruct { fn project<'pin>( diff --git a/tests/expand/tests/expand/naming-enum.expanded.rs b/tests/expand/tests/expand/naming-enum.expanded.rs index b0f6bd92..d9bcb85f 100644 --- a/tests/expand/tests/expand/naming-enum.expanded.rs +++ b/tests/expand/tests/expand/naming-enum.expanded.rs @@ -9,9 +9,10 @@ enum Enum { Tuple(#[pin] T, U), Unit, } -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] enum Proj<'pin, T, U> where Enum: 'pin, @@ -25,6 +26,7 @@ where } #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] enum ProjRef<'pin, T, U> where Enum: 'pin, @@ -49,6 +51,7 @@ enum ProjOwn { #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { diff --git a/tests/expand/tests/expand/naming-struct.expanded.rs b/tests/expand/tests/expand/naming-struct.expanded.rs index af373d8f..73f09da7 100644 --- a/tests/expand/tests/expand/naming-struct.expanded.rs +++ b/tests/expand/tests/expand/naming-struct.expanded.rs @@ -5,9 +5,10 @@ struct Struct { pinned: T, unpinned: U, } -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct Proj<'pin, T, U> where Struct: 'pin, @@ -17,6 +18,7 @@ where } #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct ProjRef<'pin, T, U> where Struct: 'pin, @@ -33,6 +35,7 @@ struct ProjOwn { #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { diff --git a/tests/expand/tests/expand/naming-tuple_struct.expanded.rs b/tests/expand/tests/expand/naming-tuple_struct.expanded.rs index e9e66a73..390b9cc7 100644 --- a/tests/expand/tests/expand/naming-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/naming-tuple_struct.expanded.rs @@ -1,14 +1,16 @@ use pin_project::pin_project; # [ pin ( __private ( Replace , project = Proj , project_ref = ProjRef , project_replace = ProjOwn ) ) ] struct TupleStruct(#[pin] T, U); -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct Proj<'pin, T, U>(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)) where TupleStruct: 'pin; #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct ProjRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) where TupleStruct: 'pin; @@ -18,6 +20,7 @@ struct ProjOwn(::pin_project::__private::PhantomData, U); #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_TupleStruct: () = { impl TupleStruct { fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { diff --git a/tests/expand/tests/expand/not_unpin-enum.expanded.rs b/tests/expand/tests/expand/not_unpin-enum.expanded.rs index 6a89d2c5..96798221 100644 --- a/tests/expand/tests/expand/not_unpin-enum.expanded.rs +++ b/tests/expand/tests/expand/not_unpin-enum.expanded.rs @@ -10,9 +10,10 @@ enum Enum { Unit, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjection<'pin, T, U> where Enum: 'pin, @@ -27,6 +28,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjectionRef<'pin, T, U> where Enum: 'pin, @@ -41,6 +43,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { fn project<'pin>( diff --git a/tests/expand/tests/expand/not_unpin-struct.expanded.rs b/tests/expand/tests/expand/not_unpin-struct.expanded.rs index 9a6dd73e..4c122661 100644 --- a/tests/expand/tests/expand/not_unpin-struct.expanded.rs +++ b/tests/expand/tests/expand/not_unpin-struct.expanded.rs @@ -6,9 +6,10 @@ struct Struct { unpinned: U, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -19,6 +20,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -29,6 +31,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>( diff --git a/tests/expand/tests/expand/not_unpin-tuple_struct.expanded.rs b/tests/expand/tests/expand/not_unpin-tuple_struct.expanded.rs index aa094a0e..930498f4 100644 --- a/tests/expand/tests/expand/not_unpin-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/not_unpin-tuple_struct.expanded.rs @@ -2,9 +2,10 @@ use pin_project::pin_project; # [ pin ( __private ( ! Unpin ) ) ] struct TupleStruct(#[pin] T, U); #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -14,12 +15,14 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjectionRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) where TupleStruct: 'pin; #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_TupleStruct: () = { impl TupleStruct { fn project<'pin>( diff --git a/tests/expand/tests/expand/pinned_drop-enum.expanded.rs b/tests/expand/tests/expand/pinned_drop-enum.expanded.rs index f68a2e1d..acbaf16a 100644 --- a/tests/expand/tests/expand/pinned_drop-enum.expanded.rs +++ b/tests/expand/tests/expand/pinned_drop-enum.expanded.rs @@ -11,9 +11,10 @@ enum Enum { Unit, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjection<'pin, T, U> where Enum: 'pin, @@ -28,6 +29,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjectionRef<'pin, T, U> where Enum: 'pin, @@ -42,6 +44,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { fn project<'pin>( diff --git a/tests/expand/tests/expand/pinned_drop-struct.expanded.rs b/tests/expand/tests/expand/pinned_drop-struct.expanded.rs index 14657c84..8cb37371 100644 --- a/tests/expand/tests/expand/pinned_drop-struct.expanded.rs +++ b/tests/expand/tests/expand/pinned_drop-struct.expanded.rs @@ -7,9 +7,10 @@ struct Struct { unpinned: U, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -20,6 +21,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -30,6 +32,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>( diff --git a/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs b/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs index bbf6451c..64a446e8 100644 --- a/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs @@ -3,9 +3,10 @@ use std::pin::Pin; #[pin(__private(PinnedDrop))] struct TupleStruct(#[pin] T, U); #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -15,12 +16,14 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjectionRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) where TupleStruct: 'pin; #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_TupleStruct: () = { impl TupleStruct { fn project<'pin>( diff --git a/tests/expand/tests/expand/project_replace-enum.expanded.rs b/tests/expand/tests/expand/project_replace-enum.expanded.rs index 9040f530..71c77c8b 100644 --- a/tests/expand/tests/expand/project_replace-enum.expanded.rs +++ b/tests/expand/tests/expand/project_replace-enum.expanded.rs @@ -10,9 +10,10 @@ enum Enum { Unit, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjection<'pin, T, U> where Enum: 'pin, @@ -27,6 +28,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjectionRef<'pin, T, U> where Enum: 'pin, @@ -52,6 +54,7 @@ enum __EnumProjectionOwned { #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { fn project<'pin>( diff --git a/tests/expand/tests/expand/project_replace-struct.expanded.rs b/tests/expand/tests/expand/project_replace-struct.expanded.rs index 2b9f5113..08b38a06 100644 --- a/tests/expand/tests/expand/project_replace-struct.expanded.rs +++ b/tests/expand/tests/expand/project_replace-struct.expanded.rs @@ -6,9 +6,10 @@ struct Struct { unpinned: U, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -19,6 +20,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -36,6 +38,7 @@ struct __StructProjectionOwned { #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>( diff --git a/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs b/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs index a11392df..0741d073 100644 --- a/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs @@ -2,9 +2,10 @@ use pin_project::pin_project; #[pin(__private(Replace))] struct TupleStruct(#[pin] T, U); #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -14,6 +15,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjectionRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) where TupleStruct: 'pin; @@ -24,6 +26,7 @@ struct __TupleStructProjectionOwned(::pin_project::__private::PhantomData< #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_TupleStruct: () = { impl TupleStruct { fn project<'pin>( diff --git a/tests/expand/tests/expand/pub-enum.expanded.rs b/tests/expand/tests/expand/pub-enum.expanded.rs index 6d3a9ebb..a6d44351 100644 --- a/tests/expand/tests/expand/pub-enum.expanded.rs +++ b/tests/expand/tests/expand/pub-enum.expanded.rs @@ -10,9 +10,10 @@ pub enum Enum { Unit, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) enum __EnumProjection<'pin, T, U> where Enum: 'pin, @@ -27,6 +28,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) enum __EnumProjectionRef<'pin, T, U> where Enum: 'pin, @@ -41,6 +43,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { pub(crate) fn project<'pin>( diff --git a/tests/expand/tests/expand/pub-struct.expanded.rs b/tests/expand/tests/expand/pub-struct.expanded.rs index 92c03f42..73082512 100644 --- a/tests/expand/tests/expand/pub-struct.expanded.rs +++ b/tests/expand/tests/expand/pub-struct.expanded.rs @@ -6,9 +6,10 @@ pub struct Struct { pub unpinned: U, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -19,6 +20,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -29,6 +31,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { pub(crate) fn project<'pin>( diff --git a/tests/expand/tests/expand/pub-tuple_struct.expanded.rs b/tests/expand/tests/expand/pub-tuple_struct.expanded.rs index d4d25cc9..c2fcf465 100644 --- a/tests/expand/tests/expand/pub-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/pub-tuple_struct.expanded.rs @@ -2,9 +2,10 @@ use pin_project::pin_project; #[pin(__private())] pub struct TupleStruct(#[pin] pub T, pub U); #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __TupleStructProjection<'pin, T, U>( pub ::pin_project::__private::Pin<&'pin mut (T)>, pub &'pin mut (U), @@ -14,6 +15,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] pub(crate) struct __TupleStructProjectionRef<'pin, T, U>( pub ::pin_project::__private::Pin<&'pin (T)>, pub &'pin (U), @@ -23,6 +25,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_TupleStruct: () = { impl TupleStruct { pub(crate) fn project<'pin>( diff --git a/tests/expand/tests/expand/unsafe_unpin-enum.expanded.rs b/tests/expand/tests/expand/unsafe_unpin-enum.expanded.rs index e490a746..3d4da18b 100644 --- a/tests/expand/tests/expand/unsafe_unpin-enum.expanded.rs +++ b/tests/expand/tests/expand/unsafe_unpin-enum.expanded.rs @@ -10,9 +10,10 @@ enum Enum { Unit, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjection<'pin, T, U> where Enum: 'pin, @@ -27,6 +28,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] enum __EnumProjectionRef<'pin, T, U> where Enum: 'pin, @@ -41,6 +43,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Enum: () = { impl Enum { fn project<'pin>( diff --git a/tests/expand/tests/expand/unsafe_unpin-struct.expanded.rs b/tests/expand/tests/expand/unsafe_unpin-struct.expanded.rs index fd50ee4e..23e67cac 100644 --- a/tests/expand/tests/expand/unsafe_unpin-struct.expanded.rs +++ b/tests/expand/tests/expand/unsafe_unpin-struct.expanded.rs @@ -6,9 +6,10 @@ struct Struct { unpinned: U, } #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -19,6 +20,7 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -29,6 +31,7 @@ where #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_Struct: () = { impl Struct { fn project<'pin>( diff --git a/tests/expand/tests/expand/unsafe_unpin-tuple_struct.expanded.rs b/tests/expand/tests/expand/unsafe_unpin-tuple_struct.expanded.rs index 4560ad06..1c55d8d6 100644 --- a/tests/expand/tests/expand/unsafe_unpin-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/unsafe_unpin-tuple_struct.expanded.rs @@ -2,9 +2,10 @@ use pin_project::{pin_project, UnsafeUnpin}; #[pin(__private(UnsafeUnpin))] struct TupleStruct(#[pin] T, U); #[doc(hidden)] -#[allow(clippy::mut_mut)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -14,12 +15,14 @@ where #[doc(hidden)] #[allow(dead_code)] #[allow(single_use_lifetimes)] +#[allow(clippy::type_repetition_in_bounds)] struct __TupleStructProjectionRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) where TupleStruct: 'pin; #[doc(hidden)] #[allow(non_upper_case_globals)] #[allow(single_use_lifetimes)] +#[allow(clippy::used_underscore_binding)] const __SCOPE_TupleStruct: () = { impl TupleStruct { fn project<'pin>( diff --git a/tests/forbid_unsafe.rs b/tests/forbid_unsafe.rs deleted file mode 100644 index 4b2e2482..00000000 --- a/tests/forbid_unsafe.rs +++ /dev/null @@ -1,108 +0,0 @@ -#![forbid(unsafe_code)] -#![warn(rust_2018_idioms, single_use_lifetimes)] -#![allow(dead_code)] - -// default #[pin_project], PinnedDrop, Replace, and !Unpin are completely safe. - -use pin_project::{pin_project, pinned_drop}; -use std::pin::Pin; - -#[pin_project] -pub struct StructDefault { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(PinnedDrop)] -pub struct StructPinnedDrop { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pinned_drop] -impl PinnedDrop for StructPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub struct StructReplace { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -// UnsafeUnpin without UnsafeUnpin impl is also safe -#[pin_project(UnsafeUnpin)] -pub struct StructUnsafeUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(!Unpin)] -pub struct StructNotUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project] -pub enum EnumDefault { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(PinnedDrop)] -pub enum EnumPinnedDrop { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pinned_drop] -impl PinnedDrop for EnumPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub enum EnumReplace { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -// UnsafeUnpin without UnsafeUnpin impl is also safe -#[pin_project(UnsafeUnpin)] -pub enum EnumUnsafeUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(!Unpin)] -pub enum EnumNotUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[test] -fn test() {} diff --git a/tests/lints.rs b/tests/include/basic-safe-part.rs similarity index 50% rename from tests/lints.rs rename to tests/include/basic-safe-part.rs index 4009f55b..d4f9a400 100644 --- a/tests/lints.rs +++ b/tests/include/basic-safe-part.rs @@ -1,126 +1,121 @@ -#![warn(rust_2018_idioms, single_use_lifetimes)] -#![warn(unused, future_incompatible)] -#![warn(clippy::all, clippy::pedantic, clippy::nursery)] - -use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; -use std::pin::Pin; +// default #[pin_project], PinnedDrop, Replace, !Unpin, and UnsafeUnpin without UnsafeUnpin impl are completely safe. #[pin_project] -pub struct StructDefault { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(PinnedDrop)] -pub struct StructPinnedDrop { +pub struct DefaultStruct { #[pin] pub pinned: T, pub unpinned: U, } -#[pinned_drop] -impl PinnedDrop for StructPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} +#[pin_project] +pub struct DefaultTupleStruct(#[pin] pub T, pub U); -#[pin_project(Replace)] -pub struct StructReplace { - #[pin] - pub pinned: T, - pub unpinned: U, +#[pin_project] +pub enum DefaultEnum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, } -#[pin_project(UnsafeUnpin)] -pub struct StructUnsafeUnpin { +#[pin_project(PinnedDrop)] +pub struct PinnedDropStruct { #[pin] pub pinned: T, pub unpinned: U, } -unsafe impl UnsafeUnpin for StructUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub struct StructNotUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, +#[pinned_drop] +impl PinnedDrop for PinnedDropStruct { + fn drop(self: Pin<&mut Self>) {} } -#[pin_project] -pub struct StructMutMut<'a, T, U> { - #[pin] - pub pinned: &'a mut T, - pub unpinned: &'a mut U, -} +#[pin_project(PinnedDrop)] +pub struct PinnedDropTupleStruct(#[pin] pub T, pub U); -#[pin_project] -pub enum EnumDefault { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), +#[pinned_drop] +impl PinnedDrop for PinnedDropTupleStruct { + fn drop(self: Pin<&mut Self>) {} } #[pin_project(PinnedDrop)] -pub enum EnumPinnedDrop { +pub enum PinnedDropEnum { Struct { #[pin] pinned: T, unpinned: U, }, Tuple(#[pin] T, U), + Unit, } #[pinned_drop] -impl PinnedDrop for EnumPinnedDrop { +impl PinnedDrop for PinnedDropEnum { fn drop(self: Pin<&mut Self>) {} } #[pin_project(Replace)] -pub enum EnumReplace { +pub struct ReplaceStruct { + #[pin] + pub pinned: T, + pub unpinned: U, +} + +#[pin_project(Replace)] +pub struct ReplaceTupleStruct(#[pin] pub T, pub U); + +#[pin_project(Replace)] +pub enum ReplaceEnum { Struct { #[pin] pinned: T, unpinned: U, }, Tuple(#[pin] T, U), + Unit, } #[pin_project(UnsafeUnpin)] -pub enum EnumUnsafeUnpin { +pub struct UnsafeUnpinStruct { + #[pin] + pub pinned: T, + pub unpinned: U, +} + +#[pin_project(UnsafeUnpin)] +pub struct UnsafeUnpinTupleStruct(#[pin] pub T, pub U); + +#[pin_project(UnsafeUnpin)] +pub enum UnsafeUnpinEnum { Struct { #[pin] pinned: T, unpinned: U, }, Tuple(#[pin] T, U), + Unit, +} + +#[pin_project(!Unpin)] +pub struct NotUnpinStruct { + #[pin] + pub pinned: T, + pub unpinned: U, } -unsafe impl UnsafeUnpin for EnumUnsafeUnpin {} +#[pin_project(!Unpin)] +pub struct NotUnpinTupleStruct(#[pin] pub T, pub U); #[pin_project(!Unpin)] -pub enum EnumNotUnpin { +pub enum NotUnpinEnum { Struct { #[pin] pinned: T, unpinned: U, }, Tuple(#[pin] T, U), + Unit, } - -#[pin_project] -pub enum EnumMutMut<'a, T, U> { - Struct { - #[pin] - pinned: &'a mut T, - unpinned: &'a mut U, - }, - Tuple(#[pin] T, U), -} - -#[allow(clippy::missing_const_for_fn)] -#[test] -fn test() {} diff --git a/tests/include/basic.rs b/tests/include/basic.rs new file mode 100644 index 00000000..9d473c99 --- /dev/null +++ b/tests/include/basic.rs @@ -0,0 +1,5 @@ +include!("basic-safe-part.rs"); + +unsafe impl UnsafeUnpin for UnsafeUnpinStruct {} +unsafe impl UnsafeUnpin for UnsafeUnpinTupleStruct {} +unsafe impl UnsafeUnpin for UnsafeUnpinEnum {} diff --git a/tests/lint.rs b/tests/lint.rs new file mode 100644 index 00000000..1e71cc1e --- /dev/null +++ b/tests/lint.rs @@ -0,0 +1,89 @@ +#![warn(rust_2018_idioms, single_use_lifetimes)] +#![warn(unused, future_incompatible)] +#![warn(clippy::all, clippy::pedantic, clippy::nursery)] + +pub mod basic { + use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; + use std::pin::Pin; + + include!("include/basic.rs"); +} + +pub mod forbid_unsafe { + #![forbid(unsafe_code)] + + use pin_project::{pin_project, pinned_drop}; + use std::pin::Pin; + + include!("include/basic-safe-part.rs"); +} + +pub mod clippy { + use pin_project::pin_project; + + #[pin_project(Replace)] + pub struct MutMutStruct<'a, T, U> { + #[pin] + pub pinned: &'a mut T, + pub unpinned: &'a mut U, + } + + #[pin_project(Replace)] + pub struct MutMutTupleStruct<'a, T, U>(#[pin] &'a mut T, &'a mut U); + + #[pin_project(Replace)] + pub enum MutMutEnum<'a, T, U> { + Struct { + #[pin] + pinned: &'a mut T, + unpinned: &'a mut U, + }, + Tuple(#[pin] &'a mut T, &'a mut U), + Unit, + } + + #[pin_project(Replace)] + pub struct TypeRepetitionInBoundsStruct + where + Self: Sized, + { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[pin_project(Replace)] + pub struct TypeRepetitionInBoundsTupleStruct(#[pin] T, U) + where + Self: Sized; + + #[pin_project(Replace)] + pub enum TypeRepetitionInBoundsEnum + where + Self: Sized, + { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, + } + + #[pin_project(Replace)] + pub struct UsedUnderscoreBindingStruct { + #[pin] + pub _pinned: T, + pub _unpinned: U, + } + + #[pin_project(Replace)] + pub enum UsedUnderscoreBindingEnum { + Struct { + #[pin] + _pinned: T, + _unpinned: U, + }, + } +} diff --git a/tests/no-std/Cargo.toml b/tests/no-std/Cargo.toml index 59b375ac..1d15b5c5 100644 --- a/tests/no-std/Cargo.toml +++ b/tests/no-std/Cargo.toml @@ -8,7 +8,5 @@ publish = false [lib] path = "lib.rs" -[workspace] - [dependencies] pin-project = { path = "../.." } diff --git a/tests/no-std/lib.rs b/tests/no-std/lib.rs index 4d088563..c36e9eb9 100644 --- a/tests/no-std/lib.rs +++ b/tests/no-std/lib.rs @@ -4,101 +4,4 @@ use core::pin::Pin; use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; -#[pin_project] -pub struct StructDefault { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(PinnedDrop)] -pub struct StructPinnedDrop { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pinned_drop] -impl PinnedDrop for StructPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub struct StructReplace { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(UnsafeUnpin)] -pub struct StructUnsafeUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -unsafe impl UnsafeUnpin for StructUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub struct StructNotUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project] -pub enum EnumDefault { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(PinnedDrop)] -pub enum EnumPinnedDrop { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pinned_drop] -impl PinnedDrop for EnumPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub enum EnumReplace { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(UnsafeUnpin)] -pub enum EnumUnsafeUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -unsafe impl UnsafeUnpin for EnumUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub enum EnumNotUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} +include!("../include/basic.rs"); diff --git a/tests/overwriting_core_crate.rs b/tests/overwriting_core_crate.rs index 121104cb..19dbe26e 100644 --- a/tests/overwriting_core_crate.rs +++ b/tests/overwriting_core_crate.rs @@ -10,107 +10,11 @@ extern crate pin_project as core; // Dummy module to check that the expansion refers to the crate. mod pin_project {} +// This works in 2018 edition, but in 2015 edition it gives an error:`pin` is ambiguous (derive helper attribute vs any other name) +#[allow(unused_imports)] +use ::pin_project as pin; + use ::pin_project::{pin_project, pinned_drop, UnsafeUnpin}; use std::pin::Pin; -#[pin_project] -pub struct StructDefault { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(PinnedDrop)] -pub struct StructPinnedDrop { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pinned_drop] -impl PinnedDrop for StructPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub struct StructReplace { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(UnsafeUnpin)] -pub struct StructUnsafeUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -unsafe impl UnsafeUnpin for StructUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub struct StructNotUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project] -pub enum EnumDefault { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(PinnedDrop)] -pub enum EnumPinnedDrop { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pinned_drop] -impl PinnedDrop for EnumPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub enum EnumReplace { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(UnsafeUnpin)] -pub enum EnumUnsafeUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -unsafe impl UnsafeUnpin for EnumUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub enum EnumNotUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[test] -fn test() {} +include!("include/basic.rs"); diff --git a/tests/project_if_attr.rs.in b/tests/project_if_attr.rs.in index a8ceeac5..7bc236db 100644 --- a/tests/project_if_attr.rs.in +++ b/tests/project_if_attr.rs.in @@ -6,8 +6,9 @@ fn project_if_let() { Variant1(#[pin] A), Variant2(u8), Variant3 { - #[pin] field: B - } + #[pin] + field: B, + }, } let mut x: Foo = Foo::Variant1(true); diff --git a/tests/rust-2015/Cargo.toml b/tests/rust-2015/Cargo.toml index b968e858..ccc04341 100644 --- a/tests/rust-2015/Cargo.toml +++ b/tests/rust-2015/Cargo.toml @@ -5,5 +5,8 @@ authors = ["Taiki Endo "] edition = "2015" publish = false +[lib] +path = "lib.rs" + [dependencies] pin-project = { path = "../.." } diff --git a/tests/rust-2015/lib.rs b/tests/rust-2015/lib.rs new file mode 100644 index 00000000..f2876e98 --- /dev/null +++ b/tests/rust-2015/lib.rs @@ -0,0 +1,12 @@ +#![no_std] + +extern crate pin_project; + +// This works in 2018 edition, but in 2015 edition it gives an error:`pin` is ambiguous (derive helper attribute vs any other name) +// #[allow(unused_imports)] +// use pin_project as pin; + +use core::pin::Pin; +use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; + +include!("../include/basic.rs"); diff --git a/tests/rust-2015/tests/no-std.rs b/tests/rust-2015/tests/no-std.rs deleted file mode 100644 index e214b1a3..00000000 --- a/tests/rust-2015/tests/no-std.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![no_std] - -extern crate pin_project; - -use core::pin::Pin; -use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; - -#[pin_project] -pub struct StructDefault { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(PinnedDrop)] -pub struct StructPinnedDrop { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pinned_drop] -impl PinnedDrop for StructPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub struct StructReplace { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(UnsafeUnpin)] -pub struct StructUnsafeUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -unsafe impl UnsafeUnpin for StructUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub struct StructNotUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project] -pub enum EnumDefault { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(PinnedDrop)] -pub enum EnumPinnedDrop { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pinned_drop] -impl PinnedDrop for EnumPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub enum EnumReplace { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(UnsafeUnpin)] -pub enum EnumUnsafeUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -unsafe impl UnsafeUnpin for EnumUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub enum EnumNotUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} diff --git a/tests/rust-2015/tests/std.rs b/tests/rust-2015/tests/std.rs index dcab4ac2..78bea3bd 100644 --- a/tests/rust-2015/tests/std.rs +++ b/tests/rust-2015/tests/std.rs @@ -1,103 +1,10 @@ extern crate pin_project; +// This works in 2018 edition, but in 2015 edition it gives an error:`pin` is ambiguous (derive helper attribute vs any other name) +// #[allow(unused_imports)] +// use pin_project as pin; + use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; use std::pin::Pin; -#[pin_project] -pub struct StructDefault { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(PinnedDrop)] -pub struct StructPinnedDrop { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pinned_drop] -impl PinnedDrop for StructPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub struct StructReplace { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project(UnsafeUnpin)] -pub struct StructUnsafeUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -unsafe impl UnsafeUnpin for StructUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub struct StructNotUnpin { - #[pin] - pub pinned: T, - pub unpinned: U, -} - -#[pin_project] -pub enum EnumDefault { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(PinnedDrop)] -pub enum EnumPinnedDrop { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pinned_drop] -impl PinnedDrop for EnumPinnedDrop { - fn drop(self: Pin<&mut Self>) {} -} - -#[pin_project(Replace)] -pub enum EnumReplace { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -#[pin_project(UnsafeUnpin)] -pub enum EnumUnsafeUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} - -unsafe impl UnsafeUnpin for EnumUnsafeUnpin {} - -#[pin_project(!Unpin)] -pub enum EnumNotUnpin { - Struct { - #[pin] - pinned: T, - unpinned: U, - }, - Tuple(#[pin] T, U), -} +include!("../../include/basic.rs"); diff --git a/tests/ui/auxiliary/Cargo.toml b/tests/ui/auxiliary/Cargo.toml index 9170dc77..a874359d 100644 --- a/tests/ui/auxiliary/Cargo.toml +++ b/tests/ui/auxiliary/Cargo.toml @@ -9,7 +9,6 @@ publish = false path = "lib.rs" proc-macro = true - [dependencies] quote = "1.0" syn = { version = "1.0", features = ["full"] }