Skip to content

Commit 77746b9

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rustup
2 parents df85532 + 9c9aa2d commit 77746b9

Some content is hidden

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

57 files changed

+2076
-393
lines changed

CHANGELOG.md

+6
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

clippy_lints/src/await_holding_lock.rs renamed to 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+
}

clippy_lints/src/functions.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,8 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet<
579579
if let hir::PatKind::Wild = pat.kind {
580580
return false; // ignore `_` patterns
581581
}
582-
let def_id = pat.hir_id.owner.to_def_id();
583-
if cx.tcx.has_typeck_results(def_id) {
584-
is_mutable_ty(cx, &cx.tcx.typeck(def_id.expect_local()).pat_ty(pat), pat.span, tys)
582+
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
583+
is_mutable_ty(cx, &cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys)
585584
} else {
586585
false
587586
}
@@ -694,11 +693,10 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
694693
Call(_, args) | MethodCall(_, _, args, _) => {
695694
let mut tys = FxHashSet::default();
696695
for arg in args {
697-
let def_id = arg.hir_id.owner.to_def_id();
698-
if self.cx.tcx.has_typeck_results(def_id)
696+
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
699697
&& is_mutable_ty(
700698
self.cx,
701-
self.cx.tcx.typeck(def_id.expect_local()).expr_ty(arg),
699+
self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg),
702700
arg.span,
703701
&mut tys,
704702
)

clippy_lints/src/future_not_send.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9292
|db| {
9393
cx.tcx.infer_ctxt().enter(|infcx| {
9494
for FulfillmentError { obligation, .. } in send_errors {
95-
infcx.maybe_note_obligation_cause_for_async_await(
96-
db,
97-
&obligation,
98-
);
99-
if let Trait(trait_pred, _) =
100-
obligation.predicate.skip_binders()
101-
{
95+
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
96+
if let Trait(trait_pred, _) = obligation.predicate.skip_binders() {
10297
db.note(&format!(
10398
"`{}` doesn't implement `{}`",
10499
trait_pred.self_ty(),

0 commit comments

Comments
 (0)