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
taiki-e committed Jan 27, 2024
1 parent 4115382 commit 381b002
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ workspace = true
members = [
"tests/no-core",
"tests/no-std",
"tests/lint",
]

# This table is shared by projects under github.com/taiki-e.
Expand Down
5 changes: 5 additions & 0 deletions tests/include/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// default pin_project! is completely safe.

::pin_project_lite::pin_project! {
/// Testing default struct.
#[derive(Debug)]
pub struct DefaultStruct<T, U> {
#[pin]
Expand All @@ -12,6 +13,7 @@
}

::pin_project_lite::pin_project! {
/// Testing named struct.
#[project = DefaultStructProj]
#[project_ref = DefaultStructProjRef]
#[derive(Debug)]
Expand All @@ -23,15 +25,18 @@
}

::pin_project_lite::pin_project! {
/// Testing enum.
#[project = DefaultEnumProj]
#[project_ref = DefaultEnumProjRef]
#[derive(Debug)]
pub enum DefaultEnum<T, U> {
/// Struct variant.
Struct {
#[pin]
pinned: T,
unpinned: 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 = "2018"
publish = false

[lib]
path = "lib.rs"

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

[lints]
workspace = true
49 changes: 41 additions & 8 deletions tests/lint.rs → tests/lint/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Check interoperability with rustc and clippy lints.
//! Check interoperability with rustc and clippy lints.
#![forbid(unsafe_code)]
// for old compilers
Expand Down Expand Up @@ -28,7 +28,7 @@
missing_abi,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
// missing_docs, // TODO: https://github.com/taiki-e/pin-project-lite/issues/3#issuecomment-703534472
non_ascii_idents,
noop_method_call,
private_bounds,
Expand All @@ -54,14 +54,17 @@
clippy::single_char_lifetime_names
)] // TODO

/// Test for basic cases.
pub mod basic {
include!("include/basic.rs");
include!("../include/basic.rs");
}

/// Test for `box_pointers` lint.
pub mod box_pointers {
use pin_project_lite::pin_project;

pin_project! {
/// Testing struct.
#[derive(Debug)]
pub struct Struct {
#[pin]
Expand All @@ -71,25 +74,30 @@ pub mod box_pointers {
}

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
#[derive(Debug)]
pub enum Enum {
/// Struct variant.
Struct {
#[pin]
p: Box<isize>,
u: Box<isize>,
},
/// Unit variant.
Unit,
}
}
}

/// Test for `explicit_outlives_requirements` lint.
pub mod explicit_outlives_requirements {
use pin_project_lite::pin_project;

pin_project! {
/// Testing struct.
#[derive(Debug)]
pub struct Struct<'a, T, U>
where
Expand All @@ -103,6 +111,7 @@ pub mod explicit_outlives_requirements {
}

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
Expand All @@ -112,37 +121,45 @@ pub mod explicit_outlives_requirements {
T: ?Sized,
U: ?Sized,
{
/// Struct variant.
Struct {
#[pin]
pinned: &'a mut T,
unpinned: &'a mut U,
},
/// Unit variant.
Unit,
}
}
}

/// Test for `variant_size_differences` and `clippy::large_enum_variant` lints.
pub mod variant_size_differences {
use pin_project_lite::pin_project;

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
#[allow(missing_debug_implementations, missing_copy_implementations)] // https://github.com/rust-lang/rust/pull/74060
#[allow(variant_size_differences)] // for the type itself
#[allow(clippy::large_enum_variant)] // for the type itself
pub enum Enum {
/// Small variant size.
V1 { f: u8 },
/// Huge variant size.
V2 { f: [u8; 1024] },
}
}
}

/// Test for `clippy::mut_mut` lint.
pub mod clippy_mut_mut {
use pin_project_lite::pin_project;

pin_project! {
/// Testing struct.
#[derive(Debug)]
pub struct Struct<'a, T, U> {
#[pin]
Expand All @@ -152,27 +169,31 @@ pub mod clippy_mut_mut {
}

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
#[derive(Debug)]
pub enum Enum<'a, T, U> {
/// Struct variant.
Struct {
#[pin]
pinned: &'a mut T,
unpinned: &'a mut U,
},
/// Unit variant.
Unit,
}
}
}

/// Test for `clippy::redundant_pub_crate` lint.
#[allow(unreachable_pub)]
mod clippy_redundant_pub_crate {
use pin_project_lite::pin_project;

pin_project! {
#[derive(Debug)]
/// Testing struct.
pub struct Struct<T, U> {
#[pin]
pub pinned: T,
Expand All @@ -181,27 +202,30 @@ mod clippy_redundant_pub_crate {
}

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
#[derive(Debug)]
pub enum Enum<T, U> {
/// Struct variant.
Struct {
#[pin]
pinned: T,
unpinned: U,
},
/// Unit variant.
Unit,
}
}
}

/// Test for `clippy::type_repetition_in_bounds` lint.
#[allow(clippy::use_self)]
pub mod clippy_type_repetition_in_bounds {
use pin_project_lite::pin_project;

pin_project! {
#[derive(Debug)]
/// Testing struct.
pub struct Struct<T, U>
where
Struct<T, U>: Sized,
Expand All @@ -213,29 +237,32 @@ pub mod clippy_type_repetition_in_bounds {
}

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
#[derive(Debug)]
pub enum Enum<T, U>
where
Enum<T, U>: Sized,
{
/// Struct variant.
Struct {
#[pin]
pinned: T,
unpinned: U,
},
/// Unit variant.
Unit,
}
}
}

#[allow(missing_debug_implementations)]
/// Test for `clippy::used_underscore_binding` lint.
pub mod clippy_used_underscore_binding {
use pin_project_lite::pin_project;

pin_project! {
/// Testing struct.
#[allow(clippy::pub_underscore_fields)]
pub struct Struct<T, U> {
#[pin]
Expand All @@ -245,10 +272,12 @@ pub mod clippy_used_underscore_binding {
}

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
pub enum Enum<T, U> {
/// Variant.
Struct {
#[pin]
_pinned: T,
Expand All @@ -258,10 +287,12 @@ pub mod clippy_used_underscore_binding {
}
}

/// Test for `clippy::ref_option_ref` lint.
pub mod clippy_ref_option_ref {
use pin_project_lite::pin_project;

pin_project! {
/// Testing struct.
#[allow(clippy::pub_underscore_fields)]
pub struct Struct<'a> {
#[pin]
Expand All @@ -271,10 +302,12 @@ pub mod clippy_ref_option_ref {
}

pin_project! {
/// Testing enum.
#[project = EnumProj]
#[project_ref = EnumProjRef]
#[project(!Unpin)]
pub enum Enum<'a> {
/// Variant.
Struct {
#[pin]
_pinned: Option<&'a ()>,
Expand Down

0 comments on commit 381b002

Please sign in to comment.