Skip to content

Commit 6567459

Browse files
committed
submodules: update clippy from 891e1a8 to b7c802b
Changes: ```` rustup to rust-lang/rust#70043 map_clone: avoid suggesting `copied()` for &mut fix redundant_pattern_matching lint Add tests for rust-lang#1654 Don't trigger while_let_on_iterator when the iterator is recreated every iteration Update issue_2356.stderr reference file Update while_let_on_iterator tests Fix while_let_on_iterator suggestion and make it MachineApplicable Add lifetime test case for `new_ret_no_self` rustup rust-lang/rust#71215 Downgrade match_bool to pedantic Run fetch before testing if master contains beta The beta branch update should not require a force push Add a note to the beta sections of release.md Remove apt-get upgrade again Always use the deploy script and templates of the master branch README: fix lit count line clippy_dev: make it fatal when the regex for updating lint count does not match `predecessors_for` will be removed soon Rustup "Remove `BodyAndCache`" Only run (late) internal lints, when they are warn/deny/forbid Only run cargo lints, when they are warn/deny/forbid span_lint_and_note now takes an Option<Span> for the note_span instead of just a span Make lint also capture blocks and closures, adjust language to mention other mutex types don't test the code in the lint docs Switch to matching against full paths instead of just the last element of the path Lint for holding locks across await points Also mention `--fix` for nightly users fix crash on issue-69020-assoc-const-arith-overflow.rs Address review comments remark fixes Update CHANGELOG.md for Rust 1.43 and 1.44 update stderr file util/fetch_prs_between.sh: Add Markdown formatted Link factor ifs into function, add differing mutex test Update the changelog update documentation Apply suggestions from PR review update span_lint_and_help call to six args test for mutex eq, add another test case use if chain cargo dev fmt fix map import to rustc_middle dev update_lints fix internal clippy warnings change visitor name to OppVisitor use Visitor api to find Mutex::lock calls add note about update-all-refs script, revert redundant pat to master move closures to seperate fns, remove known problems use span_lint_and_help, cargo dev fmt creating suggestion progress work on suggestion for auto fix Implement unsafe_derive_deserialize lint Update empty_enum.stderr Formatting and naming Formatting and naming Cleanup: `node_id` -> `hir_id` Fix issue rust-lang#2907. Don't trigger toplevel_ref_arg for `for` loops Cleanup: future_not_send: use `return_ty` method Remove badge FIXME from Cargo.toml Change note_span argument for span_lint_and_note. Add an Option<Span> argument to span_lint_and_help. Fixes internal lint warning in code base. Implement collapsible_span_lint_calls lint. ```` Fixes #71453
1 parent 6b96dd1 commit 6567459

File tree

113 files changed

+2216
-432
lines changed

Some content is hidden

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

113 files changed

+2216
-432
lines changed

.github/workflows/clippy_bors.yml

-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ jobs:
7777
run: |
7878
sudo dpkg --add-architecture i386
7979
sudo apt-get update
80-
# perform system upgrade to work around https://github.com/rust-lang/rust-clippy/issues/5477 , revert as soon as that is fixed
81-
sudo apt-get -y upgrade
8280
sudo apt-get install gcc-multilib libssl-dev:i386 libgit2-dev:i386
8381
if: matrix.host == 'i686-unknown-linux-gnu'
8482

.github/workflows/deploy.yml

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ jobs:
3838
- name: Set beta to true
3939
if: github.ref == 'refs/heads/beta'
4040
run: echo "::set-env name=BETA::true"
41+
42+
- name: Use scripts and templates from master branch
43+
run: |
44+
git fetch --no-tags --prune --depth=1 origin master
45+
git checkout origin/master -- .github/deploy.sh util/gh-pages/ util/*.py
46+
4147
- name: Deploy
4248
run: |
4349
eval "$(ssh-agent -s)"

CHANGELOG.md

+91-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,98 @@ All notable changes to this project will be documented in this file.
44
See [Changelog Update](doc/changelog_update.md) if you want to update this
55
document.
66

7-
## Unreleased / In Rust Beta or Nightly
7+
## Unreleased / In Rust Nightly
88

9-
[329923e...master](https://github.com/rust-lang/rust-clippy/compare/329923e...master)
9+
[891e1a8...master](https://github.com/rust-lang/rust-clippy/compare/891e1a8...master)
10+
11+
## Rust 1.44
12+
13+
Current beta, release 2020-06-04
14+
15+
[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8)
16+
17+
### New lints
18+
19+
* [`explicit_deref_methods`] [#5226](https://github.com/rust-lang/rust-clippy/pull/5226)
20+
* [`implicit_saturating_sub`] [#5427](https://github.com/rust-lang/rust-clippy/pull/5427)
21+
* [`macro_use_imports`] [#5230](https://github.com/rust-lang/rust-clippy/pull/5230)
22+
* [`verbose_file_reads`] [#5272](https://github.com/rust-lang/rust-clippy/pull/5272)
23+
* [`future_not_send`] [#5423](https://github.com/rust-lang/rust-clippy/pull/5423)
24+
* [`redundant_pub_crate`] [#5319](https://github.com/rust-lang/rust-clippy/pull/5319)
25+
* [`large_const_arrays`] [#5248](https://github.com/rust-lang/rust-clippy/pull/5248)
26+
* [`result_map_or_into_option`] [#5415](https://github.com/rust-lang/rust-clippy/pull/5415)
27+
* [`redundant_allocation`] [#5349](https://github.com/rust-lang/rust-clippy/pull/5349)
28+
* [`fn_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294)
29+
* [`vtable_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294)
30+
31+
32+
### Moves and Deprecations
33+
34+
* Deprecate [`replace_consts`] lint [#5380](https://github.com/rust-lang/rust-clippy/pull/5380)
35+
* Move [`cognitive_complexity`] to nursery [#5428](https://github.com/rust-lang/rust-clippy/pull/5428)
36+
* Move [`useless_transmute`] to nursery [#5364](https://github.com/rust-lang/rust-clippy/pull/5364)
37+
* Downgrade [`inefficient_to_string`] to pedantic [#5412](https://github.com/rust-lang/rust-clippy/pull/5412)
38+
* Downgrade [`option_option`] to pedantic [#5401](https://github.com/rust-lang/rust-clippy/pull/5401)
39+
* Downgrade [`unreadable_literal`] to pedantic [#5419](https://github.com/rust-lang/rust-clippy/pull/5419)
40+
* Downgrade [`let_unit_value`] to pedantic [#5409](https://github.com/rust-lang/rust-clippy/pull/5409)
41+
* Downgrade [`trivially_copy_pass_by_ref`] to pedantic [#5410](https://github.com/rust-lang/rust-clippy/pull/5410)
42+
* Downgrade [`implicit_hasher`] to pedantic [#5411](https://github.com/rust-lang/rust-clippy/pull/5411)
43+
44+
### Enhancements
45+
46+
* On _nightly_ you can now use `cargo clippy --fix -Z unstable-options` to
47+
auto-fix lints that support this [#5363](https://github.com/rust-lang/rust-clippy/pull/5363)
48+
* Make [`redundant_clone`] also trigger on cases where the cloned value is not
49+
consumed. [#5304](https://github.com/rust-lang/rust-clippy/pull/5304)
50+
* Expand [`integer_arithmetic`] to also disallow bit-shifting [#5430](https://github.com/rust-lang/rust-clippy/pull/5430)
51+
* [`option_as_ref_deref`] now detects more deref cases [#5425](https://github.com/rust-lang/rust-clippy/pull/5425)
52+
* [`large_enum_variant`] now report the sizes of the largest and second-largest variants [#5466](https://github.com/rust-lang/rust-clippy/pull/5466)
53+
* [`bool_comparison`] now also checks for inequality comparisons that can be
54+
written more concisely [#5365](https://github.com/rust-lang/rust-clippy/pull/5365)
55+
* Expand [`clone_on_copy`] to work in method call arguments as well [#5441](https://github.com/rust-lang/rust-clippy/pull/5441)
56+
* [`redundant_pattern_matching`] now also handles `while let` [#5483](https://github.com/rust-lang/rust-clippy/pull/5483)
57+
* [`integer_arithmetic`] now also lints references of integers [#5329](https://github.com/rust-lang/rust-clippy/pull/5329)
58+
* Expand [`float_cmp_const`] to also work on arrays [#5345](https://github.com/rust-lang/rust-clippy/pull/5345)
59+
* Trigger [`map_flatten`] when map is called on an `Option` [#5473](https://github.com/rust-lang/rust-clippy/pull/5473)
60+
61+
### False Positive Fixes
62+
63+
* [`many_single_char_names`] [#5468](https://github.com/rust-lang/rust-clippy/pull/5468)
64+
* [`should_implement_trait`] [#5437](https://github.com/rust-lang/rust-clippy/pull/5437)
65+
* [`unused_self`] [#5387](https://github.com/rust-lang/rust-clippy/pull/5387)
66+
* [`redundant_clone`] [#5453](https://github.com/rust-lang/rust-clippy/pull/5453)
67+
* [`precedence`] [#5445](https://github.com/rust-lang/rust-clippy/pull/5445)
68+
* [`suspicious_op_assign_impl`] [#5424](https://github.com/rust-lang/rust-clippy/pull/5424)
69+
* [`needless_lifetimes`] [#5293](https://github.com/rust-lang/rust-clippy/pull/5293)
70+
* [`redundant_pattern`] [#5287](https://github.com/rust-lang/rust-clippy/pull/5287)
71+
* [`inconsistent_digit_grouping`] [#5451](https://github.com/rust-lang/rust-clippy/pull/5451)
72+
73+
74+
### Suggestion Improvements
75+
76+
* Improved [`question_mark`] lint suggestion so that it doesn't add redundant `as_ref()` [#5481](https://github.com/rust-lang/rust-clippy/pull/5481)
77+
* Improve the suggested placeholder in [`option_map_unit_fn`] [#5292](https://github.com/rust-lang/rust-clippy/pull/5292)
78+
* Improve suggestion for [`match_single_binding`] when triggered inside a closure [#5350](https://github.com/rust-lang/rust-clippy/pull/5350)
79+
80+
### ICE Fixes
81+
82+
* Handle the unstable `trivial_bounds` feature [#5296](https://github.com/rust-lang/rust-clippy/pull/5296)
83+
* `shadow_*` lints [#5297](https://github.com/rust-lang/rust-clippy/pull/5297)
84+
85+
### Documentation
86+
87+
* Fix documentation generation for configurable lints [#5353](https://github.com/rust-lang/rust-clippy/pull/5353)
88+
* Update documentation for [`new_ret_no_self`] [#5448](https://github.com/rust-lang/rust-clippy/pull/5448)
89+
* The documentation for [`option_option`] now suggest using a tri-state enum [#5403](https://github.com/rust-lang/rust-clippy/pull/5403)
90+
* Fix bit mask example in [`verbose_bit_mask`] documentation [#5454](https://github.com/rust-lang/rust-clippy/pull/5454)
91+
* [`wildcard_imports`] documentation now mentions that `use ...::prelude::*` is
92+
not linted [#5312](https://github.com/rust-lang/rust-clippy/pull/5312)
1093

1194
## Rust 1.43
1295

13-
Current beta, release 2020-04-23
96+
Current stable, released 2020-04-23
1497

15-
[4ee1206...329923e](https://github.com/rust-lang/rust-clippy/compare/4ee1206...329923e)
98+
[4ee1206...204bb9b](https://github.com/rust-lang/rust-clippy/compare/4ee1206...204bb9b)
1699

17100
### New lints
18101

@@ -68,7 +151,7 @@ Current beta, release 2020-04-23
68151

69152
## Rust 1.42
70153

71-
Current stable, released 2020-03-12
154+
Released 2020-03-12
72155

73156
[69f99e7...4ee1206](https://github.com/rust-lang/rust-clippy/compare/69f99e7...4ee1206)
74157

@@ -1188,6 +1271,7 @@ Released 2018-09-13
11881271
[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
11891272
[`assign_op_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
11901273
[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops
1274+
[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock
11911275
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
11921276
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
11931277
[`block_in_if_condition_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_in_if_condition_expr
@@ -1286,6 +1370,7 @@ Released 2018-09-13
12861370
[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap
12871371
[`identity_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion
12881372
[`identity_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_op
1373+
[`if_let_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_mutex
12891374
[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching
12901375
[`if_let_some_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_some_result
12911376
[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
@@ -1524,6 +1609,7 @@ Released 2018-09-13
15241609
[`unneeded_wildcard_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_wildcard_pattern
15251610
[`unreachable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreachable
15261611
[`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal
1612+
[`unsafe_derive_deserialize`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_derive_deserialize
15271613
[`unsafe_removed_from_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_removed_from_name
15281614
[`unsafe_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_vector_initialization
15291615
[`unseparated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#unseparated_literal_suffix

Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ build = "build.rs"
1818
edition = "2018"
1919
publish = false
2020

21-
# [badges]
22-
# FIXME(flip1995): Add GHA badge once rust-lang/crates.io#1838 is merged
23-
2421
[[bin]]
2522
name = "cargo-clippy"
2623
test = false

clippy_dev/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,11 @@ where
291291
}
292292

293293
if !found {
294-
// This happens if the provided regex in `clippy_dev/src/main.rs` is not found in the
294+
// This happens if the provided regex in `clippy_dev/src/main.rs` does not match in the
295295
// given text or file. Most likely this is an error on the programmer's side and the Regex
296296
// is incorrect.
297-
eprintln!("error: regex `{:?}` not found. You may have to update it.", start);
297+
eprintln!("error: regex \n{:?}\ndoesn't match. You may have to update it.", start);
298+
std::process::exit(1);
298299
}
299300

300301
let mut new_lines = new_lines.join("\n");

clippy_lints/src/as_conversions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl EarlyLintPass for AsConversions {
5050
AS_CONVERSIONS,
5151
expr.span,
5252
"using a potentially dangerous silent `as` conversion",
53+
None,
5354
"consider using a safe wrapper for this conversion",
5455
);
5556
}

clippy_lints/src/assertions_on_constants.rs

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4141
} else {
4242
"`assert!(true)` will be optimized out by the compiler"
4343
},
44+
None,
4445
"remove it",
4546
);
4647
};
@@ -50,6 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
5051
ASSERTIONS_ON_CONSTANTS,
5152
e.span,
5253
"`assert!(false)` should probably be replaced",
54+
None,
5355
"use `panic!()` or `unreachable!()`",
5456
);
5557
};
@@ -59,6 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
5961
ASSERTIONS_ON_CONSTANTS,
6062
e.span,
6163
&format!("`assert!(false, {})` should probably be replaced", panic_message),
64+
None,
6265
&format!("use `panic!({})` or `unreachable!({})`", panic_message, panic_message),
6366
)
6467
};

clippy_lints/src/atomic_ordering.rs

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
8585
INVALID_ATOMIC_ORDERING,
8686
ordering_arg.span,
8787
"atomic loads cannot have `Release` and `AcqRel` ordering",
88+
None,
8889
"consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`"
8990
);
9091
} else if method == "store" &&
@@ -94,6 +95,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
9495
INVALID_ATOMIC_ORDERING,
9596
ordering_arg.span,
9697
"atomic stores cannot have `Acquire` and `AcqRel` ordering",
98+
None,
9799
"consider using ordering modes `Release`, `SeqCst` or `Relaxed`"
98100
);
99101
}
@@ -118,6 +120,7 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
118120
INVALID_ATOMIC_ORDERING,
119121
args[0].span,
120122
"memory fences cannot have `Relaxed` ordering",
123+
None,
121124
"consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`"
122125
);
123126
}
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use crate::utils::{match_def_path, paths, span_lint_and_note};
2+
use rustc_hir::def_id::DefId;
3+
use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind};
4+
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_middle::ty::GeneratorInteriorTypeCause;
6+
use rustc_session::{declare_lint_pass, declare_tool_lint};
7+
use rustc_span::Span;
8+
9+
declare_clippy_lint! {
10+
/// **What it does:** Checks for calls to await while holding a
11+
/// non-async-aware MutexGuard.
12+
///
13+
/// **Why is this bad?** The Mutex types found in syd::sync and parking_lot
14+
/// are not designed to operator in an async context across await points.
15+
///
16+
/// There are two potential solutions. One is to use an asynx-aware Mutex
17+
/// type. Many asynchronous foundation crates provide such a Mutex type. The
18+
/// other solution is to ensure the mutex is unlocked before calling await,
19+
/// either by introducing a scope or an explicit call to Drop::drop.
20+
///
21+
/// **Known problems:** None.
22+
///
23+
/// **Example:**
24+
///
25+
/// ```rust,ignore
26+
/// use std::sync::Mutex;
27+
///
28+
/// async fn foo(x: &Mutex<u32>) {
29+
/// let guard = x.lock().unwrap();
30+
/// *guard += 1;
31+
/// bar.await;
32+
/// }
33+
/// ```
34+
///
35+
/// Use instead:
36+
/// ```rust,ignore
37+
/// use std::sync::Mutex;
38+
///
39+
/// async fn foo(x: &Mutex<u32>) {
40+
/// {
41+
/// let guard = x.lock().unwrap();
42+
/// *guard += 1;
43+
/// }
44+
/// bar.await;
45+
/// }
46+
/// ```
47+
pub AWAIT_HOLDING_LOCK,
48+
pedantic,
49+
"Inside an async function, holding a MutexGuard while calling await"
50+
}
51+
52+
declare_lint_pass!(AwaitHoldingLock => [AWAIT_HOLDING_LOCK]);
53+
54+
impl LateLintPass<'_, '_> for AwaitHoldingLock {
55+
fn check_body(&mut self, cx: &LateContext<'_, '_>, body: &'_ Body<'_>) {
56+
use AsyncGeneratorKind::{Block, Closure, Fn};
57+
match body.generator_kind {
58+
Some(GeneratorKind::Async(Block))
59+
| Some(GeneratorKind::Async(Closure))
60+
| Some(GeneratorKind::Async(Fn)) => {
61+
let body_id = BodyId {
62+
hir_id: body.value.hir_id,
63+
};
64+
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
65+
let tables = cx.tcx.typeck_tables_of(def_id);
66+
check_interior_types(cx, &tables.generator_interior_types, body.value.span);
67+
},
68+
_ => {},
69+
}
70+
}
71+
}
72+
73+
fn check_interior_types(cx: &LateContext<'_, '_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) {
74+
for ty_cause in ty_causes {
75+
if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind {
76+
if is_mutex_guard(cx, adt.did) {
77+
span_lint_and_note(
78+
cx,
79+
AWAIT_HOLDING_LOCK,
80+
ty_cause.span,
81+
"this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.",
82+
ty_cause.scope_span.or(Some(span)),
83+
"these are all the await points this lock is held through",
84+
);
85+
}
86+
}
87+
}
88+
}
89+
90+
fn is_mutex_guard(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
91+
match_def_path(cx, def_id, &paths::MUTEX_GUARD)
92+
|| match_def_path(cx, def_id, &paths::RWLOCK_READ_GUARD)
93+
|| match_def_path(cx, def_id, &paths::RWLOCK_WRITE_GUARD)
94+
|| match_def_path(cx, def_id, &paths::PARKING_LOT_MUTEX_GUARD)
95+
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_READ_GUARD)
96+
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_WRITE_GUARD)
97+
}

clippy_lints/src/cargo_common_metadata.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
use std::path::PathBuf;
44

5-
use crate::utils::span_lint;
6-
use rustc_ast::ast::Crate;
7-
use rustc_lint::{EarlyContext, EarlyLintPass};
5+
use crate::utils::{run_lints, span_lint};
6+
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
7+
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::source_map::DUMMY_SP;
1010

@@ -35,11 +35,11 @@ declare_clippy_lint! {
3535
"common metadata is defined in `Cargo.toml`"
3636
}
3737

38-
fn warning(cx: &EarlyContext<'_>, message: &str) {
38+
fn warning(cx: &LateContext<'_, '_>, message: &str) {
3939
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message);
4040
}
4141

42-
fn missing_warning(cx: &EarlyContext<'_>, package: &cargo_metadata::Package, field: &str) {
42+
fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) {
4343
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
4444
warning(cx, &message);
4545
}
@@ -59,8 +59,12 @@ fn is_empty_vec(value: &[String]) -> bool {
5959

6060
declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);
6161

62-
impl EarlyLintPass for CargoCommonMetadata {
63-
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
62+
impl LateLintPass<'_, '_> for CargoCommonMetadata {
63+
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
64+
if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) {
65+
return;
66+
}
67+
6468
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
6569
metadata
6670
} else {

clippy_lints/src/cognitive_complexity.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl CognitiveComplexity {
105105
rust_cc,
106106
self.limit.limit()
107107
),
108+
None,
108109
"you could split it up into multiple smaller functions",
109110
);
110111
}
@@ -122,7 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
122123
hir_id: HirId,
123124
) {
124125
let def_id = cx.tcx.hir().local_def_id(hir_id);
125-
if !cx.tcx.has_attr(def_id, sym!(test)) {
126+
if !cx.tcx.has_attr(def_id.to_def_id(), sym!(test)) {
126127
self.check(cx, kind, decl, body, span);
127128
}
128129
}

0 commit comments

Comments
 (0)