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 - temporary_cstring_as_ptr deprecation #78505

Merged
merged 82 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
bb0ce32
Lint unnecessary int-to-int and float-to-float casts
geoffreycopin Oct 15, 2020
915ce36
manual_unwrap_or / support Result::unwrap_or
tnielens Oct 17, 2020
114cb21
Remove an extra blank line in doc examples
giraffate Oct 19, 2020
ec23db9
Add linter for a single element for loop
patrickelectric Oct 3, 2020
ba1ca19
tests: if_same_then_else2: Ignore single_element_loop lint
patrickelectric Oct 3, 2020
65b52d8
needless-lifetime / multiple where clause predicates regression
tnielens Oct 19, 2020
57bf80f
Add lint for holding RefCell Ref across an await
Sep 10, 2020
8727169
fmt
Sep 10, 2020
070a751
update_lints
Sep 10, 2020
0f4abbf
Better naming post copy/paste
Sep 28, 2020
b3a427d
Add another test case
Sep 28, 2020
3ed69cd
Move existing lint into shared file
Oct 13, 2020
ee20eba
Move refcell lint into shared module
Oct 13, 2020
d8c6bce
Convert the await holding lints to correctness
Oct 13, 2020
86f2b29
Merge lints into one pass
Oct 19, 2020
4d33225
Separate tests for each lint
Oct 19, 2020
4a4f998
Add new lint for undropped ManuallyDrop values
cgm616 Oct 16, 2020
e70817e
Update tests and add known problems to docs
cgm616 Oct 16, 2020
c693de3
New lint: manual-range-contains
llogiq Oct 15, 2020
f2da0c7
manual-unwrap-or / pr remarks
tnielens Oct 22, 2020
6533d8b
manual-unwrap-or / pr remarks, round 2
tnielens Oct 22, 2020
e8f12d2
Address review comments
geoffreycopin Oct 22, 2020
02f0110
Add test case for negative literals
geoffreycopin Oct 22, 2020
30f80c3
Fix test file
geoffreycopin Oct 22, 2020
3807634
clippy_lints: Update empty_loop lint
josephlr Oct 11, 2020
cdb555f
Merge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup
ebroto Oct 23, 2020
6caeed1
Remove duplicate import of `Target`
ebroto Oct 23, 2020
d46edd9
Keep sign in int-to-float casts
geoffreycopin Oct 23, 2020
62f60e1
No lint with `cfg!` and fix sugg for macro in `needless_bool` lint
ThibsG Oct 24, 2020
0d21ae0
manual-unwrap-or / pr remarks, round 3
tnielens Oct 24, 2020
71ac0c0
Keep separators in cast_size_32bits stderr
geoffreycopin Oct 24, 2020
33f3cfc
Fix inconsistencies in handling of inert attributes on statements
Aaron1011 Oct 23, 2020
e8731a9
Add large_types_passed_by_value lint
cauebs Oct 8, 2020
5c78d26
Auto merge of #6135 - cauebs:master, r=ebroto
bors Oct 24, 2020
29979ad
Auto merge of #6190 - montrivo:manual_result_unwrap_or, r=ebroto
bors Oct 24, 2020
b06856e
Auto merge of #6187 - geoffreycopin:master, r=ebroto
bors Oct 24, 2020
a675778
Auto merge of #6029 - Daniel-B-Smith:refcell_ref_await, r=flip1995
bors Oct 25, 2020
e0e617a
Auto merge of #6109 - patrickelectric:single_element_for_check, r=fli…
bors Oct 25, 2020
f82f9c2
Add lint for `&mut Mutex::lock`
FrancisMurillo Oct 2, 2020
6b01c39
Auto merge of #6181 - cgm616:undropped-manually-drops, r=flip1995
bors Oct 25, 2020
fb8a9cb
Change lint doc test
FrancisMurillo Oct 2, 2020
ec0c3af
Run update_lints
FrancisMurillo Oct 2, 2020
77e34a6
Inline is_mut_mutex_lock_call
FrancisMurillo Oct 5, 2020
292cb9b
Use `sugg_lint_and_help`
FrancisMurillo Oct 10, 2020
e7e03b7
Change from correctness to style and MaybeIncorrect instead of Machin…
FrancisMurillo Oct 18, 2020
df85532
Rollup merge of #78326 - Aaron1011:fix/min-stmt-lints, r=petrochenkov
JohnTitor Oct 25, 2020
fd62c18
Auto merge of #6162 - josephlr:empty-loop-no-std, r=flip1995
bors Oct 25, 2020
399732b
Auto merge of #6103 - FrancisMurillo:mut_mutex_lock, r=flip1995
bors Oct 25, 2020
d571389
Remove redundant `expect_local()` call
JohnTitor Oct 25, 2020
90cb25d
Auto merge of #6177 - rust-lang:manual-range-contains, r=flip1995
bors Oct 25, 2020
38be214
Auto merge of #6198 - montrivo:needless-lifetime, r=flip1995
bors Oct 25, 2020
718bb28
Auto merge of #6211 - ThibsG:NeedlessBoolCfg, r=flip1995
bors Oct 25, 2020
9c9aa2d
Auto merge of #6222 - JohnTitor:redundant-local-def-id, r=flip1995
bors Oct 25, 2020
db8380c
Add lint for unusually-grouped hex/binary literals
fhartwig Oct 31, 2018
f5a88b6
Allow hex literals to pass w/ groups of 2
cgm616 Oct 25, 2020
0c0f8db
Remove accidental test inclusion
cgm616 Oct 25, 2020
e7e4b35
Fix logic mistake
cgm616 Oct 25, 2020
3ce820b
Fix an invalid suggestion in `needless_collect` test
giraffate Oct 21, 2020
2f5d418
Add test case
giraffate Oct 25, 2020
312bbff
Integrate suggestions from code review
cgm616 Oct 25, 2020
77746b9
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Oct 25, 2020
4242ef8
Auto merge of #6224 - flip1995:rustup, r=flip1995
bors Oct 25, 2020
eceebc3
Auto merge of #6183 - cgm616:hex_bin_digit_grouping, r=flip1995
bors Oct 25, 2020
15f6fb9
Auto merge of #6194 - giraffate:remove_an_extra_blank_line, r=flip1995
bors Oct 25, 2020
83bb5ec
Auto merge of #6202 - giraffate:fix_invalid_suggestion_in_needless_co…
bors Oct 25, 2020
80b2168
Update triagebot.toml
flip1995 Oct 25, 2020
afbac89
Auto merge of #6225 - rust-lang:flip1995-patch-1, r=flip1995
bors Oct 25, 2020
a1bb10e
Remove lint from clippy
nathanwhit Sep 22, 2020
66d56fe
Add `invalid_paths` internal lint
Oct 27, 2020
f79c4af
Fix invalid paths
Oct 27, 2020
8823684
Auto merge of #6244 - mikerite:invalid_paths_20201027, r=flip1995
bors Oct 27, 2020
09e7053
simplify SpanlessEq::eq_path_segment
alex-700 Oct 24, 2020
2b7dd31
improve MATCH_LIKE_MATCHES_MACRO lint
alex-700 Oct 24, 2020
de83f09
Auto merge of #6216 - alex-700:improve-match-like-matches-lint, r=ebroto
bors Oct 27, 2020
8e988e1
Merge remote-tracking branch 'upstream/master' into sync-from-rust
giraffate Oct 28, 2020
dace756
cargo dev update_lints
giraffate Oct 28, 2020
ffc2e66
Fix reference
giraffate Oct 28, 2020
c42a22d
Use `double_neg.stderr`
giraffate Oct 28, 2020
a50d9e7
Deprecate temporary_cstr_as_ptr
ebroto Oct 28, 2020
e83e79f
Reinstate link to temporary_cstr_as_ptr
ebroto Oct 28, 2020
645ef50
Auto merge of #6257 - giraffate:sync-from-rust, r=ebroto
bors Oct 28, 2020
77da566
Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup
ebroto Oct 28, 2020
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
20 changes: 9 additions & 11 deletions src/tools/clippy/.github/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ sysroot=$(./target/debug/clippy-driver --print sysroot)
test "$sysroot" = "$(rustc --print sysroot)"

if [[ ${OS} == "Windows" ]]; then
desired_sysroot=C:/tmp
desired_sysroot=C:/tmp
else
desired_sysroot=/tmp
desired_sysroot=/tmp
fi
sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot)
test "$sysroot" = $desired_sysroot
Expand All @@ -22,20 +22,18 @@ unset CARGO_MANIFEST_DIR

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

./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2>double_neg.stderr && exit 1
sed -e "s,tests/ui,\$DIR," -e "/= help/d" double_neg.stderr >normalized.stderr
diff normalized.stderr tests/ui/double_neg.stderr

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


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

# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
7 changes: 7 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@ Released 2018-09-13
[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops
[`async_yields_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async
[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock
[`await_holding_refcell_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
[`bind_instead_of_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
Expand Down Expand Up @@ -1779,6 +1780,7 @@ Released 2018-09-13
[`large_digit_groups`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_digit_groups
[`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays
[`large_types_passed_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value
[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
[`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
[`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
Expand All @@ -1793,6 +1795,7 @@ Released 2018-09-13
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
Expand Down Expand Up @@ -1841,6 +1844,7 @@ Released 2018-09-13
[`must_use_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_unit
[`mut_from_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref
[`mut_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mut
[`mut_mutex_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mutex_lock
[`mut_range_bound`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound
[`mutable_key_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type
[`mutex_atomic`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_atomic
Expand Down Expand Up @@ -1936,6 +1940,7 @@ Released 2018-09-13
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
[`single_char_push_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str
[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
[`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop
[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match
[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next
Expand Down Expand Up @@ -1979,6 +1984,7 @@ Released 2018-09-13
[`try_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#try_err
[`type_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
[`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds
[`undropped_manually_drops`]: https://rust-lang.github.io/rust-clippy/master/index.html#undropped_manually_drops
[`unicode_not_nfc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unicode_not_nfc
[`unimplemented`]: https://rust-lang.github.io/rust-clippy/master/index.html#unimplemented
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
Expand Down Expand Up @@ -2011,6 +2017,7 @@ Released 2018-09-13
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings
[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result
[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,52 @@ declare_clippy_lint! {
/// }
/// ```
pub AWAIT_HOLDING_LOCK,
pedantic,
correctness,
"Inside an async function, holding a MutexGuard while calling await"
}

declare_lint_pass!(AwaitHoldingLock => [AWAIT_HOLDING_LOCK]);
declare_clippy_lint! {
/// **What it does:** 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:** None.
///
/// **Example:**
///
/// ```rust,ignore
/// use std::cell::RefCell;
///
/// async fn foo(x: &RefCell<u32>) {
/// let b = x.borrow_mut()();
/// *ref += 1;
/// bar.await;
/// }
/// ```
///
/// Use instead:
/// ```rust,ignore
/// use std::cell::RefCell;
///
/// async fn foo(x: &RefCell<u32>) {
/// {
/// let b = x.borrow_mut();
/// *ref += 1;
/// }
/// bar.await;
/// }
/// ```
pub AWAIT_HOLDING_REFCELL_REF,
correctness,
"Inside an async function, holding a RefCell ref while calling await"
}

impl LateLintPass<'_> for AwaitHoldingLock {
declare_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF]);

impl LateLintPass<'_> for AwaitHolding {
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
use AsyncGeneratorKind::{Block, Closure, Fn};
if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind {
Expand All @@ -78,6 +117,16 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
"these are all the await points this lock is held through",
);
}
if is_refcell_ref(cx, adt.did) {
span_lint_and_note(
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",
);
}
}
}
}
Expand All @@ -90,3 +139,7 @@ fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool {
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_READ_GUARD)
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_WRITE_GUARD)
}

fn is_refcell_ref(cx: &LateContext<'_>, def_id: DefId) -> bool {
match_def_path(cx, def_id, &paths::REFCELL_REF) || match_def_path(cx, def_id, &paths::REFCELL_REFMUT)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ declare_clippy_lint! {
///
/// ```rust
/// # fn somefunc() -> bool { true };
///
/// // Bad
/// if { let x = somefunc(); x } { /* ... */ }
///
Expand Down
Loading