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 #74324

Merged
merged 108 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
40ee620
Added a lint for .map(|x| x)
theo-lw Jun 8, 2020
80bcbf5
Merge commit 'c2c07fa9d095931eb5684a42942a7b573a0c5238' into clippyup
flip1995 Jun 23, 2020
fb4f9a0
Fix pattern match of ExprKind::MethodCall
theo-lw Jun 23, 2020
583d644
Auto merge of #5694 - wangtheo:issue-5626, r=matthiaskrgr
bors Jun 23, 2020
7c1b3aa
Record span of `const` kw in GenericParamKind
ayazhafiz Jun 21, 2020
5987c7d
cmp_owned: avoid FP when PartialEq is not implemented symmetrically
ebroto Jun 9, 2020
b498e1d
cmp_owned: reverse operands if necessary
ebroto Jun 12, 2020
6bf5434
copy_on_clone - add machine applicability
tnielens Jun 23, 2020
a14eab3
Auto merge of #5745 - montrivo:copy_on_clone, r=phansch
bors Jun 24, 2020
46d3304
Auto merge of #5701 - ebroto:4874_cmp_owned_fp, r=flip1995
bors Jun 24, 2020
fa0f1d3
Change a noun to a verb to make the sentence complete
carols10cents Jun 25, 2020
88fec89
Auto merge of #5748 - carols10cents:tiny-docs-fix, r=flip1995
bors Jun 25, 2020
f5ce0e5
rustc_lint: only query `typeck_tables_of` when a lint needs it.
eddyb Jun 25, 2020
a671ea4
Rollup merge of #73597 - ayazhafiz:i/const-span, r=ecstatic-morse
Manishearth Jun 26, 2020
81810fa
Auto merge of #73756 - Manishearth:rollup-aehswb2, r=Manishearth
bors Jun 26, 2020
3c5ee33
Update tests
ecstatic-morse Jun 26, 2020
dfecaef
typeck: adding type information to projection
Azhng Jun 24, 2020
1e861a2
Merge remote-tracking branch 'upstream/master' into rustup2
flip1995 Jun 30, 2020
ab649c9
Disable chrono integration test
flip1995 Jun 30, 2020
ccf7cb3
Auto merge of #5751 - flip1995:rustup, r=Manishearth,flip1995
bors Jun 30, 2020
814349f
Lint enabling the whole restriction group
ebroto Jun 26, 2020
c5d8f53
Move blanket_clippy_restriction_lints to "style"
ebroto Jun 27, 2020
d05d6ab
Auto merge of #5750 - ebroto:blanket_clippy_restriction_lints, r=Mani…
bors Jun 30, 2020
bff6c43
Require `or_patterns` to suggest nesting them
ebroto Jun 30, 2020
36b7983
Auto merge of #5758 - ebroto:5704_unnested_or_pats, r=flip1995
bors Jun 30, 2020
5b9c2ff
Fix multiple_crate_versions error
Jul 1, 2020
0860375
Auto merge of #5759 - mikerite:multiple_crate_versions_20200701, r=ma…
bors Jul 1, 2020
d347d0c
Deprecate regex_macro lint
phansch Jul 1, 2020
52cc5fc
Auto merge of #5760 - phansch:deprecate-regex-macro, r=Manishearth
bors Jul 1, 2020
590e07b
rustc_lint: avoid using TypeckTables::empty for LateContext.
eddyb Jun 26, 2020
30c046e
Use 'tcx for references to AccessLevels wherever possible.
eddyb Jun 25, 2020
a7c58e6
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 3, 2020
c493090
Auto merge of #5763 - flip1995:rustup, r=Manishearth
bors Jul 3, 2020
754bfb1
Add configurable threshold for `type_repetition_in_bounds` lint
ThibsG Jun 28, 2020
d5a8f03
Take generic args into account for bounded type
ThibsG Jul 3, 2020
2d5930a
Don't lint for predicates generated in macros
ThibsG Jul 3, 2020
c3c4027
Added restriction lint: pattern-type-mismatch
phaylon Nov 4, 2019
55877d7
span_help_and_lint -> span_lint_and_help
phaylon Feb 9, 2020
346ee96
Adjusted expected STDERR
phaylon Feb 10, 2020
6447507
Fix rebase fallout
flip1995 Jun 8, 2020
92ecc53
Catching up with rustc changes
phaylon Jul 1, 2020
d617551
Expanded lint documentation
phaylon Jul 1, 2020
fff8e72
Auto merge of #5761 - ThibsG:TypeRepetitionThreshold, r=flip1995
bors Jul 3, 2020
aa4bee2
LateContext has only one lifetime parameter now
phaylon Jul 3, 2020
c0fd452
fmt fix
phaylon Jul 3, 2020
57cdf2d
Auto merge of #4841 - phaylon:pattern-type-mismatch, r=flip1995
bors Jul 3, 2020
bf48a2d
Lint for if let Some(x) = ... instead of Option::map_or
JarredAllen Mar 5, 2020
82f8d4d
Stop linting on macros and correctly use braces for constructs
JarredAllen Apr 25, 2020
b85796f
Properly parenthesize to avoid operator precedence errors
JarredAllen Apr 25, 2020
88c8afd
Handle ref, mut, &, and &mut on the option
JarredAllen May 10, 2020
f73b455
Refactoring
JarredAllen May 10, 2020
7c4de9d
Refactoring pt. 2
JarredAllen May 12, 2020
5e20475
Don't lint if contains a macro
JarredAllen May 31, 2020
5150277
Used clippy to clean itself
JarredAllen May 31, 2020
93f0f5d
Last few tweaks
JarredAllen Jun 12, 2020
ccb9998
Fix compile error from library change
JarredAllen Jun 25, 2020
6ce9812
Clean existing lint code to match new lint
JarredAllen Jun 25, 2020
6e2d55c
Update compile-test to follow new lint
JarredAllen Jun 27, 2020
1c32263
Formatted updates to lints
JarredAllen Jul 1, 2020
c8f700e
Fixed compile errors
JarredAllen Jul 4, 2020
3503247
Shrink ParamEnv to 16 bytes
Mark-Simulacrum Jul 3, 2020
ac85692
Auto merge of #5301 - JarredAllen:option_if_let_else, r=flip1995
bors Jul 6, 2020
a6f1af7
Lint for x.powi(2) => x * x
thiagoarrais Apr 3, 2020
f627984
Lint (x * x + y * y).sqrt() => x.hypot(y)
thiagoarrais May 25, 2020
2e8a1be
new lint: match_like_matches_macro
robojumper Jul 5, 2020
0c8afa3
Lint x.log(b) / y.log(b) => x.log(y)
thiagoarrais Jun 1, 2020
1740dda
fix match_like_matches_macro in clippy
robojumper Jul 5, 2020
076ec87
Lint for to_radians and to_degrees
thiagoarrais Jun 10, 2020
f559682
Better copy for lint message
thiagoarrais Jun 15, 2020
db7bc6b
Place radian lints under suboptimal_flops
thiagoarrais Jun 15, 2020
6dc066f
Includes TODO comment for hypot lint
thiagoarrais Jun 17, 2020
6be9491
Reclassify powi(2) lint under suboptimal_flops
thiagoarrais Jun 22, 2020
3065201
Includes TODO for constants equivalent to π/180
thiagoarrais Jul 6, 2020
4705037
Auto merge of #73978 - Mark-Simulacrum:shrink-paramenv, r=nnethercote
bors Jul 6, 2020
245b006
Rollup merge of #73870 - sexxi-goose:projection-ty, r=nikomatsakis
Manishearth Jul 7, 2020
c41fcad
Auto merge of #74117 - Manishearth:rollup-ds7z0kx, r=Manishearth
bors Jul 7, 2020
5307cb5
Add a lint for `.repeat(1)`
giraffate Jul 4, 2020
e12a316
Auto merge of #5776 - flip1995:rustup, r=flip1995
bors Jul 8, 2020
37d75da
make match_like_matches_macro only apply to matches with a wildcard
robojumper Jul 8, 2020
db1c946
unnecessary_sort_by: avoid linting if key borrows
ebroto Jun 30, 2020
dac19e3
single_match_else - single expr/stmt else block corner case
tnielens Jul 6, 2020
45eea9a
Auto merge of #5771 - montrivo:bugfix/single-match-else, r=matthiaskrgr
bors Jul 9, 2020
c79c688
Fix a broken link in CONTRIBUTING.md
giraffate Jul 9, 2020
be88122
Auto merge of #5781 - giraffate:fix_a_broken_link, r=phansch
bors Jul 9, 2020
cf91c54
Avoid "whitelist"
tamird Jul 7, 2020
298a1fa
Move range_minus_one to pedantic
chrisduerr Jun 26, 2020
ba2a85d
Run update_lints
chrisduerr Jul 3, 2020
780a4c8
Fix typo
giraffate Jul 10, 2020
b3c7196
Fix test failures
chrisduerr Jul 10, 2020
afa4148
Fix tests a bit more
chrisduerr Jul 10, 2020
7d611d9
Auto merge of #5769 - robojumper:match_like_matches_macro, r=phansch
bors Jul 10, 2020
1eb0053
Stabilize `transmute` in constants and statics but not const fn
oli-obk Aug 30, 2019
1b3bc16
Fix out of bounds access by checking length equality BEFORE accessing…
matthiaskrgr Jul 11, 2020
b57ceb4
Rollup merge of #72920 - oli-obk:const_transmute, r=RalfJung
Manishearth Jul 11, 2020
2c5f8ab
fix phrase in new_lint issue template
matthiaskrgr Jul 11, 2020
fa4a737
Auto merge of #5790 - flip1995:rustup, r=flip1995
bors Jul 13, 2020
75d43aa
Rollup merge of #5443 - thiagoarrais:issue-2040, r=flip1995
flip1995 Jul 13, 2020
019e281
Rollup merge of #5752 - chrisduerr:pedantic_ranges, r=flip1995
flip1995 Jul 13, 2020
32ef448
Rollup merge of #5756 - ebroto:5754_sort_by, r=flip1995
flip1995 Jul 13, 2020
26ede31
Rollup merge of #5784 - matthiaskrgr:ice_5780, r=phansch
flip1995 Jul 13, 2020
314b068
Rollup merge of #5786 - matthiaskrgr:new_lint_issue_templ, r=phansch
flip1995 Jul 13, 2020
4b87008
Auto merge of #5792 - flip1995:rollup-torc1we, r=flip1995
bors Jul 13, 2020
f2419b9
Refactoring to use `constant_context
giraffate Jul 13, 2020
ff796b6
Rename collapsable_if fix suggestion to "collapse nested if block"
bjorn3 Jun 19, 2020
b409103
Use `.is_some()` not `Some(_)`
giraffate Jul 13, 2020
12df638
Auto merge of #5773 - giraffate:repeat_once, r=flip1995
bors Jul 14, 2020
2ca58e7
Auto merge of #5732 - bjorn3:patch-1, r=flip1995
bors Jul 14, 2020
f82ac4d
Merge commit '2ca58e7dda4a9eb142599638c59dc04d15961175' into clippyup
flip1995 Jul 14, 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
2 changes: 1 addition & 1 deletion src/tools/clippy/.github/ISSUE_TEMPLATE/new_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ labels: L-lint

- Kind: *See <https://github.com/rust-lang/rust-clippy/blob/master/README.md#clippy> for list of lint kinds*

*What benefit of this lint over old code?*
*What is the advantage of the recommended code over the original code*

For example:
- Remove bounce checking inserted by ...
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/.github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ jobs:
- 'Geal/nom'
- 'rust-lang/stdarch'
- 'serde-rs/serde'
- 'chronotope/chrono'
# FIXME: chrono currently cannot be compiled with `--all-targets`
# - 'chronotope/chrono'
- 'hyperium/hyper'
- 'rust-random/rand'
- 'rust-lang/futures-rs'
Expand Down
6 changes: 6 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ Released 2018-09-13
[`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
[`blanket_clippy_restriction_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#blanket_clippy_restriction_lints
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
Expand Down Expand Up @@ -1508,9 +1509,11 @@ Released 2018-09-13
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
[`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref
[`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool
[`match_like_matches_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
[`match_on_vec_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_on_vec_items
[`match_overlapping_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm
[`match_ref_pats`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats
Expand Down Expand Up @@ -1575,6 +1578,7 @@ Released 2018-09-13
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
[`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
[`option_env_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_env_unwrap
[`option_if_let_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_if_let_else
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none
[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
[`option_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_option
Expand All @@ -1586,6 +1590,7 @@ Released 2018-09-13
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
Expand All @@ -1612,6 +1617,7 @@ Released 2018-09-13
[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ this to work, you will need the fix of `git subtree` available
[here][gitgitgadget-pr].

[gitgitgadget-pr]: https://github.com/gitgitgadget/git/pull/493
[subtree]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#external-dependencies-subtree
[subtree]: https://rustc-dev-guide.rust-lang.org/contributing.html#external-dependencies-subtree
[`rust-lang/rust`]: https://github.com/rust-lang/rust

## Issue and PR triage
Expand Down
115 changes: 76 additions & 39 deletions src/tools/clippy/clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use crate::reexport::Name;
use crate::utils::{
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg,
span_lint_and_then, without_block_comments,
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_help,
span_lint_and_sugg, span_lint_and_then, without_block_comments,
};
use if_chain::if_chain;
use rustc_ast::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
Expand All @@ -17,7 +17,7 @@ use rustc_middle::lint::in_external_macro;
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::symbol::Symbol;
use rustc_span::symbol::{Symbol, SymbolStr};
use semver::Version;

static UNIX_SYSTEMS: &[&str] = &[
Expand Down Expand Up @@ -182,6 +182,29 @@ declare_clippy_lint! {
"unknown_lints for scoped Clippy lints"
}

declare_clippy_lint! {
/// **What it does:** Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
///
/// **Why is this bad?** Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust.
/// These lints should only be enabled on a lint-by-lint basis and with careful consideration.
///
/// **Known problems:** None.
///
/// **Example:**
/// Bad:
/// ```rust
/// #![deny(clippy::restriction)]
/// ```
///
/// Good:
/// ```rust
/// #![deny(clippy::as_conversions)]
/// ```
pub BLANKET_CLIPPY_RESTRICTION_LINTS,
style,
"enabling the complete restriction group"
}

declare_clippy_lint! {
/// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it
/// with `#[rustfmt::skip]`.
Expand Down Expand Up @@ -249,15 +272,17 @@ declare_lint_pass!(Attributes => [
DEPRECATED_SEMVER,
USELESS_ATTRIBUTE,
UNKNOWN_CLIPPY_LINTS,
BLANKET_CLIPPY_RESTRICTION_LINTS,
]);

impl<'tcx> LateLintPass<'tcx> for Attributes {
fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
if let Some(items) = &attr.meta_item_list() {
if let Some(ident) = attr.ident() {
match &*ident.as_str() {
let ident = &*ident.as_str();
match ident {
"allow" | "warn" | "deny" | "forbid" => {
check_clippy_lint_names(cx, items);
check_clippy_lint_names(cx, ident, items);
},
_ => {},
}
Expand Down Expand Up @@ -363,38 +388,43 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
}
}

#[allow(clippy::single_match_else)]
fn check_clippy_lint_names(cx: &LateContext<'_>, items: &[NestedMetaItem]) {
let lint_store = cx.lints();
for lint in items {
fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMetaItem]) {
fn extract_name(lint: &NestedMetaItem) -> Option<SymbolStr> {
if_chain! {
if let Some(meta_item) = lint.meta_item();
if meta_item.path.segments.len() > 1;
if let tool_name = meta_item.path.segments[0].ident;
if tool_name.as_str() == "clippy";
let name = meta_item.path.segments.last().unwrap().ident.name;
if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(
&name.as_str(),
Some(tool_name.name),
);
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
then {
return Some(lint_name.as_str());
}
}
None
}

let lint_store = cx.lints();
for lint in items {
if let Some(lint_name) = extract_name(lint) {
if let CheckLintNameResult::Tool(Err((None, _))) =
lint_store.check_lint_name(&lint_name, Some(sym!(clippy)))
{
span_lint_and_then(
cx,
UNKNOWN_CLIPPY_LINTS,
lint.span(),
&format!("unknown clippy lint: clippy::{}", name),
&format!("unknown clippy lint: clippy::{}", lint_name),
|diag| {
let name_lower = name.as_str().to_lowercase();
let symbols = lint_store.get_lints().iter().map(
|l| Symbol::intern(&l.name_lower())
).collect::<Vec<_>>();
let sugg = find_best_match_for_name(
symbols.iter(),
&format!("clippy::{}", name_lower),
None,
);
if name.as_str().chars().any(char::is_uppercase)
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() {
let name_lower = lint_name.to_lowercase();
let symbols = lint_store
.get_lints()
.iter()
.map(|l| Symbol::intern(&l.name_lower()))
.collect::<Vec<_>>();
let sugg = find_best_match_for_name(symbols.iter(), &format!("clippy::{}", name_lower), None);
if lint_name.chars().any(char::is_uppercase)
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok()
{
diag.span_suggestion(
lint.span(),
"lowercase the lint name",
Expand All @@ -409,10 +439,19 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, items: &[NestedMetaItem]) {
Applicability::MachineApplicable,
);
}
}
},
);
} else if lint_name == "restriction" && ident != "allow" {
span_lint_and_help(
cx,
BLANKET_CLIPPY_RESTRICTION_LINTS,
lint.span(),
"restriction lints are not meant to be all enabled",
None,
"try enabling only the lints you really need",
);
}
};
}
}
}

Expand Down Expand Up @@ -442,15 +481,14 @@ fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool {
}

fn is_relevant_block(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool {
if let Some(stmt) = block.stmts.first() {
match &stmt.kind {
block.stmts.first().map_or(
block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e)),
|stmt| match &stmt.kind {
StmtKind::Local(_) => true,
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr),
_ => false,
}
} else {
block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e))
}
},
)
}

fn is_relevant_expr(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool {
Expand All @@ -460,11 +498,10 @@ fn is_relevant_expr(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, expr: &
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
ExprKind::Call(path_expr, _) => {
if let ExprKind::Path(qpath) = &path_expr.kind {
if let Some(fun_id) = tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
!match_def_path(cx, fun_id, &paths::BEGIN_PANIC)
} else {
true
}
tables
.qpath_res(qpath, path_expr.hir_id)
.opt_def_id()
.map_or(true, |fun_id| !match_def_path(cx, fun_id, &paths::BEGIN_PANIC))
} else {
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/await_holding_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare_clippy_lint! {
/// non-async-aware MutexGuard.
///
/// **Why is this bad?** The Mutex types found in syd::sync and parking_lot
/// are not designed to operator in an async context across await points.
/// are not designed to operate in an async context across await points.
///
/// There are two potential solutions. One is to use an asynx-aware Mutex
/// type. Many asynchronous foundation crates provide such a Mutex type. The
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/collapsible_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
COLLAPSIBLE_IF,
block.span,
"this `else { if .. }` block can be collapsed",
"try",
"collapse nested if block",
snippet_block_with_applicability(cx, else_.span, "..", Some(block.span), &mut applicability).into_owned(),
applicability,
);
Expand All @@ -142,7 +142,7 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
let rhs = Sugg::ast(cx, check_inner, "..");
diag.span_suggestion(
expr.span,
"try",
"collapse nested if block",
format!(
"if {} {}",
lhs.and(&rhs),
Expand Down
5 changes: 1 addition & 4 deletions src/tools/clippy/clippy_lints/src/comparison_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,5 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
}

fn kind_is_cmp(kind: BinOpKind) -> bool {
match kind {
BinOpKind::Lt | BinOpKind::Gt | BinOpKind::Eq => true,
_ => false,
}
matches!(kind, BinOpKind::Lt | BinOpKind::Gt | BinOpKind::Eq)
}
10 changes: 9 additions & 1 deletion src/tools/clippy/clippy_lints/src/deprecated_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,13 @@ declare_deprecated_lint! {
///
/// **Deprecation reason:** Associated-constants are now preferred.
pub REPLACE_CONSTS,
"associated-constants `MIN`/`MAX` of integers are prefer to `{min,max}_value()` and module constants"
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
}

declare_deprecated_lint! {
/// **What it does:** Nothing. This lint has been deprecated.
///
/// **Deprecation reason:** The regex! macro does not exist anymore.
pub REGEX_MACRO,
"the regex! macro has been removed from the regex crate in 2018"
}
10 changes: 6 additions & 4 deletions src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) {
match method_name {
"deref" => {
if cx.tcx.lang_items().deref_trait().map_or(false, |id| {
let impls_deref_trait = cx.tcx.lang_items().deref_trait().map_or(false, |id| {
implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[])
}) {
});
if impls_deref_trait {
span_lint_and_sugg(
cx,
EXPLICIT_DEREF_METHODS,
Expand All @@ -88,9 +89,10 @@ fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var
}
},
"deref_mut" => {
if cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| {
let impls_deref_mut_trait = cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| {
implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[])
}) {
});
if impls_deref_mut_trait {
span_lint_and_sugg(
cx,
EXPLICIT_DEREF_METHODS,
Expand Down
30 changes: 15 additions & 15 deletions src/tools/clippy/clippy_lints/src/eq_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,20 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
}

fn is_valid_operator(op: BinOp) -> bool {
match op.node {
matches!(
op.node,
BinOpKind::Sub
| BinOpKind::Div
| BinOpKind::Eq
| BinOpKind::Lt
| BinOpKind::Le
| BinOpKind::Gt
| BinOpKind::Ge
| BinOpKind::Ne
| BinOpKind::And
| BinOpKind::Or
| BinOpKind::BitXor
| BinOpKind::BitAnd
| BinOpKind::BitOr => true,
_ => false,
}
| BinOpKind::Div
| BinOpKind::Eq
| BinOpKind::Lt
| BinOpKind::Le
| BinOpKind::Gt
| BinOpKind::Ge
| BinOpKind::Ne
| BinOpKind::And
| BinOpKind::Or
| BinOpKind::BitXor
| BinOpKind::BitAnd
| BinOpKind::BitOr
)
}
5 changes: 1 addition & 4 deletions src/tools/clippy/clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
_ => return false,
}

match map.find(map.get_parent_node(id)) {
Some(Node::Param(_)) => true,
_ => false,
}
matches!(map.find(map.get_parent_node(id)), Some(Node::Param(_)))
}

impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
Expand Down
Loading