Skip to content

Commit 25a9193

Browse files
committed
2 parents adb2918 + de83f09 commit 25a9193

File tree

86 files changed

+2809
-664
lines changed

Some content is hidden

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

86 files changed

+2809
-664
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
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

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ If you have @bors permissions, you can find an overview of the available
316316
commands [here][homu_instructions].
317317
318318
[triage]: https://forge.rust-lang.org/release/triage-procedure.html
319-
[l-crash]: https://github.com/rust-lang/rust-clippy/labels/L-crash%20%3Aboom%3A
320-
[l-bug]: https://github.com/rust-lang/rust-clippy/labels/L-bug%20%3Abeetle%3A
319+
[l-crash]: https://github.com/rust-lang/rust-clippy/labels/L-crash
320+
[l-bug]: https://github.com/rust-lang/rust-clippy/labels/L-bug
321321
[homu]: https://github.com/rust-lang/homu
322322
[homu_instructions]: https://buildbot2.rust-lang.org/homu/
323323
[homu_queue]: https://buildbot2.rust-lang.org/homu/queue/clippy

clippy_lints/src/await_holding_lock.rs renamed to clippy_lints/src/await_holding_invalid.rs

Lines changed: 56 additions & 3 deletions
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+
}

clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 0 additions & 1 deletion
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)