Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Clippy #94329

Merged
merged 85 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
611d039
Merge commit '57b3c4b90f4346b3990c1be387c3b3ca7b78412c' into clippyup
flip1995 Feb 10, 2022
61864b6
Clippy: Fix botstrap fallout
flip1995 Feb 10, 2022
8173aba
Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"
oli-obk Feb 11, 2022
41d7c7e
Migrate `dbg_macro` to late pass
Alexendoo Feb 11, 2022
96c73c5
Auto merge of #8411 - Alexendoo:dbg_macro, r=flip1995
bors Feb 11, 2022
bb7131c
Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk
bors Feb 11, 2022
9f75aff
Bless clippy test.
cjgillot Jan 28, 2022
7964406
Downgrade transmute_undefined_repr lint to nursery
dtolnay Feb 12, 2022
5707491
Auto merge of #8418 - dtolnay-contrib:transmuteundefinedrepr, r=llogiq
bors Feb 12, 2022
7c94736
change to a struct variant
BoxyUwU Feb 9, 2022
e2dc8ca
Replace a few paths with diagnostic items
Alexendoo Feb 12, 2022
c37d6ee
Auto merge of #8421 - Alexendoo:paths, r=llogiq
bors Feb 12, 2022
662df33
Fix `transmute_undefined_repr` with single field `#[repr(C)]` structs
Jarcho Feb 13, 2022
eed7e9f
Merge cargo lints
Jarcho Feb 13, 2022
78c2e0b
Document `pub` requirement for `new_without_default` lint
nsunderland1 Feb 14, 2022
0836970
Auto merge of #8429 - nsunderland1:master, r=llogiq
bors Feb 14, 2022
41c7004
Auto merge of #8427 - Jarcho:merge_cargo_passes, r=llogiq
bors Feb 14, 2022
4931cab
Auto merge of #8425 - Jarcho:transmute_8417, r=giraffate
bors Feb 14, 2022
fecd216
Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr
bors Feb 14, 2022
b162b11
Add recursive_format_impl lint
jamesmcm Dec 28, 2021
5fa961b
Overhaul `TyS` and `Ty`.
nnethercote Jan 25, 2022
d071ce1
Overhaul `RegionKind` and `Region`.
nnethercote Jan 28, 2022
64ae3ae
Overhaul `Const`.
nnethercote Feb 2, 2022
465cd90
Move transmute_undefined_repr back to nursery
flip1995 Feb 15, 2022
e713288
Rollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dt…
matthiaskrgr Feb 15, 2022
dcdff60
Correctly mark the span of captured arguments in `format_args!()`
ChayimFriedman2 Feb 16, 2022
b34cd79
Auto merge of #8188 - jamesmcm:recursive_display_impl, r=camsteffen
bors Feb 16, 2022
a135b52
Don't lint `needless_borrow` in method receiver positions
Jarcho Feb 17, 2022
faeeef3
Improve `redundant_slicing` lint
Jarcho Jan 3, 2022
4bdc97c
Account for auto-borrows and precedence in `redundant_slicing` lint
Jarcho Jan 4, 2022
113ac6e
Split off new lint `deref_by_slicing` from `redundant_slicing`
Jarcho Jan 11, 2022
7724d67
Move some cases from `redundant_slicing` to `deref_by_slicing`
Jarcho Feb 13, 2022
ecf3165
Rollup merge of #94030 - ChayimFriedman2:issue-94010, r=petrochenkov
matthiaskrgr Feb 17, 2022
504f3af
Don't lint Default::default if it is the udpate syntax base
hellow554 Feb 14, 2022
a4cf91b
Auto merge of #8433 - hellow554:update_default_trait, r=flip1995
bors Feb 17, 2022
9af2be8
Don't lint `needless_borrow` in method receiver positions
Jarcho Feb 17, 2022
9bfcbf4
Remove some redundant checks in various matches lints
Jarcho Feb 17, 2022
7ee2081
Auto merge of #8441 - Jarcho:needless_borrow_temp, r=flip1995
bors Feb 17, 2022
4abaa02
Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"
oli-obk Feb 17, 2022
668b3e4
Auto merge of #8218 - Jarcho:redundant_slicing_deref, r=camsteffen
bors Feb 17, 2022
cdf9a28
Improve lint message of await_holding_*
flip1995 Feb 12, 2022
c4944fb
Actually lint parking_lot in await_holding_lock
flip1995 Feb 12, 2022
c570941
Add test for drop-before-await FP
flip1995 Feb 12, 2022
ea0ce7b
Move await_holding_* lints to suspicious and improve doc
flip1995 Feb 17, 2022
8ce2d46
Check for `cfg` attrubutes before linting `match` expressions
Jarcho Feb 17, 2022
aaeeed6
trigger ptr_as_ptr inside macros
rsmantini Feb 17, 2022
8912d65
Remove hack testing for `cfg` attribute in `match_single_binding`
Jarcho Feb 17, 2022
76f91b6
Auto merge of #8442 - rsmantini:issue-8120-fix, r=Manishearth
bors Feb 17, 2022
a703a82
Auto merge of #94088 - oli-obk:revert, r=jackh726
bors Feb 18, 2022
02f3c17
Auto merge of #8419 - flip1995:await_parking_alot, r=llogiq
bors Feb 18, 2022
8a46645
Lint enum-to-int casts with `cast_possible_truncation`
Jarcho Jan 31, 2022
90bb7a3
New lint `cast_enum_truncation`
Jarcho Feb 1, 2022
88ecdd0
Extract some util functions
Jarcho Feb 18, 2022
73367f8
Auto merge of #8381 - Jarcho:cast_possible_truncation_542, r=Manishearth
bors Feb 18, 2022
c02dff7
Fix `transmute_undefined_repr` when converting between a pointer and …
Jarcho Feb 15, 2022
01732b6
Add some comments to `transmute_undefined_repr`
Jarcho Feb 15, 2022
447a245
Allow various type erasure patterns in `transmute_undefined_repr`
Jarcho Feb 15, 2022
7c07022
Allow transmuting fat pointers to some types in `transmute_undefined_…
Jarcho Feb 16, 2022
d28d19d
Fix `transmute_undefined_repr` when converting between a fat pointer …
Jarcho Feb 16, 2022
78345b4
Clarify `cfg` detection process in `matches.rs`
Jarcho Feb 18, 2022
29ee5e2
Auto merge of #8440 - Jarcho:transmute_undefined, r=Manishearth
bors Feb 18, 2022
a89c795
tests: default to more threads for ui-tests
matthiaskrgr Feb 20, 2022
e3b5cac
fix
tamaroning Feb 21, 2022
e390e6c
update clippy
lcnr Feb 7, 2022
9e605ef
Auto merge of #8443 - Jarcho:match_cfg_arm, r=flip1995
bors Feb 21, 2022
7f8760a
Auto merge of #8451 - matthiaskrgr:ui_speedup, r=llogiq
bors Feb 22, 2022
382b3f0
Fix counting the number of unchangeable arguments in `ptr_arg`
Jarcho Feb 23, 2022
db62821
fix
tamaroning Feb 23, 2022
31b49b0
fix typo
tamaroning Feb 23, 2022
042892a
Auto merge of #8466 - tamaroning:fix_reduntant_closure, r=Manishearth
bors Feb 23, 2022
fd495a0
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Feb 24, 2022
5ece8d2
Bump Clippy Version -> 0.1.61
flip1995 Feb 24, 2022
ce1904f
Bump nightly version -> 2022-02-24
flip1995 Feb 24, 2022
7b2896a
Auto merge of #8468 - flip1995:rustup, r=flip1995
bors Feb 24, 2022
862211d
Disable ``[`new-without-default`]`` for new() methods that are marked…
florian-nagel Feb 25, 2022
2955db4
Replace some more paths with diagnostic items
Alexendoo Feb 25, 2022
95897bf
Auto merge of #8472 - Mastermindaxe:#8152_new-without-default_should_…
bors Feb 25, 2022
4417f78
Auto merge of #8474 - Alexendoo:paths, r=Manishearth
bors Feb 25, 2022
bcbb07f
Rename RecursiveFormatImpl to FormatImpl
Alexendoo Feb 17, 2022
52f3d61
Add `print_in_format_impl` lint
Alexendoo Feb 17, 2022
8bba6b7
Auto merge of #8253 - Alexendoo:print-in-fmt, r=camsteffen
bors Feb 25, 2022
2c8d5a2
Auto merge of #8453 - tamaroning:fix_large_enum_variant, r=camsteffen
bors Feb 26, 2022
e329249
Auto merge of #8464 - Jarcho:ptr_arg_8463, r=camsteffen
bors Feb 26, 2022
d128f93
Merge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup
flip1995 Feb 26, 2022
0d4e583
Update Cargo.lock (Clippy version bump)
flip1995 Feb 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ dependencies = [

[[package]]
name = "clippy"
version = "0.1.60"
version = "0.1.61"
dependencies = [
"cargo_metadata",
"clippy_lints",
Expand All @@ -632,6 +632,7 @@ dependencies = [
"futures 0.3.19",
"if_chain",
"itertools 0.10.1",
"num_cpus",
"parking_lot",
"quote",
"regex",
Expand Down Expand Up @@ -662,7 +663,7 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.60"
version = "0.1.61"
dependencies = [
"cargo_metadata",
"clippy_utils",
Expand All @@ -683,7 +684,7 @@ dependencies = [

[[package]]
name = "clippy_utils"
version = "0.1.60"
version = "0.1.61"
dependencies = [
"arrayvec",
"if_chain",
Expand Down
9 changes: 6 additions & 3 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ Released 2020-11-19
* [`manual_strip`] [#6038](https://github.com/rust-lang/rust-clippy/pull/6038)
* [`map_err_ignore`] [#5998](https://github.com/rust-lang/rust-clippy/pull/5998)
* [`rc_buffer`] [#6044](https://github.com/rust-lang/rust-clippy/pull/6044)
* [`to_string_in_display`] [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
* `to_string_in_display` [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
* `single_char_push_str` [#5881](https://github.com/rust-lang/rust-clippy/pull/5881)

### Moves and Deprecations
Expand Down Expand Up @@ -1481,7 +1481,7 @@ Released 2020-11-19
[#5949](https://github.com/rust-lang/rust-clippy/pull/5949)
* [`doc_markdown`]: allow using "GraphQL" without backticks
[#5996](https://github.com/rust-lang/rust-clippy/pull/5996)
* [`to_string_in_display`]: avoid linting when calling `to_string()` on anything that is not `self`
* `to_string_in_display`: avoid linting when calling `to_string()` on anything that is not `self`
[#5971](https://github.com/rust-lang/rust-clippy/pull/5971)
* [`indexing_slicing`] and [`out_of_bounds_indexing`] treat references to arrays as arrays
[#6034](https://github.com/rust-lang/rust-clippy/pull/6034)
Expand Down Expand Up @@ -3068,6 +3068,7 @@ Released 2018-09-13
[`bytes_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_nth
[`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata
[`case_sensitive_file_extension_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#case_sensitive_file_extension_comparisons
[`cast_enum_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_enum_truncation
[`cast_lossless`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
[`cast_possible_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation
[`cast_possible_wrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
Expand Down Expand Up @@ -3105,6 +3106,7 @@ Released 2018-09-13
[`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr
[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
[`deref_by_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_by_slicing
[`derivable_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
Expand Down Expand Up @@ -3368,6 +3370,7 @@ Released 2018-09-13
[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
[`print_in_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_in_format_impl
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr
[`print_stdout`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout
Expand All @@ -3385,6 +3388,7 @@ Released 2018-09-13
[`range_zip_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
[`rc_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex
[`recursive_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#recursive_format_impl
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
Expand Down Expand Up @@ -3459,7 +3463,6 @@ Released 2018-09-13
[`tabs_in_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some
[`to_string_in_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_display
[`to_string_in_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_format_args
[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.60"
version = "0.1.61"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down Expand Up @@ -50,6 +50,7 @@ syn = { version = "1.0", features = ["full"] }
futures = "0.3"
parking_lot = "0.11.2"
tokio = { version = "1", features = ["io-util"] }
num_cpus = "1.13"

[build-dependencies]
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
version = "0.1.60"
version = "0.1.61"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
119 changes: 82 additions & 37 deletions src/tools/clippy/clippy_lints/src/await_holding_invalid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clippy_utils::diagnostics::span_lint_and_note;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{match_def_path, paths};
use rustc_hir::def_id::DefId;
use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind};
Expand All @@ -9,8 +9,7 @@ use rustc_span::Span;

declare_clippy_lint! {
/// ### What it does
/// Checks for calls to await while holding a
/// non-async-aware MutexGuard.
/// Checks for calls to await while holding a non-async-aware MutexGuard.
///
/// ### Why is this bad?
/// The Mutex types found in std::sync and parking_lot
Expand All @@ -22,77 +21,110 @@ declare_clippy_lint! {
/// either by introducing a scope or an explicit call to Drop::drop.
///
/// ### Known problems
/// Will report false positive for explicitly dropped guards ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)).
/// Will report false positive for explicitly dropped guards
/// ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). A workaround for this is
/// to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
///
/// ### Example
/// ```rust,ignore
/// use std::sync::Mutex;
///
/// ```rust
/// # use std::sync::Mutex;
/// # async fn baz() {}
/// async fn foo(x: &Mutex<u32>) {
/// let guard = x.lock().unwrap();
/// let mut guard = x.lock().unwrap();
/// *guard += 1;
/// bar.await;
/// baz().await;
/// }
///
/// async fn bar(x: &Mutex<u32>) {
/// let mut guard = x.lock().unwrap();
/// *guard += 1;
/// drop(guard); // explicit drop
/// baz().await;
/// }
/// ```
///
/// Use instead:
/// ```rust,ignore
/// use std::sync::Mutex;
///
/// ```rust
/// # use std::sync::Mutex;
/// # async fn baz() {}
/// async fn foo(x: &Mutex<u32>) {
/// {
/// let guard = x.lock().unwrap();
/// let mut guard = x.lock().unwrap();
/// *guard += 1;
/// }
/// bar.await;
/// baz().await;
/// }
///
/// async fn bar(x: &Mutex<u32>) {
/// {
/// let mut guard = x.lock().unwrap();
/// *guard += 1;
/// } // guard dropped here at end of scope
/// baz().await;
/// }
/// ```
#[clippy::version = "1.45.0"]
pub AWAIT_HOLDING_LOCK,
pedantic,
"Inside an async function, holding a MutexGuard while calling await"
suspicious,
"inside an async function, holding a `MutexGuard` while calling `await`"
}

declare_clippy_lint! {
/// ### What it does
/// Checks for calls to await while holding a
/// `RefCell` `Ref` or `RefMut`.
/// Checks for calls to await while holding a `RefCell` `Ref` or `RefMut`.
///
/// ### Why is this bad?
/// `RefCell` refs only check for exclusive mutable access
/// at runtime. Holding onto a `RefCell` ref across an `await` suspension point
/// risks panics from a mutable ref shared while other refs are outstanding.
///
/// ### Known problems
/// Will report false positive for explicitly dropped refs ([#6353](https://github.com/rust-lang/rust-clippy/issues/6353)).
/// Will report false positive for explicitly dropped refs
/// ([#6353](https://github.com/rust-lang/rust-clippy/issues/6353)). A workaround for this is
/// to wrap the `.borrow[_mut]()` call in a block instead of explicitly dropping the ref.
///
/// ### Example
/// ```rust,ignore
/// use std::cell::RefCell;
///
/// ```rust
/// # use std::cell::RefCell;
/// # async fn baz() {}
/// async fn foo(x: &RefCell<u32>) {
/// let mut y = x.borrow_mut();
/// *y += 1;
/// bar.await;
/// baz().await;
/// }
///
/// async fn bar(x: &RefCell<u32>) {
/// let mut y = x.borrow_mut();
/// *y += 1;
/// drop(y); // explicit drop
/// baz().await;
/// }
/// ```
///
/// Use instead:
/// ```rust,ignore
/// use std::cell::RefCell;
///
/// ```rust
/// # use std::cell::RefCell;
/// # async fn baz() {}
/// async fn foo(x: &RefCell<u32>) {
/// {
/// let mut y = x.borrow_mut();
/// *y += 1;
/// }
/// bar.await;
/// baz().await;
/// }
///
/// async fn bar(x: &RefCell<u32>) {
/// {
/// let mut y = x.borrow_mut();
/// *y += 1;
/// } // y dropped here at end of scope
/// baz().await;
/// }
/// ```
#[clippy::version = "1.49.0"]
pub AWAIT_HOLDING_REFCELL_REF,
pedantic,
"Inside an async function, holding a RefCell ref while calling await"
suspicious,
"inside an async function, holding a `RefCell` ref while calling `await`"
}

declare_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF]);
Expand All @@ -118,23 +150,36 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
for ty_cause in ty_causes {
if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() {
if is_mutex_guard(cx, adt.did) {
span_lint_and_note(
span_lint_and_then(
cx,
AWAIT_HOLDING_LOCK,
ty_cause.span,
"this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await",
ty_cause.scope_span.or(Some(span)),
"these are all the await points this lock is held through",
"this `MutexGuard` is held across an `await` point",
|diag| {
diag.help(
"consider using an async-aware `Mutex` type or ensuring the \
`MutexGuard` is dropped before calling await",
);
diag.span_note(
ty_cause.scope_span.unwrap_or(span),
"these are all the `await` points this lock is held through",
);
},
);
}
if is_refcell_ref(cx, adt.did) {
span_lint_and_note(
span_lint_and_then(
cx,
AWAIT_HOLDING_REFCELL_REF,
ty_cause.span,
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
ty_cause.scope_span.or(Some(span)),
"these are all the await points this ref is held through",
"this `RefCell` reference is held across an `await` point",
|diag| {
diag.help("ensure the reference is dropped before calling `await`");
diag.span_note(
ty_cause.scope_span.unwrap_or(span),
"these are all the `await` points this reference is held through",
);
},
);
}
}
Expand Down
54 changes: 54 additions & 0 deletions src/tools/clippy/clippy_lints/src/cargo/common_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! lint on missing cargo common metadata

use cargo_metadata::Metadata;
use clippy_utils::diagnostics::span_lint;
use rustc_lint::LateContext;
use rustc_span::source_map::DUMMY_SP;

use super::CARGO_COMMON_METADATA;

pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: bool) {
for package in &metadata.packages {
// only run the lint if publish is `None` (`publish = true` or skipped entirely)
// or if the vector isn't empty (`publish = ["something"]`)
if package.publish.as_ref().filter(|publish| publish.is_empty()).is_none() || ignore_publish {
if is_empty_str(&package.description) {
missing_warning(cx, package, "package.description");
}

if is_empty_str(&package.license) && is_empty_str(&package.license_file) {
missing_warning(cx, package, "either package.license or package.license_file");
}

if is_empty_str(&package.repository) {
missing_warning(cx, package, "package.repository");
}

if is_empty_str(&package.readme) {
missing_warning(cx, package, "package.readme");
}

if is_empty_vec(&package.keywords) {
missing_warning(cx, package, "package.keywords");
}

if is_empty_vec(&package.categories) {
missing_warning(cx, package, "package.categories");
}
}
}
}

fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) {
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message);
}

fn is_empty_str<T: AsRef<std::ffi::OsStr>>(value: &Option<T>) -> bool {
value.as_ref().map_or(true, |s| s.as_ref().is_empty())
}

fn is_empty_vec(value: &[String]) -> bool {
// This works because empty iterators return true
value.iter().all(String::is_empty)
}
Loading