Skip to content

Commit d128f93

Browse files
committed
Merge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup
2 parents 8128e91 + e329249 commit d128f93

File tree

113 files changed

+3461
-1441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+3461
-1441
lines changed

src/tools/clippy/CHANGELOG.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ Released 2020-11-19
14381438
* [`manual_strip`] [#6038](https://github.com/rust-lang/rust-clippy/pull/6038)
14391439
* [`map_err_ignore`] [#5998](https://github.com/rust-lang/rust-clippy/pull/5998)
14401440
* [`rc_buffer`] [#6044](https://github.com/rust-lang/rust-clippy/pull/6044)
1441-
* [`to_string_in_display`] [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
1441+
* `to_string_in_display` [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
14421442
* `single_char_push_str` [#5881](https://github.com/rust-lang/rust-clippy/pull/5881)
14431443

14441444
### Moves and Deprecations
@@ -1481,7 +1481,7 @@ Released 2020-11-19
14811481
[#5949](https://github.com/rust-lang/rust-clippy/pull/5949)
14821482
* [`doc_markdown`]: allow using "GraphQL" without backticks
14831483
[#5996](https://github.com/rust-lang/rust-clippy/pull/5996)
1484-
* [`to_string_in_display`]: avoid linting when calling `to_string()` on anything that is not `self`
1484+
* `to_string_in_display`: avoid linting when calling `to_string()` on anything that is not `self`
14851485
[#5971](https://github.com/rust-lang/rust-clippy/pull/5971)
14861486
* [`indexing_slicing`] and [`out_of_bounds_indexing`] treat references to arrays as arrays
14871487
[#6034](https://github.com/rust-lang/rust-clippy/pull/6034)
@@ -3068,6 +3068,7 @@ Released 2018-09-13
30683068
[`bytes_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_nth
30693069
[`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata
30703070
[`case_sensitive_file_extension_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#case_sensitive_file_extension_comparisons
3071+
[`cast_enum_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_enum_truncation
30713072
[`cast_lossless`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
30723073
[`cast_possible_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation
30733074
[`cast_possible_wrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
@@ -3105,6 +3106,7 @@ Released 2018-09-13
31053106
[`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr
31063107
[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver
31073108
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
3109+
[`deref_by_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_by_slicing
31083110
[`derivable_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
31093111
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
31103112
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
@@ -3368,6 +3370,7 @@ Released 2018-09-13
33683370
[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch
33693371
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
33703372
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
3373+
[`print_in_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_in_format_impl
33713374
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
33723375
[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr
33733376
[`print_stdout`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout
@@ -3385,6 +3388,7 @@ Released 2018-09-13
33853388
[`range_zip_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
33863389
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
33873390
[`rc_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex
3391+
[`recursive_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#recursive_format_impl
33883392
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
33893393
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
33903394
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
@@ -3459,7 +3463,6 @@ Released 2018-09-13
34593463
[`tabs_in_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
34603464
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
34613465
[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some
3462-
[`to_string_in_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_display
34633466
[`to_string_in_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_format_args
34643467
[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
34653468
[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments

src/tools/clippy/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.60"
3+
version = "0.1.61"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -50,6 +50,7 @@ syn = { version = "1.0", features = ["full"] }
5050
futures = "0.3"
5151
parking_lot = "0.11.2"
5252
tokio = { version = "1", features = ["io-util"] }
53+
num_cpus = "1.13"
5354

5455
[build-dependencies]
5556
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }

src/tools/clippy/clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.60"
3+
version = "0.1.61"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

src/tools/clippy/clippy_lints/src/await_holding_invalid.rs

+82-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint_and_note;
1+
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::{match_def_path, paths};
33
use rustc_hir::def_id::DefId;
44
use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind};
@@ -9,8 +9,7 @@ use rustc_span::Span;
99

1010
declare_clippy_lint! {
1111
/// ### What it does
12-
/// Checks for calls to await while holding a
13-
/// non-async-aware MutexGuard.
12+
/// Checks for calls to await while holding a non-async-aware MutexGuard.
1413
///
1514
/// ### Why is this bad?
1615
/// The Mutex types found in std::sync and parking_lot
@@ -22,77 +21,110 @@ declare_clippy_lint! {
2221
/// either by introducing a scope or an explicit call to Drop::drop.
2322
///
2423
/// ### Known problems
25-
/// Will report false positive for explicitly dropped guards ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)).
24+
/// Will report false positive for explicitly dropped guards
25+
/// ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). A workaround for this is
26+
/// to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
2627
///
2728
/// ### Example
28-
/// ```rust,ignore
29-
/// use std::sync::Mutex;
30-
///
29+
/// ```rust
30+
/// # use std::sync::Mutex;
31+
/// # async fn baz() {}
3132
/// async fn foo(x: &Mutex<u32>) {
32-
/// let guard = x.lock().unwrap();
33+
/// let mut guard = x.lock().unwrap();
3334
/// *guard += 1;
34-
/// bar.await;
35+
/// baz().await;
36+
/// }
37+
///
38+
/// async fn bar(x: &Mutex<u32>) {
39+
/// let mut guard = x.lock().unwrap();
40+
/// *guard += 1;
41+
/// drop(guard); // explicit drop
42+
/// baz().await;
3543
/// }
3644
/// ```
3745
///
3846
/// Use instead:
39-
/// ```rust,ignore
40-
/// use std::sync::Mutex;
41-
///
47+
/// ```rust
48+
/// # use std::sync::Mutex;
49+
/// # async fn baz() {}
4250
/// async fn foo(x: &Mutex<u32>) {
4351
/// {
44-
/// let guard = x.lock().unwrap();
52+
/// let mut guard = x.lock().unwrap();
4553
/// *guard += 1;
4654
/// }
47-
/// bar.await;
55+
/// baz().await;
56+
/// }
57+
///
58+
/// async fn bar(x: &Mutex<u32>) {
59+
/// {
60+
/// let mut guard = x.lock().unwrap();
61+
/// *guard += 1;
62+
/// } // guard dropped here at end of scope
63+
/// baz().await;
4864
/// }
4965
/// ```
5066
#[clippy::version = "1.45.0"]
5167
pub AWAIT_HOLDING_LOCK,
52-
pedantic,
53-
"Inside an async function, holding a MutexGuard while calling await"
68+
suspicious,
69+
"inside an async function, holding a `MutexGuard` while calling `await`"
5470
}
5571

5672
declare_clippy_lint! {
5773
/// ### What it does
58-
/// Checks for calls to await while holding a
59-
/// `RefCell` `Ref` or `RefMut`.
74+
/// Checks for calls to await while holding a `RefCell` `Ref` or `RefMut`.
6075
///
6176
/// ### Why is this bad?
6277
/// `RefCell` refs only check for exclusive mutable access
6378
/// at runtime. Holding onto a `RefCell` ref across an `await` suspension point
6479
/// risks panics from a mutable ref shared while other refs are outstanding.
6580
///
6681
/// ### Known problems
67-
/// Will report false positive for explicitly dropped refs ([#6353](https://github.com/rust-lang/rust-clippy/issues/6353)).
82+
/// Will report false positive for explicitly dropped refs
83+
/// ([#6353](https://github.com/rust-lang/rust-clippy/issues/6353)). A workaround for this is
84+
/// to wrap the `.borrow[_mut]()` call in a block instead of explicitly dropping the ref.
6885
///
6986
/// ### Example
70-
/// ```rust,ignore
71-
/// use std::cell::RefCell;
72-
///
87+
/// ```rust
88+
/// # use std::cell::RefCell;
89+
/// # async fn baz() {}
7390
/// async fn foo(x: &RefCell<u32>) {
7491
/// let mut y = x.borrow_mut();
7592
/// *y += 1;
76-
/// bar.await;
93+
/// baz().await;
94+
/// }
95+
///
96+
/// async fn bar(x: &RefCell<u32>) {
97+
/// let mut y = x.borrow_mut();
98+
/// *y += 1;
99+
/// drop(y); // explicit drop
100+
/// baz().await;
77101
/// }
78102
/// ```
79103
///
80104
/// Use instead:
81-
/// ```rust,ignore
82-
/// use std::cell::RefCell;
83-
///
105+
/// ```rust
106+
/// # use std::cell::RefCell;
107+
/// # async fn baz() {}
84108
/// async fn foo(x: &RefCell<u32>) {
85109
/// {
86110
/// let mut y = x.borrow_mut();
87111
/// *y += 1;
88112
/// }
89-
/// bar.await;
113+
/// baz().await;
114+
/// }
115+
///
116+
/// async fn bar(x: &RefCell<u32>) {
117+
/// {
118+
/// let mut y = x.borrow_mut();
119+
/// *y += 1;
120+
/// } // y dropped here at end of scope
121+
/// baz().await;
90122
/// }
91123
/// ```
92124
#[clippy::version = "1.49.0"]
93125
pub AWAIT_HOLDING_REFCELL_REF,
94-
pedantic,
95-
"Inside an async function, holding a RefCell ref while calling await"
126+
suspicious,
127+
"inside an async function, holding a `RefCell` ref while calling `await`"
96128
}
97129

98130
declare_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF]);
@@ -118,23 +150,36 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
118150
for ty_cause in ty_causes {
119151
if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() {
120152
if is_mutex_guard(cx, adt.did) {
121-
span_lint_and_note(
153+
span_lint_and_then(
122154
cx,
123155
AWAIT_HOLDING_LOCK,
124156
ty_cause.span,
125-
"this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await",
126-
ty_cause.scope_span.or(Some(span)),
127-
"these are all the await points this lock is held through",
157+
"this `MutexGuard` is held across an `await` point",
158+
|diag| {
159+
diag.help(
160+
"consider using an async-aware `Mutex` type or ensuring the \
161+
`MutexGuard` is dropped before calling await",
162+
);
163+
diag.span_note(
164+
ty_cause.scope_span.unwrap_or(span),
165+
"these are all the `await` points this lock is held through",
166+
);
167+
},
128168
);
129169
}
130170
if is_refcell_ref(cx, adt.did) {
131-
span_lint_and_note(
171+
span_lint_and_then(
132172
cx,
133173
AWAIT_HOLDING_REFCELL_REF,
134174
ty_cause.span,
135-
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
136-
ty_cause.scope_span.or(Some(span)),
137-
"these are all the await points this ref is held through",
175+
"this `RefCell` reference is held across an `await` point",
176+
|diag| {
177+
diag.help("ensure the reference is dropped before calling `await`");
178+
diag.span_note(
179+
ty_cause.scope_span.unwrap_or(span),
180+
"these are all the `await` points this reference is held through",
181+
);
182+
},
138183
);
139184
}
140185
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! lint on missing cargo common metadata
2+
3+
use cargo_metadata::Metadata;
4+
use clippy_utils::diagnostics::span_lint;
5+
use rustc_lint::LateContext;
6+
use rustc_span::source_map::DUMMY_SP;
7+
8+
use super::CARGO_COMMON_METADATA;
9+
10+
pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: bool) {
11+
for package in &metadata.packages {
12+
// only run the lint if publish is `None` (`publish = true` or skipped entirely)
13+
// or if the vector isn't empty (`publish = ["something"]`)
14+
if package.publish.as_ref().filter(|publish| publish.is_empty()).is_none() || ignore_publish {
15+
if is_empty_str(&package.description) {
16+
missing_warning(cx, package, "package.description");
17+
}
18+
19+
if is_empty_str(&package.license) && is_empty_str(&package.license_file) {
20+
missing_warning(cx, package, "either package.license or package.license_file");
21+
}
22+
23+
if is_empty_str(&package.repository) {
24+
missing_warning(cx, package, "package.repository");
25+
}
26+
27+
if is_empty_str(&package.readme) {
28+
missing_warning(cx, package, "package.readme");
29+
}
30+
31+
if is_empty_vec(&package.keywords) {
32+
missing_warning(cx, package, "package.keywords");
33+
}
34+
35+
if is_empty_vec(&package.categories) {
36+
missing_warning(cx, package, "package.categories");
37+
}
38+
}
39+
}
40+
}
41+
42+
fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) {
43+
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
44+
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message);
45+
}
46+
47+
fn is_empty_str<T: AsRef<std::ffi::OsStr>>(value: &Option<T>) -> bool {
48+
value.as_ref().map_or(true, |s| s.as_ref().is_empty())
49+
}
50+
51+
fn is_empty_vec(value: &[String]) -> bool {
52+
// This works because empty iterators return true
53+
value.iter().all(String::is_empty)
54+
}

0 commit comments

Comments
 (0)