Skip to content

Commit 77da566

Browse files
committed
Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup
2 parents 3dddf6a + 645ef50 commit 77da566

File tree

84 files changed

+2832
-672
lines changed

Some content is hidden

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

84 files changed

+2832
-672
lines changed

Diff for: src/tools/clippy/.github/driver.sh

+9-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ sysroot=$(./target/debug/clippy-driver --print sysroot)
77
test "$sysroot" = "$(rustc --print sysroot)"
88

99
if [[ ${OS} == "Windows" ]]; then
10-
desired_sysroot=C:/tmp
10+
desired_sysroot=C:/tmp
1111
else
12-
desired_sysroot=/tmp
12+
desired_sysroot=/tmp
1313
fi
1414
sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot)
1515
test "$sysroot" = $desired_sysroot
@@ -22,20 +22,18 @@ unset CARGO_MANIFEST_DIR
2222

2323
# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
2424
# FIXME: How to match the clippy invocation in compile-test.rs?
25-
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cast.rs 2> cast.stderr && exit 1
26-
sed -e "s,tests/ui,\$DIR," -e "/= help/d" cast.stderr > normalized.stderr
27-
diff normalized.stderr tests/ui/cast.stderr
28-
25+
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2>double_neg.stderr && exit 1
26+
sed -e "s,tests/ui,\$DIR," -e "/= help/d" double_neg.stderr >normalized.stderr
27+
diff normalized.stderr tests/ui/double_neg.stderr
2928

3029
# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
31-
SYSROOT=`rustc --print sysroot`
30+
SYSROOT=$(rustc --print sysroot)
3231
diff <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)
3332

34-
35-
echo "fn main() {}" > target/driver_test.rs
33+
echo "fn main() {}" >target/driver_test.rs
3634
# we can't run 2 rustcs on the same file at the same time
37-
CLIPPY=`LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc`
38-
RUSTC=`rustc ./target/driver_test.rs`
35+
CLIPPY=$(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc)
36+
RUSTC=$(rustc ./target/driver_test.rs)
3937
diff <($CLIPPY) <($RUSTC)
4038

4139
# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR

Diff for: src/tools/clippy/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@ Released 2018-09-13
16321632
[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops
16331633
[`async_yields_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async
16341634
[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock
1635+
[`await_holding_refcell_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref
16351636
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
16361637
[`bind_instead_of_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map
16371638
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
@@ -1779,6 +1780,7 @@ Released 2018-09-13
17791780
[`large_digit_groups`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_digit_groups
17801781
[`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
17811782
[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays
1783+
[`large_types_passed_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value
17821784
[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
17831785
[`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
17841786
[`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
@@ -1793,6 +1795,7 @@ Released 2018-09-13
17931795
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
17941796
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
17951797
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
1798+
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
17961799
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
17971800
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
17981801
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
@@ -1841,6 +1844,7 @@ Released 2018-09-13
18411844
[`must_use_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_unit
18421845
[`mut_from_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref
18431846
[`mut_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mut
1847+
[`mut_mutex_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mutex_lock
18441848
[`mut_range_bound`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound
18451849
[`mutable_key_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type
18461850
[`mutex_atomic`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_atomic
@@ -1936,6 +1940,7 @@ Released 2018-09-13
19361940
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
19371941
[`single_char_push_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str
19381942
[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
1943+
[`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop
19391944
[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match
19401945
[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
19411946
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next
@@ -1979,6 +1984,7 @@ Released 2018-09-13
19791984
[`try_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#try_err
19801985
[`type_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
19811986
[`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds
1987+
[`undropped_manually_drops`]: https://rust-lang.github.io/rust-clippy/master/index.html#undropped_manually_drops
19821988
[`unicode_not_nfc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unicode_not_nfc
19831989
[`unimplemented`]: https://rust-lang.github.io/rust-clippy/master/index.html#unimplemented
19841990
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
@@ -2011,6 +2017,7 @@ Released 2018-09-13
20112017
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
20122018
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
20132019
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
2020+
[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings
20142021
[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result
20152022
[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
20162023
[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug

Diff for: src/tools/clippy/clippy_lints/src/await_holding_lock.rs renamed to src/tools/clippy/clippy_lints/src/await_holding_invalid.rs

+56-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,52 @@ declare_clippy_lint! {
4545
/// }
4646
/// ```
4747
pub AWAIT_HOLDING_LOCK,
48-
pedantic,
48+
correctness,
4949
"Inside an async function, holding a MutexGuard while calling await"
5050
}
5151

52-
declare_lint_pass!(AwaitHoldingLock => [AWAIT_HOLDING_LOCK]);
52+
declare_clippy_lint! {
53+
/// **What it does:** Checks for calls to await while holding a
54+
/// `RefCell` `Ref` or `RefMut`.
55+
///
56+
/// **Why is this bad?** `RefCell` refs only check for exclusive mutable access
57+
/// at runtime. Holding onto a `RefCell` ref across an `await` suspension point
58+
/// risks panics from a mutable ref shared while other refs are outstanding.
59+
///
60+
/// **Known problems:** None.
61+
///
62+
/// **Example:**
63+
///
64+
/// ```rust,ignore
65+
/// use std::cell::RefCell;
66+
///
67+
/// async fn foo(x: &RefCell<u32>) {
68+
/// let b = x.borrow_mut()();
69+
/// *ref += 1;
70+
/// bar.await;
71+
/// }
72+
/// ```
73+
///
74+
/// Use instead:
75+
/// ```rust,ignore
76+
/// use std::cell::RefCell;
77+
///
78+
/// async fn foo(x: &RefCell<u32>) {
79+
/// {
80+
/// let b = x.borrow_mut();
81+
/// *ref += 1;
82+
/// }
83+
/// bar.await;
84+
/// }
85+
/// ```
86+
pub AWAIT_HOLDING_REFCELL_REF,
87+
correctness,
88+
"Inside an async function, holding a RefCell ref while calling await"
89+
}
5390

54-
impl LateLintPass<'_> for AwaitHoldingLock {
91+
declare_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF]);
92+
93+
impl LateLintPass<'_> for AwaitHolding {
5594
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
5695
use AsyncGeneratorKind::{Block, Closure, Fn};
5796
if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind {
@@ -78,6 +117,16 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
78117
"these are all the await points this lock is held through",
79118
);
80119
}
120+
if is_refcell_ref(cx, adt.did) {
121+
span_lint_and_note(
122+
cx,
123+
AWAIT_HOLDING_REFCELL_REF,
124+
ty_cause.span,
125+
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.",
126+
ty_cause.scope_span.or(Some(span)),
127+
"these are all the await points this ref is held through",
128+
);
129+
}
81130
}
82131
}
83132
}
@@ -90,3 +139,7 @@ fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool {
90139
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_READ_GUARD)
91140
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_WRITE_GUARD)
92141
}
142+
143+
fn is_refcell_ref(cx: &LateContext<'_>, def_id: DefId) -> bool {
144+
match_def_path(cx, def_id, &paths::REFCELL_REF) || match_def_path(cx, def_id, &paths::REFCELL_REFMUT)
145+
}

Diff for: src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ declare_clippy_lint! {
2828
///
2929
/// ```rust
3030
/// # fn somefunc() -> bool { true };
31-
///
3231
/// // Bad
3332
/// if { let x = somefunc(); x } { /* ... */ }
3433
///

0 commit comments

Comments
 (0)