Skip to content

Commit

Permalink
Use [lints] in Cargo.toml and apply more lints
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 30, 2023
1 parent c66b879 commit f932302
Show file tree
Hide file tree
Showing 31 changed files with 191 additions and 110 deletions.
8 changes: 8 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@

avoid-breaking-exported-api = false
disallowed-names = []
disallowed-macros = [
{ path = "std::dbg", reason = "it is okay to use during development, but please do not include it in main branch" },
]
disallowed-methods = [
{ path = "std::env::remove_var", reason = "this is not thread-safe and inherently unsafe; see <https://github.com/rust-lang/rust/issues/27970> for more" },
{ path = "std::env::set_var", reason = "this is not thread-safe and inherently unsafe; see <https://github.com/rust-lang/rust/issues/27970> for more" },
]
disallowed-types = []
62 changes: 50 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ allowed_external_types = [
"pin_project_internal::*",
]

[workspace]
resolver = "2"
members = [
"pin-project-internal",
"tests/auxiliary/macro",
"tests/no-core",
"tests/no-std",
"tests/rust-2015",
]

[lib]
doc-scrape-examples = false

Expand All @@ -39,7 +29,55 @@ pin-project-internal = { version = "=1.1.3", path = "pin-project-internal" }

[dev-dependencies]
pin-project-auxiliary-macro = { path = "tests/auxiliary/macro" }
macrotest = { git = "https://github.com/taiki-e/macrotest.git", branch = "dev" } # 2021 edition support + syn 2.0 + no cargo-expand
macrotest = { git = "https://github.com/taiki-e/macrotest.git", branch = "dev" } # 2021 edition support + syn 2.0 + no cargo-expand + adjust overwrite behavior
rustversion = "1"
static_assertions = "1"
trybuild = "1.0.67"
trybuild = { git = "https://github.com/taiki-e/trybuild.git", branch = "dev" } # adjust overwrite behavior

[lints]
workspace = true

[workspace]
resolver = "2"
members = [
"pin-project-internal",
"tests/auxiliary/macro",
"tests/no-core",
"tests/no-std",
"tests/rust-2015",
]

# This table is shared by projects under https://github.com/taiki-e.
# It is not intended for manual editing.
[workspace.lints.rust]
improper_ctypes = "warn"
improper_ctypes_definitions = "warn"
non_ascii_idents = "warn"
rust_2018_idioms = "warn"
single_use_lifetimes = "warn"
unreachable_pub = "warn"
# unsafe_op_in_unsafe_fn = "warn" # Set at crate-level instead since https://github.com/rust-lang/rust/pull/100081 is not available on MSRV
[workspace.lints.clippy]
all = "warn" # Downgrade deny-by-default lints
pedantic = "warn"
as_ptr_cast_mut = "warn"
default_union_representation = "warn"
inline_asm_x86_att_syntax = "warn"
trailing_empty_array = "warn"
transmute_undefined_repr = "warn"
undocumented_unsafe_blocks = "warn"
# Suppress buggy or noisy clippy lints
borrow_as_ptr = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/8286
doc_markdown = { level = "allow", priority = 1 }
float_cmp = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/7725
manual_assert = { level = "allow", priority = 1 }
manual_range_contains = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/6455#issuecomment-1225966395
missing_errors_doc = { level = "allow", priority = 1 }
module_name_repetitions = { level = "allow", priority = 1 }
similar_names = { level = "allow", priority = 1 }
single_match = { level = "allow", priority = 1 }
single_match_else = { level = "allow", priority = 1 }
struct_excessive_bools = { level = "allow", priority = 1 }
too_many_arguments = { level = "allow", priority = 1 }
too_many_lines = { level = "allow", priority = 1 }
type_complexity = { level = "allow", priority = 1 }
9 changes: 7 additions & 2 deletions examples/enum-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
// fn main() {}
// ```

#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
#![allow(
clippy::needless_lifetimes,
dead_code,
unused_imports,
unused_parens,
unknown_lints,
renamed_and_removed_lints,
clippy::just_underscores_and_digits,
clippy::needless_lifetimes,
clippy::undocumented_unsafe_blocks,
clippy::used_underscore_binding
)]

Expand Down
11 changes: 9 additions & 2 deletions examples/not_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
// }
// ```

#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
#![allow(clippy::needless_lifetimes)]
#![allow(
dead_code,
unused_imports,
unused_parens,
unknown_lints,
renamed_and_removed_lints,
clippy::needless_lifetimes,
clippy::undocumented_unsafe_blocks
)]

use pin_project::pin_project;

Expand Down
13 changes: 11 additions & 2 deletions examples/pinned_drop-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// fn main() {}
// ```

#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
#![allow(clippy::needless_lifetimes, clippy::mut_mut)]
#![allow(
dead_code,
single_use_lifetimes,
unused_imports,
unused_parens,
unknown_lints,
renamed_and_removed_lints,
clippy::mut_mut,
clippy::needless_lifetimes,
clippy::undocumented_unsafe_blocks
)]

use std::pin::Pin;

Expand Down
11 changes: 9 additions & 2 deletions examples/project_replace-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
// fn main() {}
// ```

#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
#![allow(clippy::needless_lifetimes)]
#![allow(
dead_code,
unused_imports,
unused_parens,
unknown_lints,
renamed_and_removed_lints,
clippy::needless_lifetimes,
clippy::undocumented_unsafe_blocks
)]

use pin_project::pin_project;

Expand Down
11 changes: 9 additions & 2 deletions examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
// fn main() {}
// ```

#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
#![allow(clippy::needless_lifetimes)]
#![allow(
dead_code,
unused_imports,
unused_parens,
unknown_lints,
renamed_and_removed_lints,
clippy::needless_lifetimes,
clippy::undocumented_unsafe_blocks
)]

use pin_project::pin_project;

Expand Down
11 changes: 9 additions & 2 deletions examples/unsafe_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
// fn main() {}
// ```

#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
#![allow(clippy::needless_lifetimes)]
#![allow(
dead_code,
unused_imports,
unused_parens,
unknown_lints,
renamed_and_removed_lints,
clippy::needless_lifetimes,
clippy::undocumented_unsafe_blocks
)]

use pin_project::{pin_project, UnsafeUnpin};

Expand Down
2 changes: 1 addition & 1 deletion examples/unsafe_unpin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// See ./unsafe_unpin-expanded.rs for generated code.

#![allow(dead_code)]
#![allow(dead_code, clippy::undocumented_unsafe_blocks)]

use pin_project::{pin_project, UnsafeUnpin};

Expand Down
3 changes: 3 additions & 0 deletions pin-project-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ syn = { version = "2.0.1", features = ["full", "visit-mut"] }

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

[lints]
workspace = true
9 changes: 1 addition & 8 deletions pin-project-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
)
))]
#![forbid(unsafe_code)]
#![warn(rust_2018_idioms, single_use_lifetimes, unreachable_pub, clippy::pedantic)]
#![allow(
clippy::needless_doctest_main,
clippy::similar_names,
clippy::single_match_else,
clippy::struct_field_names,
clippy::too_many_lines
)]
#![allow(clippy::needless_doctest_main, clippy::struct_field_names)]

#[macro_use]
mod error;
Expand Down
15 changes: 1 addition & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,8 @@ see [examples] directory for more examples and generated code.
allow(dead_code, unused_variables)
)
))]
#![warn(unsafe_op_in_unsafe_fn)]
#![warn(
rust_2018_idioms,
single_use_lifetimes,
unreachable_pub,
clippy::pedantic,
// Lints that may help when writing public library.
missing_debug_implementations,
missing_docs,
Expand All @@ -112,16 +109,6 @@ see [examples] directory for more examples and generated code.
// clippy::missing_inline_in_public_items,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
// Lints that may help when writing unsafe code.
improper_ctypes,
improper_ctypes_definitions,
unsafe_op_in_unsafe_fn,
clippy::as_ptr_cast_mut,
clippy::default_union_representation,
clippy::inline_asm_x86_att_syntax,
clippy::trailing_empty_array,
clippy::transmute_undefined_repr,
clippy::undocumented_unsafe_blocks,
)]
#![allow(clippy::needless_doctest_main)]

Expand Down
3 changes: 3 additions & 0 deletions tests/auxiliary/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ proc-macro = true
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["full"] }

[lints]
workspace = true
2 changes: 0 additions & 2 deletions tests/auxiliary/macro/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::{env, process::Command};

fn main() {
Expand Down
5 changes: 2 additions & 3 deletions tests/auxiliary/macro/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![cfg(nightly)]
#![warn(rust_2018_idioms, single_use_lifetimes)]
#![allow(clippy::pedantic)]
#![allow(clippy::missing_panics_doc)]

use proc_macro::TokenStream;
use quote::{format_ident, quote, ToTokens};
Expand Down Expand Up @@ -47,7 +46,7 @@ pub fn hidden_repr_cfg_not_any(args: TokenStream, input: TokenStream) -> TokenSt
#[proc_macro_attribute]
pub fn add_pinned_field(_: TokenStream, input: TokenStream) -> TokenStream {
let mut item: ItemStruct = syn::parse_macro_input!(input);
let fields = if let Fields::Named(fields) = &mut item.fields { fields } else { unreachable!() };
let Fields::Named(fields) = &mut item.fields else { unreachable!() };
fields.named.push(Field {
attrs: vec![parse_quote!(#[pin])],
vis: Visibility::Inherited,
Expand Down
3 changes: 1 addition & 2 deletions tests/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![warn(rust_2018_idioms, single_use_lifetimes)]
#![allow(dead_code)]
#![allow(dead_code, clippy::items_after_statements)]

// Refs: https://doc.rust-lang.org/reference/attributes.html

Expand Down
7 changes: 0 additions & 7 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

#![cfg(not(miri))]
#![cfg(not(careful))]
#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::env;

#[rustversion::attr(not(nightly), ignore)]
#[test]
fn ui() {
if env::var_os("CI").is_none() {
env::set_var("TRYBUILD", "overwrite");
}

let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/**/*.rs");
t.pass("tests/run-pass/**/*.rs");
Expand Down
2 changes: 0 additions & 2 deletions tests/drop_order.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![warn(rust_2018_idioms, single_use_lifetimes)]

// Refs: https://doc.rust-lang.org/reference/destructors.html

use std::{cell::Cell, pin::Pin, thread};
Expand Down
12 changes: 1 addition & 11 deletions tests/expandtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@

#![cfg(not(miri))]
#![cfg(not(careful))]
#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::env;

const PATH: &str = "tests/expand/**/*.rs";

#[rustversion::attr(not(nightly), ignore)]
#[test]
fn expandtest() {
let args = &["--all-features"];
if env::var_os("CI").is_some() {
macrotest::expand_without_refresh_args(PATH, args);
} else {
env::set_var("MACROTEST", "overwrite");
macrotest::expand_args(PATH, args);
}
macrotest::expand_args("tests/expand/**/*.rs", args);
}
3 changes: 3 additions & 0 deletions tests/no-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ path = "lib.rs"

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

[lints]
workspace = true
2 changes: 0 additions & 2 deletions tests/no-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::{env, process::Command};

fn main() {
Expand Down
3 changes: 3 additions & 0 deletions tests/no-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ path = "lib.rs"

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

[lints]
workspace = true
1 change: 0 additions & 1 deletion tests/no-std/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![no_std]
#![warn(rust_2018_idioms, single_use_lifetimes)]

// Check compatibility with no-std environment and Rust 2018.

Expand Down
Loading

0 comments on commit f932302

Please sign in to comment.