Skip to content

Commit

Permalink
Move lint test to sub-crate
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Jan 25, 2024
1 parent 75fa3f7 commit 3624259
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ members = [
"tests/auxiliary/macro",
"tests/no-core",
"tests/no-std",
"tests/lint",
"tests/rust-2015",
]

Expand Down
2 changes: 2 additions & 0 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ fn proj_allowed_lints(cx: &Context<'_>) -> (TokenStream, TokenStream, TokenStrea
#proj_ref_allowed_lints
#[allow(dead_code)] // This lint warns unused fields/variants.
#[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`.
#[allow(clippy::missing_docs_in_private_items)]
};
let proj_own_allowed_lints =
if cx.project_replace.ident().is_some() { Some(&global_allowed_lints) } else { None };
Expand Down Expand Up @@ -856,6 +857,7 @@ fn make_drop_impl(cx: &Context<'_>) -> TokenStream {
impl #impl_generics _pin_project::__private::Drop for #ident #ty_generics
#where_clause
{
#[allow(clippy::missing_inline_in_public_items)]
fn drop(&mut self) {
#unsafety {
// Safety - we're in 'drop', so we know that 'self' will
Expand Down
58 changes: 58 additions & 0 deletions tests/include/basic-safe-part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,73 @@

// default #[pin_project], PinnedDrop, project_replace, !Unpin, and UnsafeUnpin without UnsafeUnpin impl are completely safe.

/// Testing default struct.
#[::pin_project::pin_project]
#[derive(Debug)]
pub struct DefaultStruct<T, U> {
/// Pinned field.
#[pin]
pub pinned: T,
/// Unpinned field.
pub unpinned: U,
}

/// Testing named struct.
#[::pin_project::pin_project(
project = DefaultStructNamedProj,
project_ref = DefaultStructNamedProjRef,
)]
#[derive(Debug)]
pub struct DefaultStructNamed<T, U> {
/// Pinned field.
#[pin]
pub pinned: T,
/// Unpinned field.
pub unpinned: U,
}

/// Testing default tuple struct.
#[::pin_project::pin_project]
#[derive(Debug)]
pub struct DefaultTupleStruct<T, U>(#[pin] pub T, pub U);

/// Testing named tuple struct.
#[::pin_project::pin_project(
project = DefaultTupleStructNamedProj,
project_ref = DefaultTupleStructNamedProjRef,
)]
#[derive(Debug)]
pub struct DefaultTupleStructNamed<T, U>(#[pin] pub T, pub U);

/// Testing enum.
#[::pin_project::pin_project(
project = DefaultEnumProj,
project_ref = DefaultEnumProjRef,
)]
#[derive(Debug)]
pub enum DefaultEnum<T, U> {
/// Struct variant.
Struct {
/// Pinned field.
#[pin]
pinned: T,
/// Unpinned field.
unpinned: U,
},
/// Tuple variant.
Tuple(#[pin] T, U),
/// Unit variant.
Unit,
}

/// Testing pinned drop struct.
#[::pin_project::pin_project(PinnedDrop)]
#[derive(Debug)]
pub struct PinnedDropStruct<T, U> {
/// Pinned field.
#[pin]
pub pinned: T,
/// Unpinned field.
pub unpinned: U,
}

Expand All @@ -60,6 +77,7 @@ impl<T, U> PinnedDrop for PinnedDropStruct<T, U> {
fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}

/// Testing pinned drop tuple struct.
#[::pin_project::pin_project(PinnedDrop)]
#[derive(Debug)]
pub struct PinnedDropTupleStruct<T, U>(#[pin] pub T, pub U);
Expand All @@ -69,19 +87,25 @@ impl<T, U> PinnedDrop for PinnedDropTupleStruct<T, U> {
fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}

/// Testing pinned drop enum.
#[::pin_project::pin_project(
PinnedDrop,
project = PinnedDropEnumProj,
project_ref = PinnedDropEnumProjRef,
)]
#[derive(Debug)]
pub enum PinnedDropEnum<T, U> {
/// Struct variant.
Struct {
/// Pinned field.
#[pin]
pinned: T,
/// Unpinned field.
unpinned: U,
},
/// Tuple variant.
Tuple(#[pin] T, U),
/// Unit variant.
Unit,
}

Expand All @@ -90,30 +114,38 @@ impl<T, U> PinnedDrop for PinnedDropEnum<T, U> {
fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}

/// Testing default struct with replace.
#[::pin_project::pin_project(project_replace)]
#[derive(Debug)]
pub struct ReplaceStruct<T, U> {
/// Pinned field.
#[pin]
pub pinned: T,
/// Unpinned field.
pub unpinned: U,
}

/// Testing named struct with replace.
#[::pin_project::pin_project(
project = ReplaceStructNamedProj,
project_ref = ReplaceStructNamedProjRef,
project_replace = ReplaceStructNamedProjOwn,
)]
#[derive(Debug)]
pub struct ReplaceStructNamed<T, U> {
/// Pinned field.
#[pin]
pub pinned: T,
/// Unpinned field.
pub unpinned: U,
}

/// Testing default struct with replace.
#[::pin_project::pin_project(project_replace)]
#[derive(Debug)]
pub struct ReplaceTupleStruct<T, U>(#[pin] pub T, pub U);

/// Testing named struct with replace.
#[::pin_project::pin_project(
project = ReplaceTupleStructNamedProj,
project_ref = ReplaceTupleStructNamedProjRef,
Expand All @@ -122,74 +154,100 @@ pub struct ReplaceTupleStruct<T, U>(#[pin] pub T, pub U);
#[derive(Debug)]
pub struct ReplaceTupleStructNamed<T, U>(#[pin] pub T, pub U);

/// Testing enum with replace.
#[::pin_project::pin_project(
project = ReplaceEnumProj,
project_ref = ReplaceEnumProjRef,
project_replace = ReplaceEnumProjOwn,
)]
#[derive(Debug)]
pub enum ReplaceEnum<T, U> {
/// Struct variant.
Struct {
/// Pinned field.
#[pin]
pinned: T,
/// Unpinned field.
unpinned: U,
},
/// Tuple variant.
Tuple(#[pin] T, U),
/// Unit variant.
Unit,
}

/// Testing struct with unsafe `Unpin`.
#[::pin_project::pin_project(UnsafeUnpin)]
#[derive(Debug)]
pub struct UnsafeUnpinStruct<T, U> {
/// Pinned field.
#[pin]
pub pinned: T,
/// Unpinned field.
pub unpinned: U,
}

/// Testing tuple struct with unsafe `Unpin`.
#[::pin_project::pin_project(UnsafeUnpin)]
#[derive(Debug)]
pub struct UnsafeUnpinTupleStruct<T, U>(#[pin] pub T, pub U);

/// Testing enum unsafe `Unpin`.
#[::pin_project::pin_project(
UnsafeUnpin,
project = UnsafeUnpinEnumProj,
project_ref = UnsafeUnpinEnumProjRef,
)]
#[derive(Debug)]
pub enum UnsafeUnpinEnum<T, U> {
/// Struct variant.
Struct {
/// Pinned field.
#[pin]
pinned: T,
/// Unpinned field.
unpinned: U,
},
/// Tuple variant.
Tuple(#[pin] T, U),
/// Unit variant.
Unit,
}

/// Testing struct with `!Unpin`.
#[::pin_project::pin_project(!Unpin)]
#[derive(Debug)]
pub struct NotUnpinStruct<T, U> {
/// Pinned field.
#[pin]
pub pinned: T,
/// Unpinned field.
pub unpinned: U,
}

/// Testing tuple struct with `!Unpin`.
#[::pin_project::pin_project(!Unpin)]
#[derive(Debug)]
pub struct NotUnpinTupleStruct<T, U>(#[pin] pub T, pub U);

/// Testing enum with `!Unpin`.
#[::pin_project::pin_project(
!Unpin,
project = NotUnpinEnumProj,
project_ref = NotUnpinEnumProjRef,
)]
#[derive(Debug)]
pub enum NotUnpinEnum<T, U> {
/// Struct variant.
Struct {
/// Pinned field.
#[pin]
pinned: T,
/// Unpinned field.
unpinned: U,
},
/// Tuple variant.
Tuple(#[pin] T, U),
/// Unit variant.
Unit,
}
14 changes: 14 additions & 0 deletions tests/lint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "lint"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
path = "lib.rs"

[dependencies]
pin-project = { path = "../.." }

[lints]
workspace = true
Loading

0 comments on commit 3624259

Please sign in to comment.