Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
* Reduced duplicate code.
* Fixed warnings in generated code.
* Added tests/no-std to main workspace members.
  • Loading branch information
taiki-e committed Jun 3, 2020
1 parent 4689f8c commit cbfaae4
Show file tree
Hide file tree
Showing 45 changed files with 318 additions and 628 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ members = [
"tests/ui/auxiliary",
"tests/doc",
"tests/expand",
"tests/rust-2015"
"tests/no-std",
"tests/rust-2015",
]

[dependencies]
Expand Down
6 changes: 3 additions & 3 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion compiletest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions examples/enum-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ enum Enum<T, U> {
Unpinned(U),
}

#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -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<T, U> Enum<T, U> {
fn project<'pin>(
Expand Down
9 changes: 6 additions & 3 deletions examples/not_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ pub struct Struct<T, U> {
}

#[doc(hidden)]
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -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<T, U> Struct<T, U> {
pub(crate) fn project<'pin>(
Expand Down
9 changes: 6 additions & 3 deletions examples/pinned_drop-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ pub struct Struct<'a, T> {
}

#[doc(hidden)]
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[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,
Expand All @@ -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,
Expand All @@ -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>(
Expand Down
11 changes: 7 additions & 4 deletions examples/project_replace-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ struct Struct<T, U> {
}

#[doc(hidden)]
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -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<T, U> {
pinned: ::pin_project::__private::PhantomData<T>,
Expand All @@ -59,6 +61,7 @@ struct __StructProjectionOwned<T, U> {
#[doc(hidden)]
#[allow(non_upper_case_globals)]
#[allow(single_use_lifetimes)]
#[allow(clippy::used_underscore_binding)]
const __SCOPE_Struct: () = {
impl<T, U> Struct<T, U> {
fn project<'pin>(
Expand Down
9 changes: 6 additions & 3 deletions examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ struct Struct<T, U> {
}

#[doc(hidden)]
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -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<T, U> Struct<T, U> {
fn project<'pin>(
Expand Down
9 changes: 6 additions & 3 deletions examples/unsafe_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ pub struct Struct<T, U> {
}

#[doc(hidden)]
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -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<T, U> Struct<T, U> {
pub(crate) fn project<'pin>(
Expand Down
9 changes: 7 additions & 2 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub(super) fn parse_derive(input: TokenStream) -> Result<TokenStream> {
#[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
Expand Down Expand Up @@ -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 <ty>`.
#[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 <ty>`.
#[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() {
Expand Down Expand Up @@ -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 <ty>`.
#[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 <ty>`.
#[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
}
Expand Down
5 changes: 4 additions & 1 deletion tests/expand/tests/expand/default-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ enum Enum<T, U> {
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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -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<T, U> Enum<T, U> {
fn project<'pin>(
Expand Down
5 changes: 4 additions & 1 deletion tests/expand/tests/expand/default-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ struct Struct<T, U> {
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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -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<T, U> Struct<T, U> {
fn project<'pin>(
Expand Down
5 changes: 4 additions & 1 deletion tests/expand/tests/expand/default-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use pin_project::pin_project;
#[pin(__private())]
struct TupleStruct<T, U>(#[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),
Expand All @@ -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<T, U>: 'pin;
#[doc(hidden)]
#[allow(non_upper_case_globals)]
#[allow(single_use_lifetimes)]
#[allow(clippy::used_underscore_binding)]
const __SCOPE_TupleStruct: () = {
impl<T, U> TupleStruct<T, U> {
fn project<'pin>(
Expand Down
5 changes: 4 additions & 1 deletion tests/expand/tests/expand/naming-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ enum Enum<T, U> {
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<T, U>: 'pin,
Expand All @@ -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<T, U>: 'pin,
Expand All @@ -49,6 +51,7 @@ enum ProjOwn<T, U> {
#[doc(hidden)]
#[allow(non_upper_case_globals)]
#[allow(single_use_lifetimes)]
#[allow(clippy::used_underscore_binding)]
const __SCOPE_Enum: () = {
impl<T, U> Enum<T, U> {
fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> {
Expand Down
Loading

0 comments on commit cbfaae4

Please sign in to comment.